@finos/legend-shared
Advanced tools
Comparing version 5.0.0 to 5.0.1
@@ -55,4 +55,15 @@ /** | ||
export declare const pruneNullValues: (obj: Record<PropertyKey, unknown>) => Record<PropertyKey, unknown>; | ||
/** | ||
* Recursively sort object keys alphabetically | ||
*/ | ||
export declare const sortObjectKeys: (value: Record<PropertyKey, unknown>) => Record<PropertyKey, unknown>; | ||
/** | ||
* Stringify object shallowly | ||
* See https://stackoverflow.com/questions/16466220/limit-json-stringification-depth | ||
*/ | ||
export declare const shallowStringify: (object: unknown) => string; | ||
export declare const generateEnumerableNameFromToken: (existingNames: string[], token: string) => string; | ||
/** | ||
* NOTE: This is a small tool to workaround Typescript strictness check with the flag --noUncheckedIndexedAccess enabled | ||
*/ | ||
export declare const getNullableFirstElement: <T>(array: T[]) => T | undefined; | ||
@@ -59,0 +70,0 @@ /** |
@@ -97,4 +97,28 @@ /** | ||
export const pruneNullValues = (obj) => pickBy(obj, (val) => val !== null); | ||
// Stringify object shallowly | ||
// See https://stackoverflow.com/questions/16466220/limit-json-stringification-depth | ||
/** | ||
* Recursively sort object keys alphabetically | ||
*/ | ||
export const sortObjectKeys = (value) => { | ||
const _sort = (obj) => { | ||
if (Array.isArray(obj)) { | ||
return obj.map(sortObjectKeys); | ||
} | ||
else if (typeof obj === 'object') { | ||
const oldObj = obj; | ||
const newObj = {}; | ||
Object.keys(oldObj) | ||
.sort((a, b) => a.localeCompare(b)) | ||
.forEach((key) => { | ||
newObj[key] = _sort(oldObj[key]); | ||
}); | ||
return newObj; | ||
} | ||
return obj; | ||
}; | ||
return _sort(value); | ||
}; | ||
/** | ||
* Stringify object shallowly | ||
* See https://stackoverflow.com/questions/16466220/limit-json-stringification-depth | ||
*/ | ||
export const shallowStringify = (object) => JSON.stringify(object, (key, val) => key && val && typeof val !== 'number' | ||
@@ -119,2 +143,5 @@ ? Array.isArray(val) | ||
}; | ||
/** | ||
* NOTE: This is a small tool to workaround Typescript strictness check with the flag --noUncheckedIndexedAccess enabled | ||
*/ | ||
export const getNullableFirstElement = (array) => array.length ? array[0] : undefined; | ||
@@ -121,0 +148,0 @@ /** |
{ | ||
"name": "@finos/legend-shared", | ||
"version": "5.0.0", | ||
"version": "5.0.1", | ||
"description": "Legend Studio shared utilities and helpers", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
{ | ||
"name": "@finos/legend-shared", | ||
"version": "5.0.0", | ||
"version": "5.0.1", | ||
"description": "Legend Studio shared utilities and helpers", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -178,4 +178,30 @@ /** | ||
// Stringify object shallowly | ||
// See https://stackoverflow.com/questions/16466220/limit-json-stringification-depth | ||
/** | ||
* Recursively sort object keys alphabetically | ||
*/ | ||
export const sortObjectKeys = ( | ||
value: Record<PropertyKey, unknown>, | ||
): Record<PropertyKey, unknown> => { | ||
const _sort = (obj: unknown): unknown => { | ||
if (Array.isArray(obj)) { | ||
return obj.map(sortObjectKeys); | ||
} else if (typeof obj === 'object') { | ||
const oldObj = obj as Record<PropertyKey, unknown>; | ||
const newObj: Record<PropertyKey, unknown> = {}; | ||
Object.keys(oldObj) | ||
.sort((a, b) => a.localeCompare(b)) | ||
.forEach((key) => { | ||
newObj[key] = _sort(oldObj[key]); | ||
}); | ||
return newObj; | ||
} | ||
return obj; | ||
}; | ||
return _sort(value) as Record<PropertyKey, unknown>; | ||
}; | ||
/** | ||
* Stringify object shallowly | ||
* See https://stackoverflow.com/questions/16466220/limit-json-stringification-depth | ||
*/ | ||
export const shallowStringify = (object: unknown): string => | ||
@@ -210,2 +236,5 @@ JSON.stringify(object, (key, val) => | ||
/** | ||
* NOTE: This is a small tool to workaround Typescript strictness check with the flag --noUncheckedIndexedAccess enabled | ||
*/ | ||
export const getNullableFirstElement = <T>(array: T[]): T | undefined => | ||
@@ -212,0 +241,0 @@ array.length ? array[0] : undefined; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
340672
6195