@finos/legend-shared
Advanced tools
Comparing version 5.0.3 to 6.0.0
@@ -45,4 +45,4 @@ /** | ||
} | ||
export declare const hashString: (val: string) => string; | ||
export declare const hashArray: (arr: (string | Hashable)[]) => string; | ||
export declare const hashValue: (val: string | boolean | number) => string; | ||
export declare const hashArray: (arr: (string | boolean | number | Hashable)[]) => string; | ||
/** | ||
@@ -49,0 +49,0 @@ * NOTE: `node-object-hash` seems to be the much more efficient library. But it's based on Node's `crypto` module |
@@ -17,5 +17,9 @@ /** | ||
import hash from 'hash.js'; | ||
export const hashString = (val) => hash.sha1().update(val).digest('hex'); | ||
export const hashArray = (arr) => hashString(arr | ||
.map((val) => (typeof val === 'string' ? hashString(val) : val.hashCode)) | ||
export const hashValue = (val) => hash.sha1().update(val).digest('hex'); | ||
export const hashArray = (arr) => hashValue(arr | ||
.map((val) => typeof val === 'string' || | ||
typeof val === 'boolean' || | ||
typeof val === 'number' | ||
? hashValue(val) | ||
: val.hashCode) | ||
.join(',')); | ||
@@ -22,0 +26,0 @@ /** |
@@ -92,2 +92,3 @@ /** | ||
export declare const changeEntry: <T>(array: T[], oldEntry: T, newEntry: T, comparator?: (val1: T, val2: T) => boolean) => boolean; | ||
export declare const swapEntry: <T>(array: T[], entryOne: T, entryTwo: T, comparator?: (val1: T, val2: T) => boolean) => boolean; | ||
export declare const deleteEntry: <T>(array: T[], entryToDelete: T, comparator?: (val1: T, val2: T) => boolean) => boolean; | ||
@@ -94,0 +95,0 @@ export declare type GeneratorFn<T> = Generator<Promise<unknown>, // force to manually handle casting for any promise called within the generator function |
@@ -179,2 +179,12 @@ /** | ||
}; | ||
export const swapEntry = (array, entryOne, entryTwo, comparator = (val1, val2) => val1 === val2) => { | ||
const idxX = array.findIndex((entry) => comparator(entry, entryOne)); | ||
const idxY = array.findIndex((entry) => comparator(entry, entryTwo)); | ||
if (idxX !== -1 && idxY !== -1) { | ||
array[idxX] = entryTwo; | ||
array[idxY] = entryOne; | ||
return true; | ||
} | ||
return false; | ||
}; | ||
export const deleteEntry = (array, entryToDelete, comparator = (val1, val2) => val1 === val2) => { | ||
@@ -181,0 +191,0 @@ const idx = array.findIndex((entry) => comparator(entry, entryToDelete)); |
@@ -50,3 +50,3 @@ /** | ||
export declare class UnsupportedOperationError extends EnrichedError { | ||
constructor(message?: string, unsupportedObject?: unknown); | ||
constructor(message?: string | undefined, unsupportedObject?: unknown); | ||
} | ||
@@ -53,0 +53,0 @@ /** |
@@ -90,3 +90,5 @@ /** | ||
constructor(message, unsupportedObject) { | ||
super('Unsupported Operation Error', `${message}${unsupportedObject ? `\n${printObject(unsupportedObject)}` : ''}`); | ||
super('Unsupported Operation Error', message || unsupportedObject | ||
? `${message}${unsupportedObject ? `\n${printObject(unsupportedObject)}` : ''}` | ||
: undefined); | ||
} | ||
@@ -93,0 +95,0 @@ } |
{ | ||
"name": "@finos/legend-shared", | ||
"version": "5.0.3", | ||
"version": "6.0.0", | ||
"description": "Legend Studio shared utilities and helpers", | ||
@@ -65,3 +65,3 @@ "keywords": [ | ||
"cross-env": "7.0.3", | ||
"eslint": "8.21.0", | ||
"eslint": "8.22.0", | ||
"jest": "28.1.3", | ||
@@ -68,0 +68,0 @@ "lodash": "4.17.21", |
{ | ||
"name": "@finos/legend-shared", | ||
"version": "5.0.3", | ||
"version": "6.0.0", | ||
"description": "Legend Studio shared utilities and helpers", | ||
@@ -62,6 +62,6 @@ "keywords": [ | ||
"devDependencies": { | ||
"@finos/legend-dev-utils": "2.0.9", | ||
"@finos/legend-dev-utils": "2.0.10", | ||
"@jest/globals": "28.1.3", | ||
"cross-env": "7.0.3", | ||
"eslint": "8.21.0", | ||
"eslint": "8.22.0", | ||
"jest": "28.1.3", | ||
@@ -68,0 +68,0 @@ "lodash": "4.17.21", |
@@ -49,9 +49,17 @@ /** | ||
export const hashString = (val: string): string => | ||
export const hashValue = (val: string | boolean | number): string => | ||
hash.sha1().update(val).digest('hex'); | ||
export const hashArray = (arr: (string | Hashable)[]): string => | ||
hashString( | ||
export const hashArray = ( | ||
arr: (string | boolean | number | Hashable)[], | ||
): string => | ||
hashValue( | ||
arr | ||
.map((val) => (typeof val === 'string' ? hashString(val) : val.hashCode)) | ||
.map((val) => | ||
typeof val === 'string' || | ||
typeof val === 'boolean' || | ||
typeof val === 'number' | ||
? hashValue(val) | ||
: val.hashCode, | ||
) | ||
.join(','), | ||
@@ -58,0 +66,0 @@ ); |
@@ -313,2 +313,19 @@ /** | ||
export const swapEntry = <T>( | ||
array: T[], | ||
entryOne: T, | ||
entryTwo: T, | ||
comparator = (val1: T, val2: T): boolean => val1 === val2, | ||
): boolean => { | ||
const idxX = array.findIndex((entry) => comparator(entry, entryOne)); | ||
const idxY = array.findIndex((entry) => comparator(entry, entryTwo)); | ||
if (idxX !== -1 && idxY !== -1) { | ||
array[idxX] = entryTwo; | ||
array[idxY] = entryOne; | ||
return true; | ||
} | ||
return false; | ||
}; | ||
export const deleteEntry = <T>( | ||
@@ -315,0 +332,0 @@ array: T[], |
@@ -99,8 +99,10 @@ /** | ||
export class UnsupportedOperationError extends EnrichedError { | ||
constructor(message?: string, unsupportedObject?: unknown) { | ||
constructor(message?: string | undefined, unsupportedObject?: unknown) { | ||
super( | ||
'Unsupported Operation Error', | ||
`${message}${ | ||
unsupportedObject ? `\n${printObject(unsupportedObject)}` : '' | ||
}`, | ||
message || unsupportedObject | ||
? `${message}${ | ||
unsupportedObject ? `\n${printObject(unsupportedObject)}` : '' | ||
}` | ||
: undefined, | ||
); | ||
@@ -107,0 +109,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
342782
6237