2021-05-07 22:23:52 +01:00
|
|
|
export function removeDoubleSlash(str: string): string {
|
|
|
|
return str.replace(/\/\/+/g, "/");
|
|
|
|
}
|
|
|
|
|
2021-05-08 00:58:28 +01:00
|
|
|
export const getObjectKeys =
|
|
|
|
(obj: Record<string, unknown>): string[] => Object.getOwnPropertyNames(obj);
|
|
|
|
export const objectToMap =
|
|
|
|
(obj: Record<string, unknown>): Map<any, any> => new Map(Object.entries(obj));
|
|
|
|
export const sortedObjectMap =
|
|
|
|
(obj: Record<string, unknown>): Map<any, any> => new Map(Object.entries(obj).sort());
|
2021-05-07 22:23:52 +01:00
|
|
|
|
2021-05-08 00:58:28 +01:00
|
|
|
export function getKeyByObjectPropertyValue(map: Record<string, unknown>, searchValue: unknown): string {
|
2021-05-07 23:08:02 +01:00
|
|
|
for (const key of getObjectKeys(map)) {
|
2021-05-07 22:23:52 +01:00
|
|
|
if ((map as any)[key] === searchValue)
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-07 23:08:02 +01:00
|
|
|
export function verifyJSONString(str: string): boolean {
|
2021-05-07 22:23:52 +01:00
|
|
|
try {
|
|
|
|
JSON.parse(str);
|
|
|
|
} catch (e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|