topkat-utils 1.1.13 → 1.1.14
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/dist/index.d.ts +36 -0
- package/dist/index.js +58 -0
- package/dist/index.js.map +1 -0
- package/dist/src/array-utils.d.ts +56 -0
- package/dist/src/array-utils.js +160 -0
- package/dist/src/array-utils.js.map +1 -0
- package/dist/src/config.d.ts +44 -0
- package/dist/src/config.js +66 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/date-utils.d.ts +100 -0
- package/dist/src/date-utils.js +407 -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 +135 -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 +12 -0
- package/dist/src/isset.js.map +1 -0
- package/dist/src/logger-utils.d.ts +76 -0
- package/dist/src/logger-utils.js +484 -0
- package/dist/src/logger-utils.js.map +1 -0
- package/dist/src/loop-utils.d.ts +40 -0
- package/dist/src/loop-utils.js +182 -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 +59 -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 +63 -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 +409 -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 +66 -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 +46 -0
- package/dist/src/private/error-handler.js.map +1 -0
- package/dist/src/private/types.d.ts +5 -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 +45 -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 +21 -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 +267 -0
- package/dist/src/string-utils.js.map +1 -0
- package/dist/src/tests-utils.d.ts +21 -0
- package/dist/src/tests-utils.js +80 -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 +146 -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 +157 -0
- package/dist/src/transaction-utils.js.map +1 -0
- package/dist/src/validation-utils.d.ts +80 -0
- package/dist/src/validation-utils.js +249 -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 +88 -0
- package/dist/src/wtf-utils.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ObjectGeneric } from "./private/types";
|
|
2
|
+
export declare function forI<T extends any[] | any>(nbIterations: number, callback: (number: number, previousValue: any, arrayOfPreviousValues: any[]) => T): T[];
|
|
3
|
+
export declare function forIasync<T extends any[] | any>(nbIterations: number, callback: (number: any) => T): Promise<T[]>;
|
|
4
|
+
export declare type RecursiveCallback = (item: any, addr: string, lastElementKey: string | number, parent: ObjectGeneric | any[]) => false | any;
|
|
5
|
+
export declare type RecursiveConfig = {
|
|
6
|
+
disableCircularDependencyRemoval?: boolean;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* @param {any} item the first array or object or whatever you want to recursively browse
|
|
10
|
+
* @param {function} callback the callback you want to apply on items including the main one
|
|
11
|
+
* * this callback has 2 arguments: (item, address) =>
|
|
12
|
+
* * `item` => the actual item
|
|
13
|
+
* * `addr` => the address of the item, not including root (Eg: subItem1.sub2.[3].[2]) array indexes are juste written as numbers
|
|
14
|
+
* * `lastElementKey` => the key of last item. May be a number if last item is an array
|
|
15
|
+
* * `parent` => reference the parent object as this is the only way of reassigning a value for the item. Eg: parent[lastElementKey] = myNewItem
|
|
16
|
+
* * **NOTE** => if a key of an item contains dots, they will be replaced by '%' in `addr`
|
|
17
|
+
* * **NOTE2** => if false is returned by the callback it will stop all other iterations (but not in an array)
|
|
18
|
+
* @param {string} addr$ optional, the base address for the callback function
|
|
19
|
+
* @param lastElementKey technical field
|
|
20
|
+
* NOTE: will remove circular references
|
|
21
|
+
* /!\ check return values
|
|
22
|
+
*/
|
|
23
|
+
export declare function recursiveGenericFunction(item: ObjectGeneric | any[], callback: RecursiveCallback, config?: RecursiveConfig, addr$?: string, lastElementKey?: string | number, parent?: any, techFieldToAvoidCircularDependency?: any[]): Promise<any[] | ObjectGeneric>;
|
|
24
|
+
/**
|
|
25
|
+
* @param {any} item the first array or object or whatever you want to recursively browse
|
|
26
|
+
* @param {function} callback the callback you want to apply on items including the main one
|
|
27
|
+
* * this callback has 2 arguments: (item, address) =>
|
|
28
|
+
* * `item` => the actual item
|
|
29
|
+
* * `addr` => the address of the item, not including root (Eg: subItem1.sub2.[3].[2]) array indexes are juste written as numbers
|
|
30
|
+
* * `lastElementKey` => the key of last item. May be a number if last item is an array
|
|
31
|
+
* * `parent` => reference the parent object as this is the only way of reassigning a value for the item. Eg: parent[lastElementKey] = myNewItem
|
|
32
|
+
* * **NOTE** => if a key of an item contains dots, they will be replaced by '%' in `addr`
|
|
33
|
+
* * **NOTE2** => if false is returned by the callback it will stop all other iterations (but not in an array)
|
|
34
|
+
* * **NOTE3** => to reassign a key use => parent[lastElementKey] = myNewItem
|
|
35
|
+
* @param {string} addr$ optional, the base address for the callback function
|
|
36
|
+
* @param lastElementKey technical field
|
|
37
|
+
* NOTE: will remove circular references
|
|
38
|
+
* /!\ check return values
|
|
39
|
+
*/
|
|
40
|
+
export declare function recursiveGenericFunctionSync(item: ObjectGeneric | any[], callback: RecursiveCallback, config?: RecursiveConfig, addr$?: string, lastElementKey?: string | number, parent?: any, techFieldToAvoidCircularDependency?: any[]): any[] | ObjectGeneric;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.recursiveGenericFunctionSync = exports.recursiveGenericFunction = exports.forIasync = exports.forI = void 0;
|
|
40
|
+
var error_utils_1 = require("./error-utils");
|
|
41
|
+
var is_object_1 = require("./is-object");
|
|
42
|
+
function forI(nbIterations, callback) {
|
|
43
|
+
var results = [];
|
|
44
|
+
for (var i = 0; i < nbIterations; i++) {
|
|
45
|
+
var prevValue = results[results.length - 1];
|
|
46
|
+
results.push(callback(i, prevValue, results));
|
|
47
|
+
}
|
|
48
|
+
return results;
|
|
49
|
+
}
|
|
50
|
+
exports.forI = forI;
|
|
51
|
+
function forIasync(nbIterations, callback) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
53
|
+
var results, i, _a, _b;
|
|
54
|
+
return __generator(this, function (_c) {
|
|
55
|
+
switch (_c.label) {
|
|
56
|
+
case 0:
|
|
57
|
+
results = [];
|
|
58
|
+
i = 0;
|
|
59
|
+
_c.label = 1;
|
|
60
|
+
case 1:
|
|
61
|
+
if (!(i < nbIterations)) return [3 /*break*/, 4];
|
|
62
|
+
_b = (_a = results).push;
|
|
63
|
+
return [4 /*yield*/, callback(i)];
|
|
64
|
+
case 2:
|
|
65
|
+
_b.apply(_a, [_c.sent()]);
|
|
66
|
+
_c.label = 3;
|
|
67
|
+
case 3:
|
|
68
|
+
i++;
|
|
69
|
+
return [3 /*break*/, 1];
|
|
70
|
+
case 4: return [2 /*return*/, results];
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
exports.forIasync = forIasync;
|
|
76
|
+
/**
|
|
77
|
+
* @param {any} item the first array or object or whatever you want to recursively browse
|
|
78
|
+
* @param {function} callback the callback you want to apply on items including the main one
|
|
79
|
+
* * this callback has 2 arguments: (item, address) =>
|
|
80
|
+
* * `item` => the actual item
|
|
81
|
+
* * `addr` => the address of the item, not including root (Eg: subItem1.sub2.[3].[2]) array indexes are juste written as numbers
|
|
82
|
+
* * `lastElementKey` => the key of last item. May be a number if last item is an array
|
|
83
|
+
* * `parent` => reference the parent object as this is the only way of reassigning a value for the item. Eg: parent[lastElementKey] = myNewItem
|
|
84
|
+
* * **NOTE** => if a key of an item contains dots, they will be replaced by '%' in `addr`
|
|
85
|
+
* * **NOTE2** => if false is returned by the callback it will stop all other iterations (but not in an array)
|
|
86
|
+
* @param {string} addr$ optional, the base address for the callback function
|
|
87
|
+
* @param lastElementKey technical field
|
|
88
|
+
* NOTE: will remove circular references
|
|
89
|
+
* /!\ check return values
|
|
90
|
+
*/
|
|
91
|
+
function recursiveGenericFunction(item, callback, config, addr$, lastElementKey, parent, techFieldToAvoidCircularDependency) {
|
|
92
|
+
if (config === void 0) { config = {}; }
|
|
93
|
+
if (addr$ === void 0) { addr$ = ''; }
|
|
94
|
+
if (lastElementKey === void 0) { lastElementKey = ''; }
|
|
95
|
+
if (techFieldToAvoidCircularDependency === void 0) { techFieldToAvoidCircularDependency = []; }
|
|
96
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
97
|
+
var result, _a, addr_1;
|
|
98
|
+
return __generator(this, function (_b) {
|
|
99
|
+
switch (_b.label) {
|
|
100
|
+
case 0:
|
|
101
|
+
(0, error_utils_1.err500IfNotSet)({ callback: callback });
|
|
102
|
+
if (!!techFieldToAvoidCircularDependency.includes(item)) return [3 /*break*/, 7];
|
|
103
|
+
if (!(addr$ === '')) return [3 /*break*/, 1];
|
|
104
|
+
_a = true;
|
|
105
|
+
return [3 /*break*/, 3];
|
|
106
|
+
case 1: return [4 /*yield*/, callback(item, addr$, lastElementKey, parent)];
|
|
107
|
+
case 2:
|
|
108
|
+
_a = _b.sent();
|
|
109
|
+
_b.label = 3;
|
|
110
|
+
case 3:
|
|
111
|
+
result = _a;
|
|
112
|
+
if (!(result !== false)) return [3 /*break*/, 7];
|
|
113
|
+
addr_1 = addr$ ? addr$ + '.' : '';
|
|
114
|
+
if (!Array.isArray(item)) return [3 /*break*/, 5];
|
|
115
|
+
if ((config === null || config === void 0 ? void 0 : config.disableCircularDependencyRemoval) !== true)
|
|
116
|
+
techFieldToAvoidCircularDependency.push(item);
|
|
117
|
+
return [4 /*yield*/, Promise.all(item.map(function (e, i) { return recursiveGenericFunction(e, callback, config, addr_1 + '[' + i + ']', i, item, techFieldToAvoidCircularDependency); }))];
|
|
118
|
+
case 4:
|
|
119
|
+
_b.sent();
|
|
120
|
+
return [3 /*break*/, 7];
|
|
121
|
+
case 5:
|
|
122
|
+
if (!(0, is_object_1.isObject)(item)) return [3 /*break*/, 7];
|
|
123
|
+
if ((config === null || config === void 0 ? void 0 : config.disableCircularDependencyRemoval) !== true)
|
|
124
|
+
techFieldToAvoidCircularDependency.push(item);
|
|
125
|
+
return [4 /*yield*/, Promise.all(Object.entries(item).map(function (_a) {
|
|
126
|
+
var key = _a[0], val = _a[1];
|
|
127
|
+
return recursiveGenericFunction(val, callback, config, addr_1 + key.replace(/\./g, '%'), key, item, techFieldToAvoidCircularDependency);
|
|
128
|
+
}))];
|
|
129
|
+
case 6:
|
|
130
|
+
_b.sent();
|
|
131
|
+
_b.label = 7;
|
|
132
|
+
case 7: return [2 /*return*/, item];
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
exports.recursiveGenericFunction = recursiveGenericFunction;
|
|
138
|
+
/**
|
|
139
|
+
* @param {any} item the first array or object or whatever you want to recursively browse
|
|
140
|
+
* @param {function} callback the callback you want to apply on items including the main one
|
|
141
|
+
* * this callback has 2 arguments: (item, address) =>
|
|
142
|
+
* * `item` => the actual item
|
|
143
|
+
* * `addr` => the address of the item, not including root (Eg: subItem1.sub2.[3].[2]) array indexes are juste written as numbers
|
|
144
|
+
* * `lastElementKey` => the key of last item. May be a number if last item is an array
|
|
145
|
+
* * `parent` => reference the parent object as this is the only way of reassigning a value for the item. Eg: parent[lastElementKey] = myNewItem
|
|
146
|
+
* * **NOTE** => if a key of an item contains dots, they will be replaced by '%' in `addr`
|
|
147
|
+
* * **NOTE2** => if false is returned by the callback it will stop all other iterations (but not in an array)
|
|
148
|
+
* * **NOTE3** => to reassign a key use => parent[lastElementKey] = myNewItem
|
|
149
|
+
* @param {string} addr$ optional, the base address for the callback function
|
|
150
|
+
* @param lastElementKey technical field
|
|
151
|
+
* NOTE: will remove circular references
|
|
152
|
+
* /!\ check return values
|
|
153
|
+
*/
|
|
154
|
+
function recursiveGenericFunctionSync(item, callback, config, addr$, lastElementKey, parent, techFieldToAvoidCircularDependency) {
|
|
155
|
+
if (config === void 0) { config = {}; }
|
|
156
|
+
if (addr$ === void 0) { addr$ = ''; }
|
|
157
|
+
if (lastElementKey === void 0) { lastElementKey = ''; }
|
|
158
|
+
if (techFieldToAvoidCircularDependency === void 0) { techFieldToAvoidCircularDependency = []; }
|
|
159
|
+
(0, error_utils_1.err500IfNotSet)({ callback: callback });
|
|
160
|
+
if (!techFieldToAvoidCircularDependency.includes(item)) {
|
|
161
|
+
var result = addr$ === '' ? true : callback(item, addr$, lastElementKey, parent);
|
|
162
|
+
if (result !== false) {
|
|
163
|
+
var addr_2 = addr$ ? addr$ + '.' : '';
|
|
164
|
+
if (Array.isArray(item)) {
|
|
165
|
+
if ((config === null || config === void 0 ? void 0 : config.disableCircularDependencyRemoval) !== true)
|
|
166
|
+
techFieldToAvoidCircularDependency.push(item); // do not up one level
|
|
167
|
+
item.forEach(function (e, i) { return recursiveGenericFunctionSync(e, callback, config, addr_2 + '[' + i + ']', i, item, techFieldToAvoidCircularDependency); });
|
|
168
|
+
}
|
|
169
|
+
else if ((0, is_object_1.isObject)(item)) {
|
|
170
|
+
if ((config === null || config === void 0 ? void 0 : config.disableCircularDependencyRemoval) !== true)
|
|
171
|
+
techFieldToAvoidCircularDependency.push(item);
|
|
172
|
+
Object.entries(item).forEach(function (_a) {
|
|
173
|
+
var key = _a[0], val = _a[1];
|
|
174
|
+
return recursiveGenericFunctionSync(val, callback, config, addr_2 + key.replace(/\./g, '%'), key, item, techFieldToAvoidCircularDependency);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return item;
|
|
180
|
+
}
|
|
181
|
+
exports.recursiveGenericFunctionSync = recursiveGenericFunctionSync;
|
|
182
|
+
//# sourceMappingURL=loop-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loop-utils.js","sourceRoot":"","sources":["../../src/loop-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,6CAA8C;AAC9C,yCAAsC;AAEtC,SAAgB,IAAI,CAAwB,YAAoB,EAAE,QAA4E;IAC1I,IAAM,OAAO,GAAG,EAA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AAE,gCAAgC,MAAK,IAAI;oBAAE,kCAAkC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;gBACpG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,UAAC,EAAU;wBAAT,GAAG,QAAA,EAAE,GAAG,QAAA;oBAAM,OAAA,4BAA4B,CAAC,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAI,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,kCAAkC,CAAC;gBAAlI,CAAkI,CAAC,CAAA;aACnL;SACJ;KACJ;IACD,OAAO,IAAI,CAAA;AACf,CAAC;AAlBD,oEAkBC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Round with custom number of decimals (default:0) */
|
|
2
|
+
export declare function round(number: number | string, decimals?: number): number;
|
|
3
|
+
/** Round with custom number of decimals (default:2) */
|
|
4
|
+
export declare function round2(number: number | string, decimals?: number): number;
|
|
5
|
+
/** Is number between two numbers (including those numbers) */
|
|
6
|
+
export declare function isBetween(number: number, min: number, max: number, inclusive?: boolean): boolean;
|
|
7
|
+
/** Random number between two values with 0 decimals by default */
|
|
8
|
+
export declare function random(nb1: number, nb2: number, nbOfDecimals?: number): number;
|
|
9
|
+
/** Sum all values of an array, all values MUST be numbers */
|
|
10
|
+
export declare function sumArray(array: number[]): number;
|
|
11
|
+
/** Moyenne / average between array of values
|
|
12
|
+
* @param {Number} round number of decimals to keep. Default:2
|
|
13
|
+
*/
|
|
14
|
+
export declare function moyenne(array: number[], nbOfDecimals?: number): number;
|
|
15
|
+
/** length default 2, shortcut for 1 to 01 */
|
|
16
|
+
export declare function pad(numberOrStr: number | string, length?: number): string;
|
|
17
|
+
/** return the number or the closest number of the range
|
|
18
|
+
* * nb min max => returns
|
|
19
|
+
* * 7 5 10 => 7 // in the range
|
|
20
|
+
* * 2 5 10 => 5 // below the min value
|
|
21
|
+
* * 99 5 10 => 10// above the max value
|
|
22
|
+
*/
|
|
23
|
+
export declare function minMax(nb: number, min: number, max: number): number;
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
var isset_1 = require("./isset");
|
|
8
|
+
/** Round with custom number of decimals (default:0) */
|
|
9
|
+
function round(number, decimals) {
|
|
10
|
+
if (decimals === void 0) { decimals = 0; }
|
|
11
|
+
return Math.round((typeof number === 'number' ? number : parseFloat(number)) * Math.pow(10, decimals)) / Math.pow(10, decimals);
|
|
12
|
+
}
|
|
13
|
+
exports.round = round;
|
|
14
|
+
/** Round with custom number of decimals (default:2) */
|
|
15
|
+
function round2(number, decimals) {
|
|
16
|
+
if (decimals === void 0) { decimals = 2; }
|
|
17
|
+
return round(number, decimals);
|
|
18
|
+
}
|
|
19
|
+
exports.round2 = round2;
|
|
20
|
+
/** Is number between two numbers (including those numbers) */
|
|
21
|
+
function isBetween(number, min, max, inclusive) {
|
|
22
|
+
if (inclusive === void 0) { inclusive = true; }
|
|
23
|
+
return inclusive ? number <= max && number >= min : number < max && number > min;
|
|
24
|
+
}
|
|
25
|
+
exports.isBetween = isBetween;
|
|
26
|
+
/** Random number between two values with 0 decimals by default */
|
|
27
|
+
function random(nb1, nb2, nbOfDecimals) {
|
|
28
|
+
if (nbOfDecimals === void 0) { nbOfDecimals = 0; }
|
|
29
|
+
return round(Math.random() * (nb2 - nb1) + nb1, nbOfDecimals);
|
|
30
|
+
}
|
|
31
|
+
exports.random = random;
|
|
32
|
+
/** Sum all values of an array, all values MUST be numbers */
|
|
33
|
+
function sumArray(array) {
|
|
34
|
+
return array.filter(function (item) { return typeof item === 'number'; }).reduce(function (sum, val) { return (0, isset_1.isset)(val) ? val + sum : sum; }, 0);
|
|
35
|
+
}
|
|
36
|
+
exports.sumArray = sumArray;
|
|
37
|
+
/** Moyenne / average between array of values
|
|
38
|
+
* @param {Number} round number of decimals to keep. Default:2
|
|
39
|
+
*/
|
|
40
|
+
function moyenne(array, nbOfDecimals) {
|
|
41
|
+
if (nbOfDecimals === void 0) { nbOfDecimals = 2; }
|
|
42
|
+
return round(sumArray(array) / array.length, nbOfDecimals);
|
|
43
|
+
}
|
|
44
|
+
exports.moyenne = moyenne;
|
|
45
|
+
/** length default 2, shortcut for 1 to 01 */
|
|
46
|
+
function pad(numberOrStr, length) {
|
|
47
|
+
if (length === void 0) { length = 2; }
|
|
48
|
+
return ('' + numberOrStr).padStart(length, '0');
|
|
49
|
+
}
|
|
50
|
+
exports.pad = pad;
|
|
51
|
+
/** return the number or the closest number of the range
|
|
52
|
+
* * nb min max => returns
|
|
53
|
+
* * 7 5 10 => 7 // in the range
|
|
54
|
+
* * 2 5 10 => 5 // below the min value
|
|
55
|
+
* * 99 5 10 => 10// above the max value
|
|
56
|
+
*/
|
|
57
|
+
function minMax(nb, min, max) { return Math.max(min, Math.min(nb, max)); }
|
|
58
|
+
exports.minMax = minMax;
|
|
59
|
+
//# 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,iCAA+B;AAE/B,uDAAuD;AACvD,SAAgB,KAAK,CAAC,MAAuB,EAAE,QAAY;IAAZ,yBAAA,EAAA,YAAY;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,CAA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A,EAAA,gBAAgB;IACrD,OAAO,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;AAC9D,CAAC;AAFD,0BAEC;AAED,6CAA6C;AAC7C,SAAgB,GAAG,CAAC,WAA4B,EAAE,MAAU;IAAV,uBAAA,EAAA,UAAU;IAAI,OAAO,CAAC,EAAE,GAAG,WAAW,CAAC,CAAC,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAAC,CAAC;AAAjH,kBAAiH;AAEjH;;;;;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,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.mongoPush = exports.mongoFilterMerger = exports.getId = void 0;
|
|
15
|
+
//----------------------------------------
|
|
16
|
+
// MONGO UTILS
|
|
17
|
+
//----------------------------------------
|
|
18
|
+
var validation_utils_1 = require("./validation-utils");
|
|
19
|
+
var isset_1 = require("./isset");
|
|
20
|
+
/** @return undefined if cannot find _id */
|
|
21
|
+
function getId(obj) {
|
|
22
|
+
if (obj === void 0) { obj = {}; }
|
|
23
|
+
if (!obj)
|
|
24
|
+
return; // null case
|
|
25
|
+
if (obj._id)
|
|
26
|
+
return obj._id.toString();
|
|
27
|
+
else if ((0, validation_utils_1.isType)(obj, 'objectId'))
|
|
28
|
+
return obj.toString();
|
|
29
|
+
}
|
|
30
|
+
exports.getId = getId;
|
|
31
|
+
/** Merge filter with correct handling of OR and AND
|
|
32
|
+
* @param {Object} filterA
|
|
33
|
+
* @param {Object} filterB
|
|
34
|
+
* @param {Boolean} assignToFilterA defualt false: if true, it will modify filterA, else it will return merged filters as a new object
|
|
35
|
+
*/
|
|
36
|
+
function mongoFilterMerger(filterA, filterB, assignToFilterA) {
|
|
37
|
+
var _a;
|
|
38
|
+
if (assignToFilterA === void 0) { assignToFilterA = false; }
|
|
39
|
+
if ((0, isset_1.isset)(filterA.$and) && (0, isset_1.isset)(filterB.$and)) {
|
|
40
|
+
(_a = filterA.$and).push.apply(_a, filterB.$and);
|
|
41
|
+
delete filterB.$and;
|
|
42
|
+
}
|
|
43
|
+
if ((0, isset_1.isset)(filterA.$or) && (0, isset_1.isset)(filterB.$or)) {
|
|
44
|
+
if (!(0, isset_1.isset)(filterA.$and))
|
|
45
|
+
filterA.$and = [];
|
|
46
|
+
filterA.$and.push({ $or: filterA.$or }, { $or: filterA.$or });
|
|
47
|
+
delete filterB.$or;
|
|
48
|
+
}
|
|
49
|
+
if (assignToFilterA) {
|
|
50
|
+
Object.assign(filterA, filterB);
|
|
51
|
+
return filterA;
|
|
52
|
+
}
|
|
53
|
+
else
|
|
54
|
+
return __assign(__assign({}, filterA), filterB);
|
|
55
|
+
}
|
|
56
|
+
exports.mongoFilterMerger = mongoFilterMerger;
|
|
57
|
+
function mongoPush(field, value, fields) {
|
|
58
|
+
if (!(0, isset_1.isset)(fields.$push))
|
|
59
|
+
fields.$push = {};
|
|
60
|
+
fields.$push[field] = value;
|
|
61
|
+
}
|
|
62
|
+
exports.mongoPush = mongoPush;
|
|
63
|
+
//# 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,uDAA2C;AAC3C,iCAA+B;AAE/B,2CAA2C;AAC3C,SAAgB,KAAK,CAAC,GAAa;IAAb,oBAAA,EAAA,QAAa;IAC/B,IAAI,CAAC,GAAG;QAAE,OAAM,CAAC,YAAY;IAC7B,IAAI,GAAG,CAAC,GAAG;QAAE,OAAO,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAA;SACjC,IAAI,IAAA,yBAAM,EAAC,GAAG,EAAE,UAAU,CAAC;QAAE,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAA;AAC3D,CAAC;AAJD,sBAIC;AAED;;;;GAIG;AACH,SAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,EAAE,eAAuB;;IAAvB,gCAAA,EAAA,uBAAuB;IACvE,IAAI,IAAA,aAAK,EAAC,OAAO,CAAC,IAAI,CAAC,IAAI,IAAA,aAAK,EAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QAC5C,CAAA,KAAA,OAAO,CAAC,IAAI,CAAA,CAAC,IAAI,WAAI,OAAO,CAAC,IAAI,EAAC;QAClC,OAAO,OAAO,CAAC,IAAI,CAAA;KACtB;IACD,IAAI,IAAA,aAAK,EAAC,OAAO,CAAC,GAAG,CAAC,IAAI,IAAA,aAAK,EAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QAC1C,IAAI,CAAC,IAAA,aAAK,EAAC,OAAO,CAAC,IAAI,CAAC;YAAE,OAAO,CAAC,IAAI,GAAG,EAAE,CAAA;QAC3C,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAA;QAC7D,OAAO,OAAO,CAAC,GAAG,CAAA;KACrB;IACD,IAAI,eAAe,EAAE;QACjB,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QAC/B,OAAO,OAAO,CAAA;KACjB;;QAAM,6BAAY,OAAO,GAAK,OAAO,EAAE;AAC5C,CAAC;AAdD,8CAcC;AAED,SAAgB,SAAS,CAAC,KAAa,EAAE,KAAU,EAAE,MAA4B;IAC7E,IAAI,CAAC,IAAA,aAAK,EAAC,MAAM,CAAC,KAAK,CAAC;QAAE,MAAM,CAAC,KAAK,GAAG,EAAE,CAAA;IAC3C,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,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): {};
|