@applitools/utils
Advanced tools
Comparing version 1.7.7 to 1.7.8
# Changelog | ||
## [1.7.8](https://github.com/Applitools-Dev/sdk/compare/js/utils@1.7.7...js/utils@1.7.8) (2025-02-26) | ||
### Performance Improvements | ||
* ufg client dedup job info elements ([#2811](https://github.com/Applitools-Dev/sdk/issues/2811)) ([c04c147](https://github.com/Applitools-Dev/sdk/commit/c04c14776736a422292ada1029820e975adc3d31)) | ||
## [1.7.7](https://github.com/Applitools-Dev/sdk/compare/js/utils@1.7.6...js/utils@1.7.7) (2024-12-31) | ||
@@ -4,0 +11,0 @@ |
@@ -26,3 +26,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.pluralize = exports.extend = exports.wrap = exports.batchify = exports.cachify = exports.absolutizeUrl = exports.removeUndefinedProps = exports.toUriEncoding = exports.toUnAnchoredUri = exports.toString = exports.toJSON = exports.sleep = exports.jwtDecode = exports.shortid = exports.guid = exports.getEnvValue = void 0; | ||
exports.dedupAndMap = exports.deepEqual = exports.pluralize = exports.extend = exports.wrap = exports.batchify = exports.cachify = exports.absolutizeUrl = exports.removeUndefinedProps = exports.toUriEncoding = exports.toUnAnchoredUri = exports.toString = exports.toJSON = exports.sleep = exports.jwtDecode = exports.shortid = exports.guid = exports.getEnvValue = void 0; | ||
const buffer_1 = require("buffer"); | ||
@@ -186,1 +186,57 @@ const types = __importStar(require("./types")); | ||
exports.pluralize = pluralize; | ||
function deepEqual(value1, value2) { | ||
return _deepEqual(value1, value2, new Set()); | ||
} | ||
exports.deepEqual = deepEqual; | ||
function _deepEqual(value1, value2, visitedObjects) { | ||
if (value1 === value2) | ||
return true; | ||
if (visitedObjects.has(value1) && visitedObjects.has(value2)) | ||
throw new Error('circular reference'); | ||
if (typeof value1 === 'object' && typeof value2 === 'object') { | ||
visitedObjects.add(value1); | ||
visitedObjects.add(value2); | ||
} | ||
if (types.isArray(value1) && types.isArray(value2)) { | ||
if (value1.length !== value2.length) | ||
return false; | ||
for (let i = 0; i < value1.length; i++) { | ||
if (!_deepEqual(value1[i], value2[i], visitedObjects)) | ||
return false; | ||
} | ||
return true; | ||
} | ||
if (types.isObject(value1) && types.isObject(value2)) { | ||
const keys1 = Object.keys(value1); | ||
const keys2 = Object.keys(value2); | ||
if (keys1.length !== keys2.length) | ||
return false; | ||
for (const key of keys1) { | ||
if (!_deepEqual(value1[key], value2[key], visitedObjects)) | ||
return false; | ||
} | ||
return true; | ||
} | ||
return false; | ||
} | ||
/** | ||
* Deduplicates an array based on a custom equality function, applies an asynchronous transformation | ||
* to the unique values, and maps the results back to the original array structure. | ||
* | ||
* @param items - The array of items to process. | ||
* @param transform - A function that receives unique items and returns transformed results. | ||
* @param isEqual - A function that determines whether two items are considered equal. | ||
* @returns A Promise resolving to an array where each item is replaced with its transformed result. | ||
*/ | ||
async function dedupAndMap(items, transform, isEqual) { | ||
// Extract unique values | ||
const firstIndecies = items.map(value => items.findIndex(v => isEqual(v, value))); | ||
const uniqueValues = items.filter((_, index) => firstIndecies.indexOf(index) === index); | ||
// Compute results for unique values | ||
const results = await transform(uniqueValues); | ||
// Map unique values to their transformed results | ||
const resultMap = new WeakMap(); | ||
uniqueValues.forEach((val, index) => resultMap.set(val, results[index])); | ||
return items.map((_, index) => resultMap.get(items[firstIndecies[index]])); | ||
} | ||
exports.dedupAndMap = dedupAndMap; |
{ | ||
"name": "@applitools/utils", | ||
"version": "1.7.7", | ||
"version": "1.7.8", | ||
"keywords": [ | ||
@@ -51,3 +51,5 @@ "applitools", | ||
"@applitools/test-utils": "^1.5.17", | ||
"@types/node": "^12.20.55" | ||
"@types/chai": "^5", | ||
"@types/node": "^12.20.55", | ||
"chai": "^4.2.0" | ||
}, | ||
@@ -54,0 +56,0 @@ "engines": { |
@@ -40,1 +40,12 @@ export declare function getEnvValue<T extends 'boolean' | 'number' | 'string' = 'string'>(name: string, type?: T): T extends 'boolean' ? boolean : T extends 'number' ? number : T extends 'string' ? string : string | undefined; | ||
export declare function pluralize(object: [] | number, config?: [manyCase: string, singleCase: string]): string; | ||
export declare function deepEqual(value1: any, value2: any): boolean; | ||
/** | ||
* Deduplicates an array based on a custom equality function, applies an asynchronous transformation | ||
* to the unique values, and maps the results back to the original array structure. | ||
* | ||
* @param items - The array of items to process. | ||
* @param transform - A function that receives unique items and returns transformed results. | ||
* @param isEqual - A function that determines whether two items are considered equal. | ||
* @returns A Promise resolving to an array where each item is replaced with its transformed result. | ||
*/ | ||
export declare function dedupAndMap<T extends object, R>(items: T[], transform: (arr: T[]) => Promise<R[]>, isEqual: (a: T, b: T) => boolean): Promise<R[]>; |
89697
1628
4