75 lines
2.0 KiB
TypeScript
75 lines
2.0 KiB
TypeScript
import { CtaData } from "../interface";
|
|
import { SPACE_UNICODE } from "../constants/StringConstant";
|
|
import {
|
|
AnalyticsEventNameConstants,
|
|
BASE_SCREEN,
|
|
EVENT_NAMES,
|
|
} from "../constants";
|
|
import { sendAsAnalyticsEvent } from "../hooks/useAnalyticsEvent";
|
|
|
|
export function getScreenNameFromCtaData(ctaData: CtaData): string | undefined {
|
|
const splitDeeplink = ctaData.url?.split("/");
|
|
return splitDeeplink?.at(2);
|
|
}
|
|
|
|
export function getScreenMapperNameFromCtaData(
|
|
ctaData: CtaData,
|
|
): string | undefined {
|
|
const splitDeeplink = ctaData.url?.split("/");
|
|
return splitDeeplink?.at(1);
|
|
}
|
|
|
|
export function updateValueByKeyPath<T>(
|
|
obj: T,
|
|
keyPath?: string,
|
|
newValue?: any,
|
|
): void {
|
|
if (!keyPath || !newValue) {
|
|
return;
|
|
}
|
|
const keys: string[] = keyPath.split(".");
|
|
let currentObj: any = obj;
|
|
|
|
for (let i = 0; i < keys.length - 1; i++) {
|
|
const key: string = keys[i] || "";
|
|
if (
|
|
!!key &&
|
|
currentObj.hasOwnProperty(key) &&
|
|
typeof currentObj[key] === "object"
|
|
) {
|
|
currentObj = currentObj[key];
|
|
} else {
|
|
sendAsAnalyticsEvent({
|
|
name: AnalyticsEventNameConstants.HI_RN_INVALID_DATA_ERROR,
|
|
properties: {
|
|
errorType: EVENT_NAMES.KEY_PATH_INVALID_ERROR,
|
|
error: `${keyPath}`,
|
|
methodName: `${arguments.callee.name}`,
|
|
},
|
|
});
|
|
return;
|
|
}
|
|
}
|
|
|
|
const lastKey: string = keys[keys.length - 1] || "";
|
|
if (!!lastKey && currentObj.hasOwnProperty(lastKey)) {
|
|
//the values here should be in string format
|
|
try {
|
|
currentObj[lastKey] = newValue;
|
|
} catch (exception) {
|
|
sendAsAnalyticsEvent({
|
|
name: AnalyticsEventNameConstants.HI_RN_INVALID_DATA_ERROR,
|
|
properties: {
|
|
errorType: EVENT_NAMES.KEY_PATH_INVALID_ERROR,
|
|
error: `${keyPath}`,
|
|
methodName: `${arguments.callee.name}`,
|
|
},
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
export const getTextWithHtmlSpace = (text?: string) => {
|
|
return text?.split(" ").join(SPACE_UNICODE);
|
|
};
|