1
0
Fork 0
VaultUI/src/utils.ts

26 lines
789 B
TypeScript
Raw Normal View History

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-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)) {
if ((map as any)[key] === searchValue)
return key;
}
}
2021-05-07 23:08:02 +01:00
export function verifyJSONString(str: string): boolean {
try {
JSON.parse(str);
} catch (e) {
return false;
}
return true;
}