2021-05-07 22:23:52 +01:00
|
|
|
export function removeDoubleSlash(str: string): string {
|
|
|
|
return str.replace(/\/\/+/g, "/");
|
|
|
|
}
|
|
|
|
|
2021-05-21 10:19:17 +01:00
|
|
|
export const toStr = (item: unknown): string => String(item).toString();
|
|
|
|
|
2021-05-12 16:01:04 +01:00
|
|
|
export const getObjectKeys = (obj: Record<string, unknown>): string[] =>
|
|
|
|
Object.getOwnPropertyNames(obj);
|
|
|
|
export const objectToMap = (obj: Record<string, unknown>): Map<string, unknown> =>
|
|
|
|
new Map(Object.entries(obj));
|
|
|
|
export const sortedObjectMap = (obj: Record<string, unknown>): Map<string, unknown> =>
|
|
|
|
new Map(Object.entries(obj).sort());
|
2021-05-07 22:23:52 +01:00
|
|
|
|
2021-05-12 16:01:04 +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-12 16:01:04 +01:00
|
|
|
if (map[key] === searchValue) return key;
|
2021-05-07 22:23:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
2021-05-12 16:01:04 +01:00
|
|
|
}
|