topkat-utils 1.0.60 → 1.1.2
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/CHANGELOG.md +4 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +56 -0
- package/dist/index.js.map +1 -0
- package/dist/src/array-utils.d.ts +56 -0
- package/dist/src/array-utils.js +138 -0
- package/dist/src/array-utils.js.map +1 -0
- package/dist/src/date-utils.d.ts +100 -0
- package/dist/src/date-utils.js +357 -0
- package/dist/src/date-utils.js.map +1 -0
- package/dist/src/env-utils.d.ts +8 -0
- package/dist/src/env-utils.js +38 -0
- package/dist/src/env-utils.js.map +1 -0
- package/dist/src/error-utils.d.ts +8 -0
- package/dist/src/error-utils.js +99 -0
- package/dist/src/error-utils.js.map +1 -0
- package/dist/src/is-empty.d.ts +1 -0
- package/dist/src/is-empty.js +13 -0
- package/dist/src/is-empty.js.map +1 -0
- package/dist/src/is-object.d.ts +2 -0
- package/dist/src/is-object.js +7 -0
- package/dist/src/is-object.js.map +1 -0
- package/dist/src/isset.d.ts +1 -0
- package/dist/src/isset.js +8 -0
- package/dist/src/isset.js.map +1 -0
- package/dist/src/logger-utils.d.ts +76 -0
- package/dist/src/logger-utils.js +355 -0
- package/dist/src/logger-utils.js.map +1 -0
- package/dist/src/loop-utils.d.ts +37 -0
- package/dist/src/loop-utils.js +105 -0
- package/dist/src/loop-utils.js.map +1 -0
- package/dist/src/math-utils.d.ts +23 -0
- package/dist/src/math-utils.js +43 -0
- package/dist/src/math-utils.js.map +1 -0
- package/dist/src/mongo-utils.d.ts +11 -0
- package/dist/src/mongo-utils.js +49 -0
- package/dist/src/mongo-utils.js.map +1 -0
- package/dist/src/object-utils.d.ts +96 -0
- package/dist/src/object-utils.js +369 -0
- package/dist/src/object-utils.js.map +1 -0
- package/dist/src/private/config.d.ts +44 -0
- package/dist/src/private/config.js +55 -0
- package/dist/src/private/config.js.map +1 -0
- package/dist/src/private/error-handler.d.ts +10 -0
- package/dist/src/private/error-handler.js +18 -0
- package/dist/src/private/error-handler.js.map +1 -0
- package/dist/src/private/types.d.ts +4 -0
- package/dist/src/private/types.js +3 -0
- package/dist/src/private/types.js.map +1 -0
- package/dist/src/regexp-utils.d.ts +12 -0
- package/dist/src/regexp-utils.js +44 -0
- package/dist/src/regexp-utils.js.map +1 -0
- package/dist/src/remove-circular-json-stringify.d.ts +1 -0
- package/dist/src/remove-circular-json-stringify.js +20 -0
- package/dist/src/remove-circular-json-stringify.js.map +1 -0
- package/dist/src/string-utils.d.ts +77 -0
- package/dist/src/string-utils.js +209 -0
- package/dist/src/string-utils.js.map +1 -0
- package/dist/src/tests-utils.js +77 -0
- package/dist/src/tests-utils.js.map +1 -0
- package/dist/src/timer-utils.d.ts +16 -0
- package/dist/src/timer-utils.js +79 -0
- package/dist/src/timer-utils.js.map +1 -0
- package/dist/src/transaction-utils.d.ts +14 -0
- package/dist/src/transaction-utils.js +87 -0
- package/dist/src/transaction-utils.js.map +1 -0
- package/dist/src/validation-utils.d.ts +89 -0
- package/dist/src/validation-utils.js +192 -0
- package/dist/src/validation-utils.js.map +1 -0
- package/dist/src/wtf-utils.d.ts +7 -0
- package/dist/src/wtf-utils.js +83 -0
- package/dist/src/wtf-utils.js.map +1 -0
- package/index.ts +38 -0
- package/package.json +2 -2
- package/src/array-utils.ts +128 -0
- package/src/date-utils.ts +377 -0
- package/src/env-utils.ts +29 -0
- package/src/error-utils.ts +77 -0
- package/src/is-empty.ts +5 -0
- package/src/is-object.ts +3 -0
- package/src/isset.ts +3 -0
- package/src/logger-utils.ts +349 -0
- package/src/loop-utils.ts +101 -0
- package/src/math-utils.ts +38 -0
- package/src/mongo-utils.ts +38 -0
- package/src/object-utils.ts +356 -0
- package/src/private/config.ts +85 -0
- package/src/private/error-handler.ts +21 -0
- package/src/private/types.ts +6 -0
- package/src/regexp-utils.ts +37 -0
- package/src/remove-circular-json-stringify.ts +17 -0
- package/src/string-utils.ts +212 -0
- package/src/tests-utils.ts +70 -0
- package/src/timer-utils.ts +58 -0
- package/src/transaction-utils.ts +63 -0
- package/src/validation-utils.ts +253 -0
- package/src/wtf-utils.ts +88 -0
- package/tsconfig.json +11 -4
- package/utils.d.ts +0 -694
- package/utils.js +0 -2227
- package/utils.js.map +0 -1
- package/utils.ts +0 -2304
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.minMax = exports.pad = exports.moyenne = exports.sumArray = exports.random = exports.isBetween = exports.round2 = exports.round = void 0;
|
|
4
|
+
//----------------------------------------
|
|
5
|
+
// MATH UTILS
|
|
6
|
+
//----------------------------------------
|
|
7
|
+
const isset_1 = require("./isset");
|
|
8
|
+
/** Round with custom number of decimals (default:0) */
|
|
9
|
+
function round(number, decimals = 0) { return Math.round((typeof number === 'number' ? number : parseFloat(number)) * Math.pow(10, decimals)) / Math.pow(10, decimals); }
|
|
10
|
+
exports.round = round;
|
|
11
|
+
/** Round with custom number of decimals (default:2) */
|
|
12
|
+
function round2(number, decimals = 2) { return round(number, decimals); }
|
|
13
|
+
exports.round2 = round2;
|
|
14
|
+
/** Is number between two numbers (including those numbers) */
|
|
15
|
+
function isBetween(number, min, max, inclusive = true) { return inclusive ? number <= max && number >= min : number < max && number > min; }
|
|
16
|
+
exports.isBetween = isBetween;
|
|
17
|
+
/** Random number between two values with 0 decimals by default */
|
|
18
|
+
function random(nb1, nb2, nbOfDecimals = 0) { return round(Math.random() * (nb2 - nb1) + nb1, nbOfDecimals); }
|
|
19
|
+
exports.random = random;
|
|
20
|
+
/** Sum all values of an array, all values MUST be numbers */
|
|
21
|
+
function sumArray(array) {
|
|
22
|
+
return array.filter(item => typeof item === 'number').reduce((sum, val) => (0, isset_1.isset)(val) ? val + sum : sum, 0);
|
|
23
|
+
}
|
|
24
|
+
exports.sumArray = sumArray;
|
|
25
|
+
/** Moyenne / average between array of values
|
|
26
|
+
* @param {Number} round number of decimals to keep. Default:2
|
|
27
|
+
*/
|
|
28
|
+
function moyenne(array, nbOfDecimals = 2) {
|
|
29
|
+
return round(sumArray(array) / array.length, nbOfDecimals);
|
|
30
|
+
}
|
|
31
|
+
exports.moyenne = moyenne;
|
|
32
|
+
/** length default 2, shortcut for 1 to 01 */
|
|
33
|
+
function pad(numberOrStr, length = 2) { return ('' + numberOrStr).padStart(length, '0'); }
|
|
34
|
+
exports.pad = pad;
|
|
35
|
+
/** return the number or the closest number of the range
|
|
36
|
+
* * nb min max => returns
|
|
37
|
+
* * 7 5 10 => 7 // in the range
|
|
38
|
+
* * 2 5 10 => 5 // below the min value
|
|
39
|
+
* * 99 5 10 => 10// above the max value
|
|
40
|
+
*/
|
|
41
|
+
function minMax(nb, min, max) { return Math.max(min, Math.min(nb, max)); }
|
|
42
|
+
exports.minMax = minMax;
|
|
43
|
+
//# sourceMappingURL=math-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math-utils.js","sourceRoot":"","sources":["../../src/math-utils.ts"],"names":[],"mappings":";;;AAAA,0CAA0C;AAC1C,aAAa;AACb,0CAA0C;AAC1C,mCAA+B;AAE/B,uDAAuD;AACvD,SAAgB,KAAK,CAAC,MAAuB,EAAE,QAAQ,GAAG,CAAC,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAA,CAAC,CAAC;AAAhM,sBAAgM;AAChM,uDAAuD;AACvD,SAAgB,MAAM,CAAC,MAAuB,EAAE,QAAQ,GAAG,CAAC,IAAI,OAAO,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA,CAAC,CAAC;AAAhG,wBAA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;;;GAKG;AACH,SAAgB,MAAM,CAAC,EAAU,EAAE,GAAW,EAAE,GAAW,IAAI,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAA,CAAC,CAAC;AAAxG,wBAAwG"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** @return undefined if cannot find _id */
|
|
2
|
+
export declare function getId(obj?: any): string;
|
|
3
|
+
/** Merge filter with correct handling of OR and AND
|
|
4
|
+
* @param {Object} filterA
|
|
5
|
+
* @param {Object} filterB
|
|
6
|
+
* @param {Boolean} assignToFilterA defualt false: if true, it will modify filterA, else it will return merged filters as a new object
|
|
7
|
+
*/
|
|
8
|
+
export declare function mongoFilterMerger(filterA: any, filterB: any, assignToFilterA?: boolean): any;
|
|
9
|
+
export declare function mongoPush(field: string, value: any, fields: {
|
|
10
|
+
[k: string]: any;
|
|
11
|
+
}): void;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mongoPush = exports.mongoFilterMerger = exports.getId = void 0;
|
|
4
|
+
//----------------------------------------
|
|
5
|
+
// MONGO UTILS
|
|
6
|
+
//----------------------------------------
|
|
7
|
+
const validation_utils_1 = require("./validation-utils");
|
|
8
|
+
const isset_1 = require("./isset");
|
|
9
|
+
/** @return undefined if cannot find _id */
|
|
10
|
+
function getId(obj = {}) {
|
|
11
|
+
if (!obj)
|
|
12
|
+
return; // null case
|
|
13
|
+
if (obj._id)
|
|
14
|
+
return obj._id.toString();
|
|
15
|
+
else if ((0, validation_utils_1.isType)(obj, 'objectId'))
|
|
16
|
+
return obj.toString();
|
|
17
|
+
}
|
|
18
|
+
exports.getId = getId;
|
|
19
|
+
/** Merge filter with correct handling of OR and AND
|
|
20
|
+
* @param {Object} filterA
|
|
21
|
+
* @param {Object} filterB
|
|
22
|
+
* @param {Boolean} assignToFilterA defualt false: if true, it will modify filterA, else it will return merged filters as a new object
|
|
23
|
+
*/
|
|
24
|
+
function mongoFilterMerger(filterA, filterB, assignToFilterA = false) {
|
|
25
|
+
if ((0, isset_1.isset)(filterA.$and) && (0, isset_1.isset)(filterB.$and)) {
|
|
26
|
+
filterA.$and.push(...filterB.$and);
|
|
27
|
+
delete filterB.$and;
|
|
28
|
+
}
|
|
29
|
+
if ((0, isset_1.isset)(filterA.$or) && (0, isset_1.isset)(filterB.$or)) {
|
|
30
|
+
if (!(0, isset_1.isset)(filterA.$and))
|
|
31
|
+
filterA.$and = [];
|
|
32
|
+
filterA.$and.push({ $or: filterA.$or }, { $or: filterA.$or });
|
|
33
|
+
delete filterB.$or;
|
|
34
|
+
}
|
|
35
|
+
if (assignToFilterA) {
|
|
36
|
+
Object.assign(filterA, filterB);
|
|
37
|
+
return filterA;
|
|
38
|
+
}
|
|
39
|
+
else
|
|
40
|
+
return Object.assign(Object.assign({}, filterA), filterB);
|
|
41
|
+
}
|
|
42
|
+
exports.mongoFilterMerger = mongoFilterMerger;
|
|
43
|
+
function mongoPush(field, value, fields) {
|
|
44
|
+
if (!(0, isset_1.isset)(fields.$push))
|
|
45
|
+
fields.$push = {};
|
|
46
|
+
fields.$push[field] = value;
|
|
47
|
+
}
|
|
48
|
+
exports.mongoPush = mongoPush;
|
|
49
|
+
//# sourceMappingURL=mongo-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongo-utils.js","sourceRoot":"","sources":["../../src/mongo-utils.ts"],"names":[],"mappings":";;;AAAA,0CAA0C;AAC1C,cAAc;AACd,0CAA0C;AAC1C,yDAA2C;AAC3C,mCAA+B;AAE/B,2CAA2C;AAC3C,SAAgB,KAAK,CAAC,MAAW,EAAE;IAC/B,IAAI,CAAC,GAAG;QAAE,OAAM,CAAC,YAAY;IAC7B,IAAI,GAAG,CAAC,GAAG;QAAE,OAAO,GAAG,CAAC,GAAG,CAAC,QAAQ,EAA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,KAAK,CAAA;AAC/B,CAAC;AAHD,8BAGC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { ObjectGeneric } from "./private/types";
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param {Object} object main object
|
|
5
|
+
* @param {String[]} maskedOrSelectedFields array of fields
|
|
6
|
+
* @param {Boolean} isMask default: true; determine the behavior of the function. If is mask, selected fields will not appear in the resulting object. If it's a select, only selected fields will appear.
|
|
7
|
+
* @param {Boolean} deleteKeysInsteadOfReturningAnewObject default:false; modify the existing object instead of creating a new instance
|
|
8
|
+
*/
|
|
9
|
+
export declare function simpleObjectMaskOrSelect(object: ObjectGeneric, maskedOrSelectedFields: string[], isMask?: boolean, deleteKeysInsteadOfReturningAnewObject?: boolean): ObjectGeneric;
|
|
10
|
+
/**
|
|
11
|
+
* check if **object OR array** has property Safely (avoid cannot read property x of null and such)
|
|
12
|
+
* @param {Object} obj object to test against
|
|
13
|
+
* @param {string} addr `a.b.c.0.1` will test if myObject has props a that has prop b. Work wit arrays as well (like `arr.0`)
|
|
14
|
+
*/
|
|
15
|
+
export declare function has(obj: ObjectGeneric, addr: string): boolean;
|
|
16
|
+
/** Find address in an object "a.b.c" IN { a : { b : {c : 'blah' }}} RETURNS 'blah'
|
|
17
|
+
* @param obj
|
|
18
|
+
* @param addr accept syntax like "obj.subItem.[0].sub2" OR "obj.subItem.0.sub2" OR "obj.subItem[0].sub2"
|
|
19
|
+
* @returns the last item of the chain OR undefined if not found
|
|
20
|
+
*/
|
|
21
|
+
export declare function findByAddress(obj: ObjectGeneric, addr: string): any | undefined;
|
|
22
|
+
/** Will return all objects matching that path. Eg: user.*.myVar */
|
|
23
|
+
export declare function findByAddressAll(obj: any, addr: any, returnAddresses?: true): Array<[string, any]>;
|
|
24
|
+
export declare function findByAddressAll(obj: any, addr: any, returnAddresses?: false): Array<any>;
|
|
25
|
+
/** Enforce writing subItems. Eg: user.name.blah will ensure all are set until the writing of the last item
|
|
26
|
+
* NOTE: doesn't work with arrays
|
|
27
|
+
*/
|
|
28
|
+
export declare function objForceWrite(obj: ObjectGeneric, addr: string, item: any): void;
|
|
29
|
+
/** Enforce writing subItems, only if obj.addr is empty.
|
|
30
|
+
* Eg: user.name.blah will ensure all are set until the writing of the last item
|
|
31
|
+
* if user.name.blah has a value it will not change it.
|
|
32
|
+
* NOTE: doesn't work with arrays
|
|
33
|
+
*/
|
|
34
|
+
export declare function objForceWriteIfNotSet(obj: ObjectGeneric, addr: string, item: any): void;
|
|
35
|
+
/** Merge mixins into class. Use it in the constructor like: mergeMixins(this, {myMixin: true}) */
|
|
36
|
+
export declare function mergeMixins(that: any, ...mixins: any[]): void;
|
|
37
|
+
export declare function cloneObject(o: any): any;
|
|
38
|
+
/** Deep clone. WILL REMOVE circular references */
|
|
39
|
+
export declare function deepClone<T>(obj: T, cache?: any[]): T;
|
|
40
|
+
/**
|
|
41
|
+
* @param {Object} obj the object on which we want to filter the keys
|
|
42
|
+
* @param {function} filterFunc function that returns true if the key match the wanted criteria
|
|
43
|
+
*/
|
|
44
|
+
export declare function filterKeys(obj: object, filter: any): any;
|
|
45
|
+
/**
|
|
46
|
+
* @param {Object} obj the object on which we want to delete a property
|
|
47
|
+
* @param {Array} addr addressArray on which to delete the property
|
|
48
|
+
*/
|
|
49
|
+
export declare function deleteByAddress(obj: object, addr: string[]): void;
|
|
50
|
+
/** Remove all key/values pair if value is undefined */
|
|
51
|
+
export declare function objFilterUndefined(o: any): any;
|
|
52
|
+
/** Lock all 1st level props of an object to read only */
|
|
53
|
+
export declare function readOnly(o: any): any;
|
|
54
|
+
/** Fields of the object can be created BUT NOT reassignated */
|
|
55
|
+
export declare function reassignForbidden(o: any): any;
|
|
56
|
+
/** All fileds and subFields of the object will become readOnly */
|
|
57
|
+
export declare function readOnlyForAll(object: any): any;
|
|
58
|
+
export declare function objFilterUndefinedRecursive(obj: any): any;
|
|
59
|
+
export declare function sortObjKeyAccordingToValue(unorderedObj: any, ascending?: boolean): {};
|
|
60
|
+
/**
|
|
61
|
+
* Make default value if object key do not exist
|
|
62
|
+
* @param {object} obj
|
|
63
|
+
* @param {string} addr
|
|
64
|
+
* @param {any} defaultValue
|
|
65
|
+
* @param {function} callback (obj[addr]) => processValue. Eg: myObjAddr => myObjAddr.push('bikou')
|
|
66
|
+
* @return obj[addr] eventually processed by the callback
|
|
67
|
+
*/
|
|
68
|
+
export declare function ensureObjectProp(obj: object, addr: string, defaultValue: any, callback?: (o: any) => any): any;
|
|
69
|
+
/** object and array merge
|
|
70
|
+
* @warn /!\ Array will be merged and duplicate values will be deleted /!\
|
|
71
|
+
* @return {Object} new object result from merge
|
|
72
|
+
* NOTE: objects in params will NOT be modified*/
|
|
73
|
+
export declare function mergeDeep(...objects: any[]): any;
|
|
74
|
+
/** object and array merge
|
|
75
|
+
* @warn /!\ Array will be replaced by the latest object /!\
|
|
76
|
+
* @return {Object} new object result from merge
|
|
77
|
+
* NOTE: objects in params will NOT be modified */
|
|
78
|
+
export declare function mergeDeepOverrideArrays(...objects: any[]): any;
|
|
79
|
+
/** object and array merge
|
|
80
|
+
* @param {Function} replacerForArrays item[key] = (prevValue, currentVal) => () When 2 values are arrays,
|
|
81
|
+
* @param {Function} replacerForObjects item[key] = (prevValue, currentVal) => () When 2 values are objects,
|
|
82
|
+
* @param {Function} replacerDefault item[key] = (prevValue, currentVal) => () For all other values
|
|
83
|
+
* @param {...Object} objects
|
|
84
|
+
* @return {Object} new object result from merge
|
|
85
|
+
* NOTE: objects in params will NOT be modified
|
|
86
|
+
*/
|
|
87
|
+
export declare function mergeDeepConfigurable(replacerForArrays: (prev: any, curr: any) => any, replacerForObjects: any, replacerDefault?: (prev: any, curr: any) => any, ...objects: any[]): any;
|
|
88
|
+
/** { a: {b:2}} => {'a.b':2} useful for translations
|
|
89
|
+
* NOTE: will remove circular references
|
|
90
|
+
*/
|
|
91
|
+
export declare function flattenObject(data: any, config?: {
|
|
92
|
+
withoutArraySyntax?: boolean;
|
|
93
|
+
withArraySyntaxMinified?: boolean;
|
|
94
|
+
}): {};
|
|
95
|
+
/** {'a.b':2} => { a: {b:2}} */
|
|
96
|
+
export declare function unflattenObject(data: any): {};
|
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unflattenObject = exports.flattenObject = exports.mergeDeepConfigurable = exports.mergeDeepOverrideArrays = exports.mergeDeep = exports.ensureObjectProp = exports.sortObjKeyAccordingToValue = exports.objFilterUndefinedRecursive = exports.readOnlyForAll = exports.reassignForbidden = exports.readOnly = exports.objFilterUndefined = exports.deleteByAddress = exports.filterKeys = exports.deepClone = exports.cloneObject = exports.mergeMixins = exports.objForceWriteIfNotSet = exports.objForceWrite = exports.findByAddressAll = exports.findByAddress = exports.has = exports.simpleObjectMaskOrSelect = void 0;
|
|
4
|
+
const error_utils_1 = require("./error-utils");
|
|
5
|
+
const loop_utils_1 = require("./loop-utils");
|
|
6
|
+
const isset_1 = require("./isset");
|
|
7
|
+
const is_object_1 = require("./is-object");
|
|
8
|
+
const error_handler_1 = require("./private/error-handler");
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @param {Object} object main object
|
|
12
|
+
* @param {String[]} maskedOrSelectedFields array of fields
|
|
13
|
+
* @param {Boolean} isMask default: true; determine the behavior of the function. If is mask, selected fields will not appear in the resulting object. If it's a select, only selected fields will appear.
|
|
14
|
+
* @param {Boolean} deleteKeysInsteadOfReturningAnewObject default:false; modify the existing object instead of creating a new instance
|
|
15
|
+
*/
|
|
16
|
+
function simpleObjectMaskOrSelect(object, maskedOrSelectedFields, isMask = true, deleteKeysInsteadOfReturningAnewObject = false) {
|
|
17
|
+
const allKeys = Object.keys(object);
|
|
18
|
+
const keysToMask = allKeys.filter(keyName => {
|
|
19
|
+
if (isMask)
|
|
20
|
+
return maskedOrSelectedFields.includes(keyName);
|
|
21
|
+
else
|
|
22
|
+
return !maskedOrSelectedFields.includes(keyName);
|
|
23
|
+
});
|
|
24
|
+
if (deleteKeysInsteadOfReturningAnewObject) {
|
|
25
|
+
keysToMask.forEach(keyNameToDelete => delete object[keyNameToDelete]);
|
|
26
|
+
return object;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
return allKeys.reduce((newObject, key) => {
|
|
30
|
+
if (!keysToMask.includes(key))
|
|
31
|
+
newObject[key] = object[key];
|
|
32
|
+
return newObject;
|
|
33
|
+
}, {});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.simpleObjectMaskOrSelect = simpleObjectMaskOrSelect;
|
|
37
|
+
/**
|
|
38
|
+
* check if **object OR array** has property Safely (avoid cannot read property x of null and such)
|
|
39
|
+
* @param {Object} obj object to test against
|
|
40
|
+
* @param {string} addr `a.b.c.0.1` will test if myObject has props a that has prop b. Work wit arrays as well (like `arr.0`)
|
|
41
|
+
*/
|
|
42
|
+
function has(obj, addr) {
|
|
43
|
+
if (!(0, isset_1.isset)(obj) || typeof obj !== 'object')
|
|
44
|
+
return;
|
|
45
|
+
let propsArr = addr.replace(/\.?\[(\d+)\]/g, '.$1').split('.'); // replace a[3] => a.3;
|
|
46
|
+
let objChain = obj;
|
|
47
|
+
return propsArr.every(prop => {
|
|
48
|
+
objChain = objChain[prop];
|
|
49
|
+
return (0, isset_1.isset)(objChain);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
exports.has = has;
|
|
53
|
+
/** Find address in an object "a.b.c" IN { a : { b : {c : 'blah' }}} RETURNS 'blah'
|
|
54
|
+
* @param obj
|
|
55
|
+
* @param addr accept syntax like "obj.subItem.[0].sub2" OR "obj.subItem.0.sub2" OR "obj.subItem[0].sub2"
|
|
56
|
+
* @returns the last item of the chain OR undefined if not found
|
|
57
|
+
*/
|
|
58
|
+
function findByAddress(obj, addr) {
|
|
59
|
+
if (addr === '')
|
|
60
|
+
return obj;
|
|
61
|
+
if (!(0, isset_1.isset)(obj) || typeof obj !== 'object')
|
|
62
|
+
return console.warn('Main object in `findByAddress` function is undefined or has the wrong type');
|
|
63
|
+
const propsArr = addr.replace(/\.?\[(\d+)\]/g, '.$1').split('.'); // replace .[4] AND [4] TO .4
|
|
64
|
+
const objRef = propsArr.reduce((objChain, prop) => {
|
|
65
|
+
if (!(0, isset_1.isset)(objChain) || typeof objChain !== 'object' || !(0, isset_1.isset)(objChain[prop]))
|
|
66
|
+
return;
|
|
67
|
+
else
|
|
68
|
+
return objChain[prop];
|
|
69
|
+
}, obj);
|
|
70
|
+
return objRef;
|
|
71
|
+
}
|
|
72
|
+
exports.findByAddress = findByAddress;
|
|
73
|
+
function findByAddressAll(obj, addr, returnAddresses = false) {
|
|
74
|
+
(0, error_utils_1.err500IfNotSet)({ obj, addr });
|
|
75
|
+
if (addr === '')
|
|
76
|
+
return obj;
|
|
77
|
+
const addrRegexp = new RegExp('^' + addr
|
|
78
|
+
.replace(/\.?\[(\d+)\]/g, '.$1') // replace .[4] AND [4] TO .4
|
|
79
|
+
.replace(/\./g, '\\.')
|
|
80
|
+
.replace(/\.\*/g, '.[^.]+') // replace * by [^. (all but a point)]
|
|
81
|
+
+ '$');
|
|
82
|
+
const matchingItems = [];
|
|
83
|
+
(0, loop_utils_1.recursiveGenericFunctionSync)(obj, (item, address) => {
|
|
84
|
+
if (addrRegexp.test(address))
|
|
85
|
+
matchingItems.push(returnAddresses ? [address, item] : item);
|
|
86
|
+
});
|
|
87
|
+
return matchingItems;
|
|
88
|
+
}
|
|
89
|
+
exports.findByAddressAll = findByAddressAll;
|
|
90
|
+
/** Enforce writing subItems. Eg: user.name.blah will ensure all are set until the writing of the last item
|
|
91
|
+
* NOTE: doesn't work with arrays
|
|
92
|
+
*/
|
|
93
|
+
function objForceWrite(obj, addr, item) {
|
|
94
|
+
const chunks = addr.replace(/\.?\[(\d+)\]/g, '.[$1').split('.');
|
|
95
|
+
let lastItem = obj;
|
|
96
|
+
chunks.forEach((chunkRaw, i) => {
|
|
97
|
+
const chunk = chunkRaw.replace(/^\[/, '');
|
|
98
|
+
if (i === chunks.length - 1)
|
|
99
|
+
lastItem[chunk] = item;
|
|
100
|
+
else if (!(0, isset_1.isset)(lastItem[chunk])) {
|
|
101
|
+
const nextChunk = chunks[i + 1];
|
|
102
|
+
if ((0, isset_1.isset)(nextChunk) && nextChunk.startsWith('['))
|
|
103
|
+
lastItem[chunk] = [];
|
|
104
|
+
else
|
|
105
|
+
lastItem[chunk] = {};
|
|
106
|
+
}
|
|
107
|
+
else if (typeof lastItem[chunk] !== 'object')
|
|
108
|
+
throw new error_handler_1.dataValidationUtilErrorHandler(`itemNotTypeObjectOrArrayInAddrChainForObjForceWrite`, 500, { origin: 'Validator', chunks, actualValueOfItem: lastItem[chunk], actualChunk: chunk });
|
|
109
|
+
lastItem = lastItem[chunk];
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
exports.objForceWrite = objForceWrite;
|
|
113
|
+
/** Enforce writing subItems, only if obj.addr is empty.
|
|
114
|
+
* Eg: user.name.blah will ensure all are set until the writing of the last item
|
|
115
|
+
* if user.name.blah has a value it will not change it.
|
|
116
|
+
* NOTE: doesn't work with arrays
|
|
117
|
+
*/
|
|
118
|
+
function objForceWriteIfNotSet(obj, addr, item) {
|
|
119
|
+
if (!(0, isset_1.isset)(findByAddress(obj, addr)))
|
|
120
|
+
return objForceWrite(obj, addr, item);
|
|
121
|
+
}
|
|
122
|
+
exports.objForceWriteIfNotSet = objForceWriteIfNotSet;
|
|
123
|
+
/** Merge mixins into class. Use it in the constructor like: mergeMixins(this, {myMixin: true}) */
|
|
124
|
+
function mergeMixins(that, ...mixins) {
|
|
125
|
+
mixins.forEach(mixin => {
|
|
126
|
+
for (const method in mixin) {
|
|
127
|
+
that[method] = mixin[method];
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
exports.mergeMixins = mergeMixins;
|
|
132
|
+
function cloneObject(o) {
|
|
133
|
+
return JSON.parse(JSON.stringify(o));
|
|
134
|
+
}
|
|
135
|
+
exports.cloneObject = cloneObject;
|
|
136
|
+
/** Deep clone. WILL REMOVE circular references */
|
|
137
|
+
function deepClone(obj, cache = []) {
|
|
138
|
+
let copy;
|
|
139
|
+
// usefull to not modify 1st level objet by lower levels
|
|
140
|
+
// this is required for the same object to be referenced not in a redundant way
|
|
141
|
+
const newCache = [...cache];
|
|
142
|
+
if (obj instanceof Date)
|
|
143
|
+
return new Date(obj);
|
|
144
|
+
// Handle Array
|
|
145
|
+
if (Array.isArray(obj)) {
|
|
146
|
+
if (newCache.includes(obj))
|
|
147
|
+
return [];
|
|
148
|
+
newCache.push(obj);
|
|
149
|
+
copy = [];
|
|
150
|
+
for (var i = 0, len = obj.length; i < len; i++) {
|
|
151
|
+
copy[i] = deepClone(obj[i], newCache);
|
|
152
|
+
}
|
|
153
|
+
return copy;
|
|
154
|
+
}
|
|
155
|
+
if (typeof obj === 'object' && obj !== null && Object.getPrototypeOf(obj) === Object.prototype) {
|
|
156
|
+
if (newCache.includes(obj))
|
|
157
|
+
return {};
|
|
158
|
+
newCache.push(obj);
|
|
159
|
+
copy = {};
|
|
160
|
+
for (var key in obj) {
|
|
161
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
162
|
+
copy[key] = deepClone(obj[key], newCache);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return copy;
|
|
166
|
+
}
|
|
167
|
+
return obj; // number, string...
|
|
168
|
+
}
|
|
169
|
+
exports.deepClone = deepClone;
|
|
170
|
+
/**
|
|
171
|
+
* @param {Object} obj the object on which we want to filter the keys
|
|
172
|
+
* @param {function} filterFunc function that returns true if the key match the wanted criteria
|
|
173
|
+
*/
|
|
174
|
+
function filterKeys(obj, filter) {
|
|
175
|
+
const clone = cloneObject(obj);
|
|
176
|
+
(0, loop_utils_1.recursiveGenericFunctionSync)(obj, (item, addr, lastElementKey) => {
|
|
177
|
+
if (!filter(lastElementKey))
|
|
178
|
+
deleteByAddress(clone, addr.split('.'));
|
|
179
|
+
});
|
|
180
|
+
return clone;
|
|
181
|
+
}
|
|
182
|
+
exports.filterKeys = filterKeys;
|
|
183
|
+
/**
|
|
184
|
+
* @param {Object} obj the object on which we want to delete a property
|
|
185
|
+
* @param {Array} addr addressArray on which to delete the property
|
|
186
|
+
*/
|
|
187
|
+
function deleteByAddress(obj, addr) {
|
|
188
|
+
let current = obj;
|
|
189
|
+
for (let i = 0; i < addr.length - 2; i++)
|
|
190
|
+
current = current[addr[i]];
|
|
191
|
+
delete current[addr[addr.length - 1]];
|
|
192
|
+
}
|
|
193
|
+
exports.deleteByAddress = deleteByAddress;
|
|
194
|
+
/** Remove all key/values pair if value is undefined */
|
|
195
|
+
function objFilterUndefined(o) {
|
|
196
|
+
Object.keys(o).forEach(k => !(0, isset_1.isset)(o[k]) && delete o[k]);
|
|
197
|
+
return o;
|
|
198
|
+
}
|
|
199
|
+
exports.objFilterUndefined = objFilterUndefined;
|
|
200
|
+
/** Lock all 1st level props of an object to read only */
|
|
201
|
+
function readOnly(o) {
|
|
202
|
+
const throwErr = () => { throw new error_handler_1.dataValidationUtilErrorHandler('Cannot modify object that is read only', 500); };
|
|
203
|
+
return new Proxy(o, {
|
|
204
|
+
set: throwErr,
|
|
205
|
+
defineProperty: throwErr,
|
|
206
|
+
deleteProperty: throwErr,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
exports.readOnly = readOnly;
|
|
210
|
+
/** Fields of the object can be created BUT NOT reassignated */
|
|
211
|
+
function reassignForbidden(o) {
|
|
212
|
+
return new Proxy(o, {
|
|
213
|
+
defineProperty: function (that, key, value) {
|
|
214
|
+
if (key in that)
|
|
215
|
+
throw new error_handler_1.dataValidationUtilErrorHandler(`Cannot reassign the property ${key.toString()} of this object`, 500);
|
|
216
|
+
else {
|
|
217
|
+
that[key] = value;
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
deleteProperty: function (_, key) {
|
|
222
|
+
throw new error_handler_1.dataValidationUtilErrorHandler(`Cannot delete the property ${key.toString()} of this object`, 500);
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
exports.reassignForbidden = reassignForbidden;
|
|
227
|
+
/** All fileds and subFields of the object will become readOnly */
|
|
228
|
+
function readOnlyForAll(object) {
|
|
229
|
+
(0, loop_utils_1.recursiveGenericFunctionSync)(object, (item, _, lastElementKey, parent) => {
|
|
230
|
+
if (typeof item === 'object')
|
|
231
|
+
parent[lastElementKey] = readOnly(item);
|
|
232
|
+
});
|
|
233
|
+
return object;
|
|
234
|
+
}
|
|
235
|
+
exports.readOnlyForAll = readOnlyForAll;
|
|
236
|
+
function objFilterUndefinedRecursive(obj) {
|
|
237
|
+
if (obj) {
|
|
238
|
+
const flattenedObj = flattenObject(obj);
|
|
239
|
+
Object.keys(flattenedObj).forEach(key => {
|
|
240
|
+
if (!(0, isset_1.isset)(flattenedObj[key])) {
|
|
241
|
+
delete flattenedObj[key];
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
return unflattenObject(flattenedObj);
|
|
245
|
+
}
|
|
246
|
+
else
|
|
247
|
+
return obj;
|
|
248
|
+
}
|
|
249
|
+
exports.objFilterUndefinedRecursive = objFilterUndefinedRecursive;
|
|
250
|
+
function sortObjKeyAccordingToValue(unorderedObj, ascending = true) {
|
|
251
|
+
const orderedObj = {};
|
|
252
|
+
const sortingConst = ascending ? 1 : -1;
|
|
253
|
+
Object.keys(unorderedObj)
|
|
254
|
+
.sort((keyA, keyB) => unorderedObj[keyA] < unorderedObj[keyB] ? sortingConst : -sortingConst)
|
|
255
|
+
.forEach(key => { orderedObj[key] = unorderedObj[key]; });
|
|
256
|
+
return orderedObj;
|
|
257
|
+
}
|
|
258
|
+
exports.sortObjKeyAccordingToValue = sortObjKeyAccordingToValue;
|
|
259
|
+
/**
|
|
260
|
+
* Make default value if object key do not exist
|
|
261
|
+
* @param {object} obj
|
|
262
|
+
* @param {string} addr
|
|
263
|
+
* @param {any} defaultValue
|
|
264
|
+
* @param {function} callback (obj[addr]) => processValue. Eg: myObjAddr => myObjAddr.push('bikou')
|
|
265
|
+
* @return obj[addr] eventually processed by the callback
|
|
266
|
+
*/
|
|
267
|
+
function ensureObjectProp(obj, addr, defaultValue, callback = o => o) {
|
|
268
|
+
(0, error_utils_1.err500IfNotSet)({ obj, addr, defaultValue, callback });
|
|
269
|
+
if (!(0, isset_1.isset)(obj[addr]))
|
|
270
|
+
obj[addr] = defaultValue;
|
|
271
|
+
callback(obj[addr]);
|
|
272
|
+
return obj[addr];
|
|
273
|
+
}
|
|
274
|
+
exports.ensureObjectProp = ensureObjectProp;
|
|
275
|
+
/** object and array merge
|
|
276
|
+
* @warn /!\ Array will be merged and duplicate values will be deleted /!\
|
|
277
|
+
* @return {Object} new object result from merge
|
|
278
|
+
* NOTE: objects in params will NOT be modified*/
|
|
279
|
+
function mergeDeep(...objects) {
|
|
280
|
+
return mergeDeepConfigurable((previousVal, currentVal) => [...previousVal, ...currentVal].filter((elm, i, arr) => arr.indexOf(elm) === i), (previousVal, currentVal) => mergeDeep(previousVal, currentVal), undefined, ...objects);
|
|
281
|
+
}
|
|
282
|
+
exports.mergeDeep = mergeDeep;
|
|
283
|
+
/** object and array merge
|
|
284
|
+
* @warn /!\ Array will be replaced by the latest object /!\
|
|
285
|
+
* @return {Object} new object result from merge
|
|
286
|
+
* NOTE: objects in params will NOT be modified */
|
|
287
|
+
function mergeDeepOverrideArrays(...objects) {
|
|
288
|
+
return mergeDeepConfigurable(undefined, (previousVal, currentVal) => mergeDeepOverrideArrays(previousVal, currentVal), undefined, ...objects);
|
|
289
|
+
}
|
|
290
|
+
exports.mergeDeepOverrideArrays = mergeDeepOverrideArrays;
|
|
291
|
+
/** object and array merge
|
|
292
|
+
* @param {Function} replacerForArrays item[key] = (prevValue, currentVal) => () When 2 values are arrays,
|
|
293
|
+
* @param {Function} replacerForObjects item[key] = (prevValue, currentVal) => () When 2 values are objects,
|
|
294
|
+
* @param {Function} replacerDefault item[key] = (prevValue, currentVal) => () For all other values
|
|
295
|
+
* @param {...Object} objects
|
|
296
|
+
* @return {Object} new object result from merge
|
|
297
|
+
* NOTE: objects in params will NOT be modified
|
|
298
|
+
*/
|
|
299
|
+
function mergeDeepConfigurable(replacerForArrays = (prev, curr) => curr, replacerForObjects, replacerDefault = (prev, curr) => curr, ...objects) {
|
|
300
|
+
return objects.reduce((actuallyMerged, obj) => {
|
|
301
|
+
Object.keys(obj).forEach(key => {
|
|
302
|
+
const previousVal = actuallyMerged[key];
|
|
303
|
+
const currentVal = obj[key];
|
|
304
|
+
if (Array.isArray(previousVal) && Array.isArray(currentVal)) {
|
|
305
|
+
actuallyMerged[key] = replacerForArrays(previousVal, currentVal);
|
|
306
|
+
}
|
|
307
|
+
else if ((0, is_object_1.isObject)(previousVal) && (0, is_object_1.isObject)(currentVal)) {
|
|
308
|
+
actuallyMerged[key] = replacerForObjects(previousVal, currentVal);
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
actuallyMerged[key] = replacerDefault(previousVal, currentVal);
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
return actuallyMerged;
|
|
315
|
+
}, {});
|
|
316
|
+
}
|
|
317
|
+
exports.mergeDeepConfigurable = mergeDeepConfigurable;
|
|
318
|
+
/** { a: {b:2}} => {'a.b':2} useful for translations
|
|
319
|
+
* NOTE: will remove circular references
|
|
320
|
+
*/
|
|
321
|
+
function flattenObject(data, config = {}) {
|
|
322
|
+
const { withoutArraySyntax = false, withArraySyntaxMinified = false } = config;
|
|
323
|
+
const result = {};
|
|
324
|
+
const seenObjects = []; // avoidCircular reference to infinite loop
|
|
325
|
+
const recurse = (cur, prop) => {
|
|
326
|
+
if (Array.isArray(cur)) {
|
|
327
|
+
let l = cur.length;
|
|
328
|
+
let i = 0;
|
|
329
|
+
if (withoutArraySyntax)
|
|
330
|
+
recurse(cur[0], prop);
|
|
331
|
+
else {
|
|
332
|
+
for (; i < l; i++)
|
|
333
|
+
recurse(cur[i], prop + (withArraySyntaxMinified ? `.${i}` : `[${i}]`));
|
|
334
|
+
if (l == 0)
|
|
335
|
+
result[prop] = [];
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
else if ((0, is_object_1.isObject)(cur)) { // is object
|
|
339
|
+
try {
|
|
340
|
+
if (seenObjects.includes(cur))
|
|
341
|
+
cur = deepClone(cur); // avoid circular ref but allow duplicate objects
|
|
342
|
+
else
|
|
343
|
+
seenObjects.push(cur);
|
|
344
|
+
const isEmpty = Object.keys(cur).length === 0;
|
|
345
|
+
for (const p in cur)
|
|
346
|
+
recurse(cur[p], (prop ? prop + '.' : '') + p.replace(/\./g, '%')); // allow prop to contain special chars like points);
|
|
347
|
+
if (isEmpty && prop)
|
|
348
|
+
result[prop] = {};
|
|
349
|
+
}
|
|
350
|
+
catch (error) {
|
|
351
|
+
console.warn('Circular reference in flattenObject, impossible to parse');
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
else
|
|
355
|
+
result[prop] = cur;
|
|
356
|
+
};
|
|
357
|
+
recurse(data, '');
|
|
358
|
+
return result;
|
|
359
|
+
}
|
|
360
|
+
exports.flattenObject = flattenObject;
|
|
361
|
+
/** {'a.b':2} => { a: {b:2}} */
|
|
362
|
+
function unflattenObject(data) {
|
|
363
|
+
const newO = {};
|
|
364
|
+
for (const [addr, value] of Object.entries(data))
|
|
365
|
+
objForceWrite(newO, addr, value);
|
|
366
|
+
return newO;
|
|
367
|
+
}
|
|
368
|
+
exports.unflattenObject = unflattenObject;
|
|
369
|
+
//# sourceMappingURL=object-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object-utils.js","sourceRoot":"","sources":["../../src/object-utils.ts"],"names":[],"mappings":";;;AAIA,+CAA8C;AAC9C,6CAA2D;AAC3D,mCAA+B;AAC/B,2CAAsC;AACtC,2DAAwE;AAExE;;;;;;GAMG;AACH,SAAgB,wBAAwB,CAAC,MAAqB,EAAE,sBAAgC,EAAE,MAAM,GAAG,IAAI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Prod: boolean;
|
|
5
|
+
nbOfLogsToKeep: number;
|
|
6
|
+
customTypes: object;
|
|
7
|
+
preprocessLog?: Function;
|
|
8
|
+
terminal: {
|
|
9
|
+
noColor: boolean;
|
|
10
|
+
theme: {
|
|
11
|
+
primary: Color;
|
|
12
|
+
shade1: Color;
|
|
13
|
+
shade2: Color;
|
|
14
|
+
bgColor?: Color;
|
|
15
|
+
paddingX: number;
|
|
16
|
+
paddingY: number;
|
|
17
|
+
fontColor?: Color;
|
|
18
|
+
pageWidth: number;
|
|
19
|
+
debugModeColor: Color;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
/** Allow dynamic changing of config */
|
|
24
|
+
export declare function configFn(): Config;
|
|
25
|
+
/** Register custom config
|
|
26
|
+
* @param {object} customConfig { 'email': email => /.+@.+/.test(email), type2 : myTestFunction() }
|
|
27
|
+
* * env: 'development',
|
|
28
|
+
* * customTypes: {},
|
|
29
|
+
* * terminal: {
|
|
30
|
+
* * noColor: false, // disable colored escape sequences like /mOO35...etc
|
|
31
|
+
* * theme: {
|
|
32
|
+
* * primary: [61, 167, 32], // main color (title font)
|
|
33
|
+
* * shade1: [127, 192, 39], // gradient shade 1
|
|
34
|
+
* * shade2: [194, 218, 47], // gradient shade 2
|
|
35
|
+
* * bgColor: false, // background color
|
|
36
|
+
* * paddingX: 2, // nb spaces added before an outputted str
|
|
37
|
+
* * paddingY: 2, //
|
|
38
|
+
* * fontColor: false, // default font color
|
|
39
|
+
* * pageWidth: 53, // page size in character
|
|
40
|
+
* * debugModeColor: [147, 212, 6], // usually orange
|
|
41
|
+
* * }
|
|
42
|
+
* * },
|
|
43
|
+
*/
|
|
44
|
+
export declare function registerConfig(customConfig: any): void;
|