@contrail/util 1.0.32 → 1.0.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/date-util/date-util.d.ts +4 -4
- package/lib/date-util/date-util.js +8 -8
- package/lib/date-util/getIsoDatePart/getIsoDatePart.d.ts +1 -1
- package/lib/date-util/getIsoDatePart/getIsoDatePart.js +17 -17
- package/lib/index.d.ts +4 -4
- package/lib/index.js +20 -20
- package/lib/map-util/map-util.d.ts +3 -3
- package/lib/map-util/map-util.js +18 -18
- package/lib/object-util/applyChangesIfEqual/applyChangesIfEqual.d.ts +2 -2
- package/lib/object-util/applyChangesIfEqual/applyChangesIfEqual.js +23 -23
- package/lib/object-util/cloneDeep/cloneDeep.d.ts +1 -1
- package/lib/object-util/cloneDeep/cloneDeep.js +10 -10
- package/lib/object-util/compareDeep/compareDeep.d.ts +7 -7
- package/lib/object-util/compareDeep/compareDeep.js +87 -87
- package/lib/object-util/compareDeep/mockData.d.ts +88 -88
- package/lib/object-util/compareDeep/mockData.js +91 -91
- package/lib/object-util/isObject/isObject.d.ts +1 -1
- package/lib/object-util/isObject/isObject.js +7 -7
- package/lib/object-util/mergeDeep/mergeDeep.d.ts +1 -1
- package/lib/object-util/mergeDeep/mergeDeep.js +26 -26
- package/lib/object-util/object-util.d.ts +16 -16
- package/lib/object-util/object-util.js +43 -43
- package/lib/string-util/string-util.d.ts +8 -9
- package/lib/string-util/string-util.js +63 -65
- package/package.json +40 -40
- package/lib/string-util/replaceAllWithFunction/replaceAllWithFunction.d.ts +0 -1
- package/lib/string-util/replaceAllWithFunction/replaceAllWithFunction.js +0 -24
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getIsoDatePart } from "./getIsoDatePart/getIsoDatePart";
|
|
2
|
-
export declare class DateUtil {
|
|
3
|
-
static getIsoDatePart: typeof getIsoDatePart;
|
|
4
|
-
}
|
|
1
|
+
import { getIsoDatePart } from "./getIsoDatePart/getIsoDatePart";
|
|
2
|
+
export declare class DateUtil {
|
|
3
|
+
static getIsoDatePart: typeof getIsoDatePart;
|
|
4
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DateUtil = void 0;
|
|
4
|
-
const getIsoDatePart_1 = require("./getIsoDatePart/getIsoDatePart");
|
|
5
|
-
class DateUtil {
|
|
6
|
-
}
|
|
7
|
-
exports.DateUtil = DateUtil;
|
|
8
|
-
DateUtil.getIsoDatePart = getIsoDatePart_1.getIsoDatePart;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DateUtil = void 0;
|
|
4
|
+
const getIsoDatePart_1 = require("./getIsoDatePart/getIsoDatePart");
|
|
5
|
+
class DateUtil {
|
|
6
|
+
}
|
|
7
|
+
exports.DateUtil = DateUtil;
|
|
8
|
+
DateUtil.getIsoDatePart = getIsoDatePart_1.getIsoDatePart;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getIsoDatePart(date: Date): string;
|
|
1
|
+
export declare function getIsoDatePart(date: Date): string;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getIsoDatePart = void 0;
|
|
4
|
-
function getIsoDatePart(date) {
|
|
5
|
-
console.log('date 1: ', date.toISOString(), '\n\n\n\n\n\n\n\n');
|
|
6
|
-
let d = new Date(date);
|
|
7
|
-
console.log('date 2: ', d.toISOString(), '\n\n\n\n\n\n\n\n');
|
|
8
|
-
let month = '' + (d.getMonth() + 1), day = '' + d.getDate(), year = d.getFullYear();
|
|
9
|
-
if (month.length < 2) {
|
|
10
|
-
month = '0' + month;
|
|
11
|
-
}
|
|
12
|
-
if (day.length < 2) {
|
|
13
|
-
day = '0' + day;
|
|
14
|
-
}
|
|
15
|
-
return [year, month, day].join('-');
|
|
16
|
-
}
|
|
17
|
-
exports.getIsoDatePart = getIsoDatePart;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getIsoDatePart = void 0;
|
|
4
|
+
function getIsoDatePart(date) {
|
|
5
|
+
console.log('date 1: ', date.toISOString(), '\n\n\n\n\n\n\n\n');
|
|
6
|
+
let d = new Date(date);
|
|
7
|
+
console.log('date 2: ', d.toISOString(), '\n\n\n\n\n\n\n\n');
|
|
8
|
+
let month = '' + (d.getMonth() + 1), day = '' + d.getDate(), year = d.getFullYear();
|
|
9
|
+
if (month.length < 2) {
|
|
10
|
+
month = '0' + month;
|
|
11
|
+
}
|
|
12
|
+
if (day.length < 2) {
|
|
13
|
+
day = '0' + day;
|
|
14
|
+
}
|
|
15
|
+
return [year, month, day].join('-');
|
|
16
|
+
}
|
|
17
|
+
exports.getIsoDatePart = getIsoDatePart;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './object-util/object-util';
|
|
2
|
-
export * from './string-util/string-util';
|
|
3
|
-
export * from './date-util/date-util';
|
|
4
|
-
export * from './map-util/map-util';
|
|
1
|
+
export * from './object-util/object-util';
|
|
2
|
+
export * from './string-util/string-util';
|
|
3
|
+
export * from './date-util/date-util';
|
|
4
|
+
export * from './map-util/map-util';
|
package/lib/index.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./object-util/object-util"), exports);
|
|
18
|
-
__exportStar(require("./string-util/string-util"), exports);
|
|
19
|
-
__exportStar(require("./date-util/date-util"), exports);
|
|
20
|
-
__exportStar(require("./map-util/map-util"), exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./object-util/object-util"), exports);
|
|
18
|
+
__exportStar(require("./string-util/string-util"), exports);
|
|
19
|
+
__exportStar(require("./date-util/date-util"), exports);
|
|
20
|
+
__exportStar(require("./map-util/map-util"), exports);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare class MapUtil {
|
|
2
|
-
static keyBy(array: any[], variableString: any): {};
|
|
3
|
-
}
|
|
1
|
+
export declare class MapUtil {
|
|
2
|
+
static keyBy(array: any[], variableString: any): {};
|
|
3
|
+
}
|
package/lib/map-util/map-util.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MapUtil = void 0;
|
|
4
|
-
const string_util_1 = require("../string-util/string-util");
|
|
5
|
-
class MapUtil {
|
|
6
|
-
static keyBy(array, variableString) {
|
|
7
|
-
if (variableString.charAt(0) !== '{') {
|
|
8
|
-
variableString = `{${variableString}}`;
|
|
9
|
-
}
|
|
10
|
-
const map = {};
|
|
11
|
-
for (const obj of array) {
|
|
12
|
-
const value = string_util_1.StringUtil.parseVariables(variableString, obj);
|
|
13
|
-
map[value] = obj;
|
|
14
|
-
}
|
|
15
|
-
return map;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.MapUtil = MapUtil;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MapUtil = void 0;
|
|
4
|
+
const string_util_1 = require("../string-util/string-util");
|
|
5
|
+
class MapUtil {
|
|
6
|
+
static keyBy(array, variableString) {
|
|
7
|
+
if (variableString.charAt(0) !== '{') {
|
|
8
|
+
variableString = `{${variableString}}`;
|
|
9
|
+
}
|
|
10
|
+
const map = {};
|
|
11
|
+
for (const obj of array) {
|
|
12
|
+
const value = string_util_1.StringUtil.parseVariables(variableString, obj);
|
|
13
|
+
map[value] = obj;
|
|
14
|
+
}
|
|
15
|
+
return map;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.MapUtil = MapUtil;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function applyChangesIfEqual(target: any, priorSourceValues: any, newSourceValues: any, propertyKeys: any): void;
|
|
2
|
-
export declare function determineChangesIfEqual(target: any, priorSourceValues: any, newSourceValues: any, propertyKeys: any): any;
|
|
1
|
+
export declare function applyChangesIfEqual(target: any, priorSourceValues: any, newSourceValues: any, propertyKeys: any): void;
|
|
2
|
+
export declare function determineChangesIfEqual(target: any, priorSourceValues: any, newSourceValues: any, propertyKeys: any): any;
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.determineChangesIfEqual = exports.applyChangesIfEqual = void 0;
|
|
4
|
-
function applyChangesIfEqual(target, priorSourceValues, newSourceValues, propertyKeys) {
|
|
5
|
-
const changes = determineChangesIfEqual(target, priorSourceValues, newSourceValues, propertyKeys);
|
|
6
|
-
if (changes) {
|
|
7
|
-
Object.assign(target, changes);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
exports.applyChangesIfEqual = applyChangesIfEqual;
|
|
11
|
-
function determineChangesIfEqual(target, priorSourceValues, newSourceValues, propertyKeys) {
|
|
12
|
-
const changes = {};
|
|
13
|
-
for (const propKey of propertyKeys) {
|
|
14
|
-
if (newSourceValues[propKey] === undefined) {
|
|
15
|
-
continue;
|
|
16
|
-
}
|
|
17
|
-
if (!target[propKey] || (priorSourceValues[propKey] === target[propKey])) {
|
|
18
|
-
changes[propKey] = newSourceValues[propKey];
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return changes;
|
|
22
|
-
}
|
|
23
|
-
exports.determineChangesIfEqual = determineChangesIfEqual;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.determineChangesIfEqual = exports.applyChangesIfEqual = void 0;
|
|
4
|
+
function applyChangesIfEqual(target, priorSourceValues, newSourceValues, propertyKeys) {
|
|
5
|
+
const changes = determineChangesIfEqual(target, priorSourceValues, newSourceValues, propertyKeys);
|
|
6
|
+
if (changes) {
|
|
7
|
+
Object.assign(target, changes);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.applyChangesIfEqual = applyChangesIfEqual;
|
|
11
|
+
function determineChangesIfEqual(target, priorSourceValues, newSourceValues, propertyKeys) {
|
|
12
|
+
const changes = {};
|
|
13
|
+
for (const propKey of propertyKeys) {
|
|
14
|
+
if (newSourceValues[propKey] === undefined) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
if (!target[propKey] || (priorSourceValues[propKey] === target[propKey])) {
|
|
18
|
+
changes[propKey] = newSourceValues[propKey];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return changes;
|
|
22
|
+
}
|
|
23
|
+
exports.determineChangesIfEqual = determineChangesIfEqual;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function cloneDeep(obj: any): any;
|
|
1
|
+
export declare function cloneDeep(obj: any): any;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cloneDeep = void 0;
|
|
4
|
-
function cloneDeep(obj) {
|
|
5
|
-
if (!obj) {
|
|
6
|
-
return null;
|
|
7
|
-
}
|
|
8
|
-
return JSON.parse(JSON.stringify(obj));
|
|
9
|
-
}
|
|
10
|
-
exports.cloneDeep = cloneDeep;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cloneDeep = void 0;
|
|
4
|
+
function cloneDeep(obj) {
|
|
5
|
+
if (!obj) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
return JSON.parse(JSON.stringify(obj));
|
|
9
|
+
}
|
|
10
|
+
exports.cloneDeep = cloneDeep;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export interface ObjectDiff {
|
|
2
|
-
propertyName: string;
|
|
3
|
-
oldValue: any;
|
|
4
|
-
newValue: any;
|
|
5
|
-
}
|
|
6
|
-
export declare function getObjectDiffs(before: any, after: any, prefix: string): ObjectDiff[];
|
|
7
|
-
export declare function getObjectDiff(before: any, after: any, name: any): ObjectDiff;
|
|
1
|
+
export interface ObjectDiff {
|
|
2
|
+
propertyName: string;
|
|
3
|
+
oldValue: any;
|
|
4
|
+
newValue: any;
|
|
5
|
+
}
|
|
6
|
+
export declare function getObjectDiffs(before: any, after: any, prefix: string): ObjectDiff[];
|
|
7
|
+
export declare function getObjectDiff(before: any, after: any, name: any): ObjectDiff;
|
|
@@ -1,87 +1,87 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getObjectDiff = exports.getObjectDiffs = void 0;
|
|
4
|
-
function getObjectDiffs(before, after, prefix) {
|
|
5
|
-
const diffs = [];
|
|
6
|
-
if (!before || !after) {
|
|
7
|
-
return diffs;
|
|
8
|
-
}
|
|
9
|
-
const beforeProperties = Object.getOwnPropertyNames(before);
|
|
10
|
-
const afterProperties = Object.getOwnPropertyNames(after);
|
|
11
|
-
const addedProperties = afterProperties.filter(value => !beforeProperties.includes(value));
|
|
12
|
-
const deletedProperties = beforeProperties.filter(value => !afterProperties.includes(value));
|
|
13
|
-
const commonProperties = beforeProperties.filter(value => afterProperties.includes(value));
|
|
14
|
-
addedProperties.forEach(addedProperty => {
|
|
15
|
-
diffs.push(getObjectDiff(null, after[addedProperty], prefix + addedProperty));
|
|
16
|
-
});
|
|
17
|
-
deletedProperties.forEach(deletedProperty => {
|
|
18
|
-
diffs.push(getObjectDiff(before[deletedProperty], null, prefix + deletedProperty));
|
|
19
|
-
});
|
|
20
|
-
commonProperties.forEach(commonProperty => {
|
|
21
|
-
const beforeVal = before[commonProperty];
|
|
22
|
-
const afterVal = after[commonProperty];
|
|
23
|
-
if (beforeVal === afterVal) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
if (beforeVal === null || afterVal === null) {
|
|
27
|
-
diffs.push(getObjectDiff(beforeVal, afterVal, prefix + commonProperty));
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
if (typeof beforeVal !== typeof afterVal) {
|
|
31
|
-
diffs.push(getObjectDiff(beforeVal, afterVal, prefix + commonProperty));
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
if (isObject(beforeVal)) {
|
|
35
|
-
if (isDate(beforeVal)) {
|
|
36
|
-
if (!datesEqual(beforeVal, afterVal)) {
|
|
37
|
-
diffs.push(getObjectDiff(beforeVal, afterVal, prefix + commonProperty));
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
else if (Array.isArray(beforeVal)) {
|
|
41
|
-
const beforeArray = [...beforeVal].sort(sortFunc);
|
|
42
|
-
const afterArray = [...afterVal].sort(sortFunc);
|
|
43
|
-
if (JSON.stringify(beforeArray) !== JSON.stringify(afterArray)) {
|
|
44
|
-
diffs.push(getObjectDiff(beforeVal, afterVal, prefix + commonProperty));
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
const nestedObjectDiffs = getObjectDiffs(beforeVal, afterVal, prefix + commonProperty + '.');
|
|
49
|
-
diffs.push(...nestedObjectDiffs);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
if (beforeVal !== afterVal) {
|
|
54
|
-
diffs.push(getObjectDiff(beforeVal, afterVal, prefix + commonProperty));
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
return diffs;
|
|
59
|
-
}
|
|
60
|
-
exports.getObjectDiffs = getObjectDiffs;
|
|
61
|
-
function getObjectDiff(before, after, name) {
|
|
62
|
-
const diff = {
|
|
63
|
-
propertyName: name,
|
|
64
|
-
oldValue: before,
|
|
65
|
-
newValue: after,
|
|
66
|
-
};
|
|
67
|
-
return diff;
|
|
68
|
-
}
|
|
69
|
-
exports.getObjectDiff = getObjectDiff;
|
|
70
|
-
function sortFunc(x, y) {
|
|
71
|
-
const pre = ['string', 'number', 'bool'];
|
|
72
|
-
if (typeof x !== typeof y)
|
|
73
|
-
return pre.indexOf(typeof y) - pre.indexOf(typeof x);
|
|
74
|
-
if (x === y)
|
|
75
|
-
return 0;
|
|
76
|
-
else
|
|
77
|
-
return (x > y) ? 1 : -1;
|
|
78
|
-
}
|
|
79
|
-
function isObject(object) {
|
|
80
|
-
return object != null && typeof object === 'object';
|
|
81
|
-
}
|
|
82
|
-
function isDate(object) {
|
|
83
|
-
return object != null && object instanceof Date;
|
|
84
|
-
}
|
|
85
|
-
function datesEqual(date1, date2) {
|
|
86
|
-
return date1.getTime() === date2.getTime();
|
|
87
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getObjectDiff = exports.getObjectDiffs = void 0;
|
|
4
|
+
function getObjectDiffs(before, after, prefix) {
|
|
5
|
+
const diffs = [];
|
|
6
|
+
if (!before || !after) {
|
|
7
|
+
return diffs;
|
|
8
|
+
}
|
|
9
|
+
const beforeProperties = Object.getOwnPropertyNames(before);
|
|
10
|
+
const afterProperties = Object.getOwnPropertyNames(after);
|
|
11
|
+
const addedProperties = afterProperties.filter(value => !beforeProperties.includes(value));
|
|
12
|
+
const deletedProperties = beforeProperties.filter(value => !afterProperties.includes(value));
|
|
13
|
+
const commonProperties = beforeProperties.filter(value => afterProperties.includes(value));
|
|
14
|
+
addedProperties.forEach(addedProperty => {
|
|
15
|
+
diffs.push(getObjectDiff(null, after[addedProperty], prefix + addedProperty));
|
|
16
|
+
});
|
|
17
|
+
deletedProperties.forEach(deletedProperty => {
|
|
18
|
+
diffs.push(getObjectDiff(before[deletedProperty], null, prefix + deletedProperty));
|
|
19
|
+
});
|
|
20
|
+
commonProperties.forEach(commonProperty => {
|
|
21
|
+
const beforeVal = before[commonProperty];
|
|
22
|
+
const afterVal = after[commonProperty];
|
|
23
|
+
if (beforeVal === afterVal) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (beforeVal === null || afterVal === null) {
|
|
27
|
+
diffs.push(getObjectDiff(beforeVal, afterVal, prefix + commonProperty));
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (typeof beforeVal !== typeof afterVal) {
|
|
31
|
+
diffs.push(getObjectDiff(beforeVal, afterVal, prefix + commonProperty));
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (isObject(beforeVal)) {
|
|
35
|
+
if (isDate(beforeVal)) {
|
|
36
|
+
if (!datesEqual(beforeVal, afterVal)) {
|
|
37
|
+
diffs.push(getObjectDiff(beforeVal, afterVal, prefix + commonProperty));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else if (Array.isArray(beforeVal)) {
|
|
41
|
+
const beforeArray = [...beforeVal].sort(sortFunc);
|
|
42
|
+
const afterArray = [...afterVal].sort(sortFunc);
|
|
43
|
+
if (JSON.stringify(beforeArray) !== JSON.stringify(afterArray)) {
|
|
44
|
+
diffs.push(getObjectDiff(beforeVal, afterVal, prefix + commonProperty));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
const nestedObjectDiffs = getObjectDiffs(beforeVal, afterVal, prefix + commonProperty + '.');
|
|
49
|
+
diffs.push(...nestedObjectDiffs);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
if (beforeVal !== afterVal) {
|
|
54
|
+
diffs.push(getObjectDiff(beforeVal, afterVal, prefix + commonProperty));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
return diffs;
|
|
59
|
+
}
|
|
60
|
+
exports.getObjectDiffs = getObjectDiffs;
|
|
61
|
+
function getObjectDiff(before, after, name) {
|
|
62
|
+
const diff = {
|
|
63
|
+
propertyName: name,
|
|
64
|
+
oldValue: before,
|
|
65
|
+
newValue: after,
|
|
66
|
+
};
|
|
67
|
+
return diff;
|
|
68
|
+
}
|
|
69
|
+
exports.getObjectDiff = getObjectDiff;
|
|
70
|
+
function sortFunc(x, y) {
|
|
71
|
+
const pre = ['string', 'number', 'bool'];
|
|
72
|
+
if (typeof x !== typeof y)
|
|
73
|
+
return pre.indexOf(typeof y) - pre.indexOf(typeof x);
|
|
74
|
+
if (x === y)
|
|
75
|
+
return 0;
|
|
76
|
+
else
|
|
77
|
+
return (x > y) ? 1 : -1;
|
|
78
|
+
}
|
|
79
|
+
function isObject(object) {
|
|
80
|
+
return object != null && typeof object === 'object';
|
|
81
|
+
}
|
|
82
|
+
function isDate(object) {
|
|
83
|
+
return object != null && object instanceof Date;
|
|
84
|
+
}
|
|
85
|
+
function datesEqual(date1, date2) {
|
|
86
|
+
return date1.getTime() === date2.getTime();
|
|
87
|
+
}
|
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
export declare const item1Assortment1: {
|
|
2
|
-
id: string;
|
|
3
|
-
stringProperty: string;
|
|
4
|
-
intProperty: number;
|
|
5
|
-
boolProperty: boolean;
|
|
6
|
-
dateProperty: Date;
|
|
7
|
-
arrayProperty: string[];
|
|
8
|
-
};
|
|
9
|
-
export declare const item1Assortment2: {
|
|
10
|
-
id: string;
|
|
11
|
-
stringProperty: string;
|
|
12
|
-
intProperty: number;
|
|
13
|
-
boolProperty: boolean;
|
|
14
|
-
dateProperty: Date;
|
|
15
|
-
arrayProperty: string[];
|
|
16
|
-
};
|
|
17
|
-
export declare const item1Assortment3: {
|
|
18
|
-
id: string;
|
|
19
|
-
stringProperty: string;
|
|
20
|
-
intProperty: number;
|
|
21
|
-
boolProperty: boolean;
|
|
22
|
-
dateProperty: Date;
|
|
23
|
-
arrayProperty: any;
|
|
24
|
-
};
|
|
25
|
-
export declare const item2Assortment1: {
|
|
26
|
-
id: string;
|
|
27
|
-
stringProperty: string;
|
|
28
|
-
intProperty: number;
|
|
29
|
-
boolProperty: boolean;
|
|
30
|
-
dateProperty: Date;
|
|
31
|
-
arrayProperty: string[];
|
|
32
|
-
};
|
|
33
|
-
export declare const item2Assortment2ScalarChange: {
|
|
34
|
-
id: string;
|
|
35
|
-
stringProperty: string;
|
|
36
|
-
intProperty: number;
|
|
37
|
-
boolProperty: boolean;
|
|
38
|
-
dateProperty: Date;
|
|
39
|
-
arrayProperty: string[];
|
|
40
|
-
};
|
|
41
|
-
export declare const item2Assortment2ArrayChange: {
|
|
42
|
-
id: string;
|
|
43
|
-
stringProperty: string;
|
|
44
|
-
intProperty: number;
|
|
45
|
-
boolProperty: boolean;
|
|
46
|
-
dateProperty: Date;
|
|
47
|
-
arrayProperty: string[];
|
|
48
|
-
};
|
|
49
|
-
export declare const item2Assortment2DateChange: {
|
|
50
|
-
id: string;
|
|
51
|
-
stringProperty: string;
|
|
52
|
-
intProperty: number;
|
|
53
|
-
boolProperty: boolean;
|
|
54
|
-
dateProperty: Date;
|
|
55
|
-
arrayProperty: string[];
|
|
56
|
-
};
|
|
57
|
-
export declare const item3Assortment1: {
|
|
58
|
-
id: string;
|
|
59
|
-
stringProperty: string;
|
|
60
|
-
intProperty: number;
|
|
61
|
-
boolProperty: boolean;
|
|
62
|
-
dateProperty: Date;
|
|
63
|
-
arrayProperty: string[];
|
|
64
|
-
nestedProperties: {
|
|
65
|
-
nestedBoolProperty: boolean;
|
|
66
|
-
nestedDateProperty: Date;
|
|
67
|
-
nestedArrayProperty: string[];
|
|
68
|
-
nestedObject: {
|
|
69
|
-
nestedBoolProperty: boolean;
|
|
70
|
-
};
|
|
71
|
-
};
|
|
72
|
-
};
|
|
73
|
-
export declare const item3Assortment2NestedChanges: {
|
|
74
|
-
id: string;
|
|
75
|
-
stringProperty: string;
|
|
76
|
-
intProperty: number;
|
|
77
|
-
boolProperty: boolean;
|
|
78
|
-
dateProperty: Date;
|
|
79
|
-
arrayProperty: string[];
|
|
80
|
-
nestedProperties: {
|
|
81
|
-
nestedBoolProperty: boolean;
|
|
82
|
-
nestedDateProperty: Date;
|
|
83
|
-
nestedArrayProperty: string[];
|
|
84
|
-
nestedObject: {
|
|
85
|
-
nestedBoolProperty: boolean;
|
|
86
|
-
};
|
|
87
|
-
};
|
|
88
|
-
};
|
|
1
|
+
export declare const item1Assortment1: {
|
|
2
|
+
id: string;
|
|
3
|
+
stringProperty: string;
|
|
4
|
+
intProperty: number;
|
|
5
|
+
boolProperty: boolean;
|
|
6
|
+
dateProperty: Date;
|
|
7
|
+
arrayProperty: string[];
|
|
8
|
+
};
|
|
9
|
+
export declare const item1Assortment2: {
|
|
10
|
+
id: string;
|
|
11
|
+
stringProperty: string;
|
|
12
|
+
intProperty: number;
|
|
13
|
+
boolProperty: boolean;
|
|
14
|
+
dateProperty: Date;
|
|
15
|
+
arrayProperty: string[];
|
|
16
|
+
};
|
|
17
|
+
export declare const item1Assortment3: {
|
|
18
|
+
id: string;
|
|
19
|
+
stringProperty: string;
|
|
20
|
+
intProperty: number;
|
|
21
|
+
boolProperty: boolean;
|
|
22
|
+
dateProperty: Date;
|
|
23
|
+
arrayProperty: any;
|
|
24
|
+
};
|
|
25
|
+
export declare const item2Assortment1: {
|
|
26
|
+
id: string;
|
|
27
|
+
stringProperty: string;
|
|
28
|
+
intProperty: number;
|
|
29
|
+
boolProperty: boolean;
|
|
30
|
+
dateProperty: Date;
|
|
31
|
+
arrayProperty: string[];
|
|
32
|
+
};
|
|
33
|
+
export declare const item2Assortment2ScalarChange: {
|
|
34
|
+
id: string;
|
|
35
|
+
stringProperty: string;
|
|
36
|
+
intProperty: number;
|
|
37
|
+
boolProperty: boolean;
|
|
38
|
+
dateProperty: Date;
|
|
39
|
+
arrayProperty: string[];
|
|
40
|
+
};
|
|
41
|
+
export declare const item2Assortment2ArrayChange: {
|
|
42
|
+
id: string;
|
|
43
|
+
stringProperty: string;
|
|
44
|
+
intProperty: number;
|
|
45
|
+
boolProperty: boolean;
|
|
46
|
+
dateProperty: Date;
|
|
47
|
+
arrayProperty: string[];
|
|
48
|
+
};
|
|
49
|
+
export declare const item2Assortment2DateChange: {
|
|
50
|
+
id: string;
|
|
51
|
+
stringProperty: string;
|
|
52
|
+
intProperty: number;
|
|
53
|
+
boolProperty: boolean;
|
|
54
|
+
dateProperty: Date;
|
|
55
|
+
arrayProperty: string[];
|
|
56
|
+
};
|
|
57
|
+
export declare const item3Assortment1: {
|
|
58
|
+
id: string;
|
|
59
|
+
stringProperty: string;
|
|
60
|
+
intProperty: number;
|
|
61
|
+
boolProperty: boolean;
|
|
62
|
+
dateProperty: Date;
|
|
63
|
+
arrayProperty: string[];
|
|
64
|
+
nestedProperties: {
|
|
65
|
+
nestedBoolProperty: boolean;
|
|
66
|
+
nestedDateProperty: Date;
|
|
67
|
+
nestedArrayProperty: string[];
|
|
68
|
+
nestedObject: {
|
|
69
|
+
nestedBoolProperty: boolean;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
export declare const item3Assortment2NestedChanges: {
|
|
74
|
+
id: string;
|
|
75
|
+
stringProperty: string;
|
|
76
|
+
intProperty: number;
|
|
77
|
+
boolProperty: boolean;
|
|
78
|
+
dateProperty: Date;
|
|
79
|
+
arrayProperty: string[];
|
|
80
|
+
nestedProperties: {
|
|
81
|
+
nestedBoolProperty: boolean;
|
|
82
|
+
nestedDateProperty: Date;
|
|
83
|
+
nestedArrayProperty: string[];
|
|
84
|
+
nestedObject: {
|
|
85
|
+
nestedBoolProperty: boolean;
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
};
|
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.item3Assortment2NestedChanges = exports.item3Assortment1 = exports.item2Assortment2DateChange = exports.item2Assortment2ArrayChange = exports.item2Assortment2ScalarChange = exports.item2Assortment1 = exports.item1Assortment3 = exports.item1Assortment2 = exports.item1Assortment1 = void 0;
|
|
4
|
-
exports.item1Assortment1 = {
|
|
5
|
-
id: 'id1',
|
|
6
|
-
stringProperty: 'stringProperty1',
|
|
7
|
-
intProperty: 1,
|
|
8
|
-
boolProperty: false,
|
|
9
|
-
dateProperty: new Date('12/22/1994'),
|
|
10
|
-
arrayProperty: ['A', 'B', 'C'],
|
|
11
|
-
};
|
|
12
|
-
exports.item1Assortment2 = {
|
|
13
|
-
id: 'id1',
|
|
14
|
-
stringProperty: 'stringProperty1',
|
|
15
|
-
intProperty: 1,
|
|
16
|
-
boolProperty: false,
|
|
17
|
-
dateProperty: new Date('12/22/1994'),
|
|
18
|
-
arrayProperty: ['A', 'B', 'C'],
|
|
19
|
-
};
|
|
20
|
-
exports.item1Assortment3 = {
|
|
21
|
-
id: 'id1',
|
|
22
|
-
stringProperty: 'stringProperty1',
|
|
23
|
-
intProperty: 1,
|
|
24
|
-
boolProperty: false,
|
|
25
|
-
dateProperty: new Date('12/22/1994'),
|
|
26
|
-
arrayProperty: null,
|
|
27
|
-
};
|
|
28
|
-
exports.item2Assortment1 = {
|
|
29
|
-
id: 'id2',
|
|
30
|
-
stringProperty: 'stringProperty2',
|
|
31
|
-
intProperty: 2,
|
|
32
|
-
boolProperty: false,
|
|
33
|
-
dateProperty: new Date('12/23/1994'),
|
|
34
|
-
arrayProperty: ['A', 'B'],
|
|
35
|
-
};
|
|
36
|
-
exports.item2Assortment2ScalarChange = {
|
|
37
|
-
id: 'id2',
|
|
38
|
-
stringProperty: 'stringProperty3Update',
|
|
39
|
-
intProperty: 4,
|
|
40
|
-
boolProperty: true,
|
|
41
|
-
dateProperty: new Date('12/23/1994'),
|
|
42
|
-
arrayProperty: ['A', 'B'],
|
|
43
|
-
};
|
|
44
|
-
exports.item2Assortment2ArrayChange = {
|
|
45
|
-
id: 'id2',
|
|
46
|
-
stringProperty: 'stringProperty2',
|
|
47
|
-
intProperty: 2,
|
|
48
|
-
boolProperty: false,
|
|
49
|
-
dateProperty: new Date('12/23/1994'),
|
|
50
|
-
arrayProperty: ['A', 'B', 'D'],
|
|
51
|
-
};
|
|
52
|
-
exports.item2Assortment2DateChange = {
|
|
53
|
-
id: 'id2',
|
|
54
|
-
stringProperty: 'stringProperty2',
|
|
55
|
-
intProperty: 2,
|
|
56
|
-
boolProperty: false,
|
|
57
|
-
dateProperty: new Date('12/23/1995'),
|
|
58
|
-
arrayProperty: ['A', 'B'],
|
|
59
|
-
};
|
|
60
|
-
exports.item3Assortment1 = {
|
|
61
|
-
id: 'id3',
|
|
62
|
-
stringProperty: 'stringProperty2',
|
|
63
|
-
intProperty: 2,
|
|
64
|
-
boolProperty: false,
|
|
65
|
-
dateProperty: new Date('12/23/1994'),
|
|
66
|
-
arrayProperty: ['A', 'B'],
|
|
67
|
-
nestedProperties: {
|
|
68
|
-
nestedBoolProperty: false,
|
|
69
|
-
nestedDateProperty: new Date('12/22/1994'),
|
|
70
|
-
nestedArrayProperty: ['C', 'D'],
|
|
71
|
-
nestedObject: {
|
|
72
|
-
nestedBoolProperty: false,
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
exports.item3Assortment2NestedChanges = {
|
|
77
|
-
id: 'id3',
|
|
78
|
-
stringProperty: 'stringProperty2',
|
|
79
|
-
intProperty: 2,
|
|
80
|
-
boolProperty: true,
|
|
81
|
-
dateProperty: new Date('12/23/1994'),
|
|
82
|
-
arrayProperty: ['A', 'B'],
|
|
83
|
-
nestedProperties: {
|
|
84
|
-
nestedBoolProperty: false,
|
|
85
|
-
nestedDateProperty: new Date('12/23/1995'),
|
|
86
|
-
nestedArrayProperty: ['C', 'D', 'A'],
|
|
87
|
-
nestedObject: {
|
|
88
|
-
nestedBoolProperty: true,
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.item3Assortment2NestedChanges = exports.item3Assortment1 = exports.item2Assortment2DateChange = exports.item2Assortment2ArrayChange = exports.item2Assortment2ScalarChange = exports.item2Assortment1 = exports.item1Assortment3 = exports.item1Assortment2 = exports.item1Assortment1 = void 0;
|
|
4
|
+
exports.item1Assortment1 = {
|
|
5
|
+
id: 'id1',
|
|
6
|
+
stringProperty: 'stringProperty1',
|
|
7
|
+
intProperty: 1,
|
|
8
|
+
boolProperty: false,
|
|
9
|
+
dateProperty: new Date('12/22/1994'),
|
|
10
|
+
arrayProperty: ['A', 'B', 'C'],
|
|
11
|
+
};
|
|
12
|
+
exports.item1Assortment2 = {
|
|
13
|
+
id: 'id1',
|
|
14
|
+
stringProperty: 'stringProperty1',
|
|
15
|
+
intProperty: 1,
|
|
16
|
+
boolProperty: false,
|
|
17
|
+
dateProperty: new Date('12/22/1994'),
|
|
18
|
+
arrayProperty: ['A', 'B', 'C'],
|
|
19
|
+
};
|
|
20
|
+
exports.item1Assortment3 = {
|
|
21
|
+
id: 'id1',
|
|
22
|
+
stringProperty: 'stringProperty1',
|
|
23
|
+
intProperty: 1,
|
|
24
|
+
boolProperty: false,
|
|
25
|
+
dateProperty: new Date('12/22/1994'),
|
|
26
|
+
arrayProperty: null,
|
|
27
|
+
};
|
|
28
|
+
exports.item2Assortment1 = {
|
|
29
|
+
id: 'id2',
|
|
30
|
+
stringProperty: 'stringProperty2',
|
|
31
|
+
intProperty: 2,
|
|
32
|
+
boolProperty: false,
|
|
33
|
+
dateProperty: new Date('12/23/1994'),
|
|
34
|
+
arrayProperty: ['A', 'B'],
|
|
35
|
+
};
|
|
36
|
+
exports.item2Assortment2ScalarChange = {
|
|
37
|
+
id: 'id2',
|
|
38
|
+
stringProperty: 'stringProperty3Update',
|
|
39
|
+
intProperty: 4,
|
|
40
|
+
boolProperty: true,
|
|
41
|
+
dateProperty: new Date('12/23/1994'),
|
|
42
|
+
arrayProperty: ['A', 'B'],
|
|
43
|
+
};
|
|
44
|
+
exports.item2Assortment2ArrayChange = {
|
|
45
|
+
id: 'id2',
|
|
46
|
+
stringProperty: 'stringProperty2',
|
|
47
|
+
intProperty: 2,
|
|
48
|
+
boolProperty: false,
|
|
49
|
+
dateProperty: new Date('12/23/1994'),
|
|
50
|
+
arrayProperty: ['A', 'B', 'D'],
|
|
51
|
+
};
|
|
52
|
+
exports.item2Assortment2DateChange = {
|
|
53
|
+
id: 'id2',
|
|
54
|
+
stringProperty: 'stringProperty2',
|
|
55
|
+
intProperty: 2,
|
|
56
|
+
boolProperty: false,
|
|
57
|
+
dateProperty: new Date('12/23/1995'),
|
|
58
|
+
arrayProperty: ['A', 'B'],
|
|
59
|
+
};
|
|
60
|
+
exports.item3Assortment1 = {
|
|
61
|
+
id: 'id3',
|
|
62
|
+
stringProperty: 'stringProperty2',
|
|
63
|
+
intProperty: 2,
|
|
64
|
+
boolProperty: false,
|
|
65
|
+
dateProperty: new Date('12/23/1994'),
|
|
66
|
+
arrayProperty: ['A', 'B'],
|
|
67
|
+
nestedProperties: {
|
|
68
|
+
nestedBoolProperty: false,
|
|
69
|
+
nestedDateProperty: new Date('12/22/1994'),
|
|
70
|
+
nestedArrayProperty: ['C', 'D'],
|
|
71
|
+
nestedObject: {
|
|
72
|
+
nestedBoolProperty: false,
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
exports.item3Assortment2NestedChanges = {
|
|
77
|
+
id: 'id3',
|
|
78
|
+
stringProperty: 'stringProperty2',
|
|
79
|
+
intProperty: 2,
|
|
80
|
+
boolProperty: true,
|
|
81
|
+
dateProperty: new Date('12/23/1994'),
|
|
82
|
+
arrayProperty: ['A', 'B'],
|
|
83
|
+
nestedProperties: {
|
|
84
|
+
nestedBoolProperty: false,
|
|
85
|
+
nestedDateProperty: new Date('12/23/1995'),
|
|
86
|
+
nestedArrayProperty: ['C', 'D', 'A'],
|
|
87
|
+
nestedObject: {
|
|
88
|
+
nestedBoolProperty: true,
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function isObject(item: any): boolean;
|
|
1
|
+
export declare function isObject(item: any): boolean;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isObject = void 0;
|
|
4
|
-
function isObject(item) {
|
|
5
|
-
return (item && typeof item === 'object' && !Array.isArray(item));
|
|
6
|
-
}
|
|
7
|
-
exports.isObject = isObject;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isObject = void 0;
|
|
4
|
+
function isObject(item) {
|
|
5
|
+
return (item && typeof item === 'object' && !Array.isArray(item));
|
|
6
|
+
}
|
|
7
|
+
exports.isObject = isObject;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function mergeDeep(target: any, ...sources: any[]): any;
|
|
1
|
+
export declare function mergeDeep(target: any, ...sources: any[]): any;
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mergeDeep = void 0;
|
|
4
|
-
const isObject_1 = require("../isObject/isObject");
|
|
5
|
-
function mergeDeep(target, ...sources) {
|
|
6
|
-
if (!sources.length)
|
|
7
|
-
return target;
|
|
8
|
-
const source = sources.shift();
|
|
9
|
-
if ((0, isObject_1.isObject)(target) && (0, isObject_1.isObject)(source)) {
|
|
10
|
-
for (const key in source) {
|
|
11
|
-
if ((0, isObject_1.isObject)(source[key]) && !isDate(source[key])) {
|
|
12
|
-
if (!target[key])
|
|
13
|
-
Object.assign(target, { [key]: {} });
|
|
14
|
-
mergeDeep(target[key], source[key]);
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
Object.assign(target, { [key]: source[key] });
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return mergeDeep(target, ...sources);
|
|
22
|
-
}
|
|
23
|
-
exports.mergeDeep = mergeDeep;
|
|
24
|
-
function isDate(object) {
|
|
25
|
-
return object != null && object instanceof Date;
|
|
26
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mergeDeep = void 0;
|
|
4
|
+
const isObject_1 = require("../isObject/isObject");
|
|
5
|
+
function mergeDeep(target, ...sources) {
|
|
6
|
+
if (!sources.length)
|
|
7
|
+
return target;
|
|
8
|
+
const source = sources.shift();
|
|
9
|
+
if ((0, isObject_1.isObject)(target) && (0, isObject_1.isObject)(source)) {
|
|
10
|
+
for (const key in source) {
|
|
11
|
+
if ((0, isObject_1.isObject)(source[key]) && !isDate(source[key])) {
|
|
12
|
+
if (!target[key])
|
|
13
|
+
Object.assign(target, { [key]: {} });
|
|
14
|
+
mergeDeep(target[key], source[key]);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
Object.assign(target, { [key]: source[key] });
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return mergeDeep(target, ...sources);
|
|
22
|
+
}
|
|
23
|
+
exports.mergeDeep = mergeDeep;
|
|
24
|
+
function isDate(object) {
|
|
25
|
+
return object != null && object instanceof Date;
|
|
26
|
+
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { cloneDeep } from './cloneDeep/cloneDeep';
|
|
2
|
-
import { isObject } from './isObject/isObject';
|
|
3
|
-
import { mergeDeep } from './mergeDeep/mergeDeep';
|
|
4
|
-
import { getObjectDiffs } from './compareDeep/compareDeep';
|
|
5
|
-
import { applyChangesIfEqual, determineChangesIfEqual } from './applyChangesIfEqual/applyChangesIfEqual';
|
|
6
|
-
export { ObjectDiff } from './compareDeep/compareDeep';
|
|
7
|
-
export declare class ObjectUtil {
|
|
8
|
-
static getByPath(obj: any, path: string, def?: any): any;
|
|
9
|
-
static setByPath(obj: any, path: string, value: any): void;
|
|
10
|
-
static isObject: typeof isObject;
|
|
11
|
-
static mergeDeep: typeof mergeDeep;
|
|
12
|
-
static cloneDeep: typeof cloneDeep;
|
|
13
|
-
static compareDeep: typeof getObjectDiffs;
|
|
14
|
-
static applyChangesIfEqual: typeof applyChangesIfEqual;
|
|
15
|
-
static determineChangesIfEqual: typeof determineChangesIfEqual;
|
|
16
|
-
}
|
|
1
|
+
import { cloneDeep } from './cloneDeep/cloneDeep';
|
|
2
|
+
import { isObject } from './isObject/isObject';
|
|
3
|
+
import { mergeDeep } from './mergeDeep/mergeDeep';
|
|
4
|
+
import { getObjectDiffs } from './compareDeep/compareDeep';
|
|
5
|
+
import { applyChangesIfEqual, determineChangesIfEqual } from './applyChangesIfEqual/applyChangesIfEqual';
|
|
6
|
+
export { ObjectDiff } from './compareDeep/compareDeep';
|
|
7
|
+
export declare class ObjectUtil {
|
|
8
|
+
static getByPath(obj: any, path: string, def?: any): any;
|
|
9
|
+
static setByPath(obj: any, path: string, value: any): void;
|
|
10
|
+
static isObject: typeof isObject;
|
|
11
|
+
static mergeDeep: typeof mergeDeep;
|
|
12
|
+
static cloneDeep: typeof cloneDeep;
|
|
13
|
+
static compareDeep: typeof getObjectDiffs;
|
|
14
|
+
static applyChangesIfEqual: typeof applyChangesIfEqual;
|
|
15
|
+
static determineChangesIfEqual: typeof determineChangesIfEqual;
|
|
16
|
+
}
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ObjectUtil = void 0;
|
|
4
|
-
const cloneDeep_1 = require("./cloneDeep/cloneDeep");
|
|
5
|
-
const isObject_1 = require("./isObject/isObject");
|
|
6
|
-
const mergeDeep_1 = require("./mergeDeep/mergeDeep");
|
|
7
|
-
const compareDeep_1 = require("./compareDeep/compareDeep");
|
|
8
|
-
const applyChangesIfEqual_1 = require("./applyChangesIfEqual/applyChangesIfEqual");
|
|
9
|
-
class ObjectUtil {
|
|
10
|
-
static getByPath(obj, path, def = null) {
|
|
11
|
-
const pathUnits = path
|
|
12
|
-
.replace(/\[/g, '.')
|
|
13
|
-
.replace(/]/g, '')
|
|
14
|
-
.split('.');
|
|
15
|
-
pathUnits.forEach((level) => {
|
|
16
|
-
if (obj) {
|
|
17
|
-
obj = obj[level];
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
if (obj === undefined) {
|
|
21
|
-
return def;
|
|
22
|
-
}
|
|
23
|
-
return obj;
|
|
24
|
-
}
|
|
25
|
-
static setByPath(obj, path, value) {
|
|
26
|
-
const a = path.split('.');
|
|
27
|
-
let o = obj;
|
|
28
|
-
while (a.length - 1) {
|
|
29
|
-
const n = a.shift();
|
|
30
|
-
if (!(n in o))
|
|
31
|
-
o[n] = {};
|
|
32
|
-
o = o[n];
|
|
33
|
-
}
|
|
34
|
-
o[a[0]] = value;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.ObjectUtil = ObjectUtil;
|
|
38
|
-
ObjectUtil.isObject = isObject_1.isObject;
|
|
39
|
-
ObjectUtil.mergeDeep = mergeDeep_1.mergeDeep;
|
|
40
|
-
ObjectUtil.cloneDeep = cloneDeep_1.cloneDeep;
|
|
41
|
-
ObjectUtil.compareDeep = compareDeep_1.getObjectDiffs;
|
|
42
|
-
ObjectUtil.applyChangesIfEqual = applyChangesIfEqual_1.applyChangesIfEqual;
|
|
43
|
-
ObjectUtil.determineChangesIfEqual = applyChangesIfEqual_1.determineChangesIfEqual;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ObjectUtil = void 0;
|
|
4
|
+
const cloneDeep_1 = require("./cloneDeep/cloneDeep");
|
|
5
|
+
const isObject_1 = require("./isObject/isObject");
|
|
6
|
+
const mergeDeep_1 = require("./mergeDeep/mergeDeep");
|
|
7
|
+
const compareDeep_1 = require("./compareDeep/compareDeep");
|
|
8
|
+
const applyChangesIfEqual_1 = require("./applyChangesIfEqual/applyChangesIfEqual");
|
|
9
|
+
class ObjectUtil {
|
|
10
|
+
static getByPath(obj, path, def = null) {
|
|
11
|
+
const pathUnits = path
|
|
12
|
+
.replace(/\[/g, '.')
|
|
13
|
+
.replace(/]/g, '')
|
|
14
|
+
.split('.');
|
|
15
|
+
pathUnits.forEach((level) => {
|
|
16
|
+
if (obj) {
|
|
17
|
+
obj = obj[level];
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
if (obj === undefined) {
|
|
21
|
+
return def;
|
|
22
|
+
}
|
|
23
|
+
return obj;
|
|
24
|
+
}
|
|
25
|
+
static setByPath(obj, path, value) {
|
|
26
|
+
const a = path.split('.');
|
|
27
|
+
let o = obj;
|
|
28
|
+
while (a.length - 1) {
|
|
29
|
+
const n = a.shift();
|
|
30
|
+
if (!(n in o))
|
|
31
|
+
o[n] = {};
|
|
32
|
+
o = o[n];
|
|
33
|
+
}
|
|
34
|
+
o[a[0]] = value;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.ObjectUtil = ObjectUtil;
|
|
38
|
+
ObjectUtil.isObject = isObject_1.isObject;
|
|
39
|
+
ObjectUtil.mergeDeep = mergeDeep_1.mergeDeep;
|
|
40
|
+
ObjectUtil.cloneDeep = cloneDeep_1.cloneDeep;
|
|
41
|
+
ObjectUtil.compareDeep = compareDeep_1.getObjectDiffs;
|
|
42
|
+
ObjectUtil.applyChangesIfEqual = applyChangesIfEqual_1.applyChangesIfEqual;
|
|
43
|
+
ObjectUtil.determineChangesIfEqual = applyChangesIfEqual_1.determineChangesIfEqual;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
export declare class StringUtil {
|
|
2
|
-
static convertToHyphenCase(entityName: string, transformToLowerCase?: boolean): string;
|
|
3
|
-
static parseVariables(variableString: string, data: any, quoteStrings?: boolean): string;
|
|
4
|
-
static convertToCamelCase(str: any): any;
|
|
5
|
-
static convertToTitleCase(str: any): any;
|
|
6
|
-
static isString(value: any): boolean;
|
|
7
|
-
static isArray(value: any): boolean;
|
|
8
|
-
|
|
9
|
-
}
|
|
1
|
+
export declare class StringUtil {
|
|
2
|
+
static convertToHyphenCase(entityName: string, transformToLowerCase?: boolean): string;
|
|
3
|
+
static parseVariables(variableString: string, data: any, quoteStrings?: boolean): string;
|
|
4
|
+
static convertToCamelCase(str: any): any;
|
|
5
|
+
static convertToTitleCase(str: any): any;
|
|
6
|
+
static isString(value: any): boolean;
|
|
7
|
+
static isArray(value: any): boolean;
|
|
8
|
+
}
|
|
@@ -1,65 +1,63 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StringUtil = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
let
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
exports.StringUtil = StringUtil;
|
|
65
|
-
StringUtil.replaceAllWithFunction = replaceAllWithFunction_1.replaceAllWithFunction;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StringUtil = void 0;
|
|
4
|
+
class StringUtil {
|
|
5
|
+
static convertToHyphenCase(entityName, transformToLowerCase = true) {
|
|
6
|
+
const slugName = entityName === null || entityName === void 0 ? void 0 : entityName.split(/(?=[A-Z])/).join('-');
|
|
7
|
+
if (slugName && transformToLowerCase) {
|
|
8
|
+
return slugName.toLowerCase();
|
|
9
|
+
}
|
|
10
|
+
return slugName;
|
|
11
|
+
}
|
|
12
|
+
static parseVariables(variableString, data, quoteStrings = false) {
|
|
13
|
+
const regExp = /\{([^}]+)\}/g;
|
|
14
|
+
const replacedString = variableString.replace(regExp, (match, group) => {
|
|
15
|
+
const variableLevels = group.split('.');
|
|
16
|
+
let replacementValue = data;
|
|
17
|
+
for (let i = 0; i < variableLevels.length; i++) {
|
|
18
|
+
if (replacementValue) {
|
|
19
|
+
replacementValue = replacementValue[variableLevels[i]];
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
replacementValue = undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (quoteStrings && StringUtil.isString(replacementValue)) {
|
|
26
|
+
replacementValue = JSON.stringify(replacementValue);
|
|
27
|
+
}
|
|
28
|
+
if (StringUtil.isArray(replacementValue)) {
|
|
29
|
+
if (quoteStrings) {
|
|
30
|
+
const newArray = [];
|
|
31
|
+
for (const val of replacementValue) {
|
|
32
|
+
newArray.push(JSON.stringify(val));
|
|
33
|
+
}
|
|
34
|
+
replacementValue = newArray;
|
|
35
|
+
}
|
|
36
|
+
replacementValue = '[' + replacementValue + ']';
|
|
37
|
+
}
|
|
38
|
+
if (Object.prototype.toString.call(replacementValue) === '[object Object]') {
|
|
39
|
+
replacementValue = JSON.stringify(replacementValue);
|
|
40
|
+
}
|
|
41
|
+
return replacementValue;
|
|
42
|
+
});
|
|
43
|
+
return replacedString;
|
|
44
|
+
}
|
|
45
|
+
static convertToCamelCase(str) {
|
|
46
|
+
str = str.replace(/-/g, ' ');
|
|
47
|
+
return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
|
|
48
|
+
return index === 0 ? word.toLowerCase() : word.toUpperCase();
|
|
49
|
+
}).replace(/\s+/g, '');
|
|
50
|
+
}
|
|
51
|
+
static convertToTitleCase(str) {
|
|
52
|
+
const camelCase = this.convertToCamelCase(str);
|
|
53
|
+
const withSpaces = camelCase.replace(/([A-Z])/g, " $1");
|
|
54
|
+
return withSpaces.charAt(0).toUpperCase() + withSpaces.slice(1);
|
|
55
|
+
}
|
|
56
|
+
static isString(value) {
|
|
57
|
+
return typeof value === 'string' || value instanceof String;
|
|
58
|
+
}
|
|
59
|
+
static isArray(value) {
|
|
60
|
+
return Array.isArray(value);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.StringUtil = StringUtil;
|
package/package.json
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@contrail/util",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "General javascript utilities",
|
|
5
|
-
"main": "lib/index.js",
|
|
6
|
-
"types": "lib/index.d.ts",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"build": "tsc",
|
|
9
|
-
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
|
|
10
|
-
"lint": "tslint -p tsconfig.json",
|
|
11
|
-
"test:watch": "jest --watch",
|
|
12
|
-
"test": "jest"
|
|
13
|
-
},
|
|
14
|
-
"keywords": [],
|
|
15
|
-
"author": "",
|
|
16
|
-
"license": "ISC",
|
|
17
|
-
"devDependencies": {
|
|
18
|
-
"@types/jest": "^23.3.14",
|
|
19
|
-
"jest": "^29.3.1",
|
|
20
|
-
"prettier": "^1.19.1",
|
|
21
|
-
"ts-jest": "^29.0.3",
|
|
22
|
-
"tslint": "^5.11.0",
|
|
23
|
-
"tslint-config-prettier": "^1.18.0",
|
|
24
|
-
"typescript": "^4.0.0"
|
|
25
|
-
},
|
|
26
|
-
"jest": {
|
|
27
|
-
"moduleFileExtensions": [
|
|
28
|
-
"js",
|
|
29
|
-
"json",
|
|
30
|
-
"ts"
|
|
31
|
-
],
|
|
32
|
-
"rootDir": "src",
|
|
33
|
-
"testRegex": ".spec.ts$",
|
|
34
|
-
"transform": {
|
|
35
|
-
"^.+\\.(t|j)s$": "ts-jest"
|
|
36
|
-
},
|
|
37
|
-
"coverageDirectory": "../coverage",
|
|
38
|
-
"testEnvironment": "node"
|
|
39
|
-
}
|
|
40
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@contrail/util",
|
|
3
|
+
"version": "1.0.34",
|
|
4
|
+
"description": "General javascript utilities",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
|
|
10
|
+
"lint": "tslint -p tsconfig.json",
|
|
11
|
+
"test:watch": "jest --watch",
|
|
12
|
+
"test": "jest"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [],
|
|
15
|
+
"author": "",
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/jest": "^23.3.14",
|
|
19
|
+
"jest": "^29.3.1",
|
|
20
|
+
"prettier": "^1.19.1",
|
|
21
|
+
"ts-jest": "^29.0.3",
|
|
22
|
+
"tslint": "^5.11.0",
|
|
23
|
+
"tslint-config-prettier": "^1.18.0",
|
|
24
|
+
"typescript": "^4.0.0"
|
|
25
|
+
},
|
|
26
|
+
"jest": {
|
|
27
|
+
"moduleFileExtensions": [
|
|
28
|
+
"js",
|
|
29
|
+
"json",
|
|
30
|
+
"ts"
|
|
31
|
+
],
|
|
32
|
+
"rootDir": "src",
|
|
33
|
+
"testRegex": ".spec.ts$",
|
|
34
|
+
"transform": {
|
|
35
|
+
"^.+\\.(t|j)s$": "ts-jest"
|
|
36
|
+
},
|
|
37
|
+
"coverageDirectory": "../coverage",
|
|
38
|
+
"testEnvironment": "node"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function replaceAllWithFunction(string: string, regEx: RegExp, replacerFunction: (matchedString: string) => string): string;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.replaceAllWithFunction = void 0;
|
|
4
|
-
function replaceAllWithFunction(string, regEx, replacerFunction) {
|
|
5
|
-
let match;
|
|
6
|
-
let newString = '';
|
|
7
|
-
let startIndex = 0;
|
|
8
|
-
let hasMatches = false;
|
|
9
|
-
while ((match = regEx.exec(string)) !== null) {
|
|
10
|
-
let matchedString = match[0];
|
|
11
|
-
let index = match.index;
|
|
12
|
-
const newValue = replacerFunction(matchedString);
|
|
13
|
-
const subString = string.substring(startIndex, index);
|
|
14
|
-
newString += subString;
|
|
15
|
-
newString += newValue;
|
|
16
|
-
startIndex = index + matchedString.length;
|
|
17
|
-
hasMatches = true;
|
|
18
|
-
}
|
|
19
|
-
if (!(newString === null || newString === void 0 ? void 0 : newString.length) && !hasMatches) {
|
|
20
|
-
newString = string;
|
|
21
|
-
}
|
|
22
|
-
return newString;
|
|
23
|
-
}
|
|
24
|
-
exports.replaceAllWithFunction = replaceAllWithFunction;
|