Files
super-app/App/common/utilities/MiscUtils.ts
Rohitaksh Choudhary 3f471498ed NTP-8070 | Rohitaksh | RN integration iOS (#14407)
Signed-off-by: kishan kumar <kishan.kumar@navi.com>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Chirayu <chirayu.mor@navi.com>
Co-authored-by: Prakhar Saxena <prakhar.saxena@navi.com>
Co-authored-by: Shivam Goyal <shivam.goyal@navi.com>
Co-authored-by: vedant aggarwal <vedant.aggarwal@navi.com>
Co-authored-by: A Shrihari Raju <shrihari.raju@navi.com>
Co-authored-by: Prajjaval Verma <prajjaval.verma@navi.com>
Co-authored-by: Raaj Gopal <raaj.gopal@navi.com>
Co-authored-by: Aman S <aman.s@navi.com>
Co-authored-by: Aman <amankasyapp@gmail.com>
Co-authored-by: Sanjay P <sanjay.p@navi.com>
Co-authored-by: Varun Jain <varun.jain@navi.com>
Co-authored-by: Shiv Natani <shiv.natani@navi.com>
Co-authored-by: Hardik Chaudhary <hardik.chaudhary@navi.com>
Co-authored-by: Kishan Kumar <kishan.kumar@navi.com>
Co-authored-by: Balrambhai Sharma <sharma.balrambhai@navi.com>
Co-authored-by: Ujjwal Kumar <ujjwal.kumar@navi.com>
Co-authored-by: Aditya Narayan Malik <aditya.narayan@navi.com>
Co-authored-by: Ayushman Sharma <ayushman.sharma@navi.com>
Co-authored-by: Anmol Agrawal <anmol.agrawal@navi.com>
Co-authored-by: Soumya Ranjan Patra <soumya.ranjan@navi.com>
Co-authored-by: Sohan Reddy Atukula <sohan.reddy@navi.com>
Co-authored-by: Sayed Owais Ali <sayed.owais@navi.com>
Co-authored-by: Ankit Yadav <ankit.yadav@navi.com>
Co-authored-by: Shaurya Rehan <shaurya.rehan@navi.com>
Co-authored-by: saksham-mahajan_navi <saksham.mahajan@navi.com>
Co-authored-by: shankar yadav <shankar.yadav@navi.com>
Co-authored-by: Mehul Garg <mehul.garg@navi.com>
Co-authored-by: Somarapu Vamshi <somarapu.vamshi@navi.com>
Co-authored-by: Kshitij Pramod Ghongadi <kshitij.pramod@navi.com>
Co-authored-by: Sandeep Kumar <sandeep.ku@navi.com>
Co-authored-by: Aparna Vadlamani <aparna.vadlamani@navi.com>
Co-authored-by: Siddiboina Susai <siddiboina.susai@navi.com>
Co-authored-by: Kamalesh Garnayak <kamalesh.garnayak@navi.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Divyesh Shinde <divyesh.shinde@navi.com>
Co-authored-by: Mohit Rajput <mohit.rajput@navi.com>
Co-authored-by: Akshita Singh <akshita.singh@navi.com>
Co-authored-by: shreyansu raj <shreyansu.raj@navi.com>
Co-authored-by: Venkat Praneeth Reddy <venkat.praneeth@navi.com>
2025-01-13 13:30:56 +00:00

103 lines
2.5 KiB
TypeScript

import { CtaData } from "../interface";
import { FontMapping, 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);
};
type FontKey = keyof typeof FontMapping;
export const getMappedFontForIos = (currentFont?: string): string => {
if (!currentFont) {
return "";
}
const currentFontKey = currentFont as FontKey;
if (FontMapping[currentFontKey]) {
return FontMapping[currentFontKey];
}
return currentFont;
};
export const parseString = (value: string) => {
switch (value) {
case "true":
return true;
case "false":
return false;
case "null":
case "undefined":
case "":
case "[object Object]":
return null;
default:
return value;
}
};