1
0
Fork 0
VaultUI/src/utils.ts

23 lines
731 B
TypeScript
Raw Normal View History

export function removeDoubleSlash(str: string): string {
return str.replace(/\/\/+/g, "/");
}
2021-05-07 23:08:02 +01:00
export const getObjectKeys = (obj: Record<string, unknown>) => Object.getOwnPropertyNames(obj);
export const objectToMap = (obj: Record<string, unknown>) => new Map(Object.entries(obj));
export const sortedObjectMap = (obj: Record<string, unknown>) => new Map(Object.entries(obj).sort());
2021-05-07 23:08:02 +01:00
export function getKeyByObjectPropertyValue(map: Record<string, unknown>, searchValue: any) {
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;
}