@contrail/util
Advanced tools
Comparing version 1.0.12 to 1.0.13
export * from './object-util/object-util'; | ||
export * from './string-util/string-util'; |
@@ -0,0 +0,0 @@ "use strict"; |
export declare function cloneDeep(obj: any): any; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -7,1 +7,2 @@ export interface ObjectDiff { | ||
export declare function getObjectDiffs(before: any, after: any, prefix: string): ObjectDiff[]; | ||
export declare function getObjectDiff(before: any, after: any, name: any): ObjectDiff; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getObjectDiffs = void 0; | ||
exports.getObjectDiff = exports.getObjectDiffs = void 0; | ||
function getObjectDiffs(before, after, prefix) { | ||
@@ -21,20 +21,30 @@ const diffs = []; | ||
commonProperties.forEach(commonProperty => { | ||
if (typeof before[commonProperty] !== typeof after[commonProperty]) { | ||
diffs.push(getObjectDiff(before[commonProperty], after[commonProperty], prefix + commonProperty)); | ||
const beforeVal = before[commonProperty]; | ||
const afterVal = after[commonProperty]; | ||
if (beforeVal === afterVal) { | ||
return; | ||
} | ||
else if (isObject(before[commonProperty])) { | ||
if (isDate(before[commonProperty])) { | ||
if (!datesEqual(before[commonProperty], after[commonProperty])) { | ||
diffs.push(getObjectDiff(before[commonProperty], after[commonProperty], prefix + commonProperty)); | ||
if (beforeVal === null || afterVal === null) { | ||
diffs.push(getObjectDiff(beforeVal, afterVal, prefix + commonProperty)); | ||
return; | ||
} | ||
if (typeof beforeVal !== typeof afterVal) { | ||
diffs.push(getObjectDiff(beforeVal, afterVal, prefix + commonProperty)); | ||
return; | ||
} | ||
if (isObject(beforeVal)) { | ||
if (isDate(beforeVal)) { | ||
if (!datesEqual(beforeVal, afterVal)) { | ||
diffs.push(getObjectDiff(beforeVal, afterVal, prefix + commonProperty)); | ||
} | ||
} | ||
else if (Array.isArray(before[commonProperty])) { | ||
const beforeArray = [...before[commonProperty]].sort(sortFunc); | ||
const afterArray = [...after[commonProperty]].sort(sortFunc); | ||
else if (Array.isArray(beforeVal)) { | ||
const beforeArray = [...beforeVal].sort(sortFunc); | ||
const afterArray = [...afterVal].sort(sortFunc); | ||
if (JSON.stringify(beforeArray) !== JSON.stringify(afterArray)) { | ||
diffs.push(getObjectDiff(before[commonProperty], after[commonProperty], prefix + commonProperty)); | ||
diffs.push(getObjectDiff(beforeVal, afterVal, prefix + commonProperty)); | ||
} | ||
} | ||
else { | ||
const nestedObjectDiffs = getObjectDiffs(before[commonProperty], after[commonProperty], prefix + commonProperty + '.'); | ||
const nestedObjectDiffs = getObjectDiffs(beforeVal, afterVal, prefix + commonProperty + '.'); | ||
diffs.push(...nestedObjectDiffs); | ||
@@ -44,4 +54,4 @@ } | ||
else { | ||
if (before[commonProperty] !== after[commonProperty]) { | ||
diffs.push(getObjectDiff(before[commonProperty], after[commonProperty], prefix + commonProperty)); | ||
if (beforeVal !== afterVal) { | ||
diffs.push(getObjectDiff(beforeVal, afterVal, prefix + commonProperty)); | ||
} | ||
@@ -61,2 +71,3 @@ } | ||
} | ||
exports.getObjectDiff = getObjectDiff; | ||
function sortFunc(x, y) { | ||
@@ -63,0 +74,0 @@ const pre = ['string', 'number', 'bool']; |
@@ -17,2 +17,10 @@ export declare const item1Assortment1: { | ||
}; | ||
export declare const item1Assortment3: { | ||
id: string; | ||
stringProperty: string; | ||
intProperty: number; | ||
boolProperty: boolean; | ||
dateProperty: Date; | ||
arrayProperty: any; | ||
}; | ||
export declare const item2Assortment1: { | ||
@@ -19,0 +27,0 @@ id: string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.item3Assortment2NestedChanges = exports.item3Assortment1 = exports.item2Assortment2DateChange = exports.item2Assortment2ArrayChange = exports.item2Assortment2ScalarChange = exports.item2Assortment1 = exports.item1Assortment2 = exports.item1Assortment1 = void 0; | ||
exports.item3Assortment2NestedChanges = exports.item3Assortment1 = exports.item2Assortment2DateChange = exports.item2Assortment2ArrayChange = exports.item2Assortment2ScalarChange = exports.item2Assortment1 = exports.item1Assortment3 = exports.item1Assortment2 = exports.item1Assortment1 = void 0; | ||
exports.item1Assortment1 = { | ||
@@ -20,2 +20,10 @@ id: 'id1', | ||
}; | ||
exports.item1Assortment3 = { | ||
id: 'id1', | ||
stringProperty: 'stringProperty1', | ||
intProperty: 1, | ||
boolProperty: false, | ||
dateProperty: new Date('12/22/1994'), | ||
arrayProperty: null, | ||
}; | ||
exports.item2Assortment1 = { | ||
@@ -22,0 +30,0 @@ id: 'id2', |
export declare function isObject(item: any): boolean; |
@@ -0,0 +0,0 @@ "use strict"; |
export declare function mergeDeep(target: any, ...sources: any[]): any; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { cloneDeep } from './cloneDeep/cloneDeep'; |
@@ -0,0 +0,0 @@ "use strict"; |
export declare class StringUtil { | ||
static convertToHyphenCase(entityName: string, transformToLowerCase?: boolean): string; | ||
} |
@@ -0,0 +0,0 @@ "use strict"; |
{ | ||
"name": "@contrail/util", | ||
"version": "1.0.12", | ||
"version": "1.0.13", | ||
"description": "General javascript utilities", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
14627
402
0