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,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerConfig = exports.configFn = void 0;
|
|
4
|
+
const isset_1 = require("../isset");
|
|
5
|
+
let config = {
|
|
6
|
+
env: 'development',
|
|
7
|
+
isProd: false,
|
|
8
|
+
nbOfLogsToKeep: 25,
|
|
9
|
+
customTypes: {},
|
|
10
|
+
terminal: {
|
|
11
|
+
noColor: false,
|
|
12
|
+
theme: {
|
|
13
|
+
primary: [0, 149, 250],
|
|
14
|
+
shade1: [0, 90, 250],
|
|
15
|
+
shade2: [0, 208, 245],
|
|
16
|
+
paddingX: 2,
|
|
17
|
+
paddingY: 2,
|
|
18
|
+
pageWidth: 53,
|
|
19
|
+
debugModeColor: [201, 27, 169],
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
/** Allow dynamic changing of config */
|
|
24
|
+
function configFn() { return config; }
|
|
25
|
+
exports.configFn = configFn;
|
|
26
|
+
/** Register custom config
|
|
27
|
+
* @param {object} customConfig { 'email': email => /.+@.+/.test(email), type2 : myTestFunction() }
|
|
28
|
+
* * env: 'development',
|
|
29
|
+
* * customTypes: {},
|
|
30
|
+
* * terminal: {
|
|
31
|
+
* * noColor: false, // disable colored escape sequences like /mOO35...etc
|
|
32
|
+
* * theme: {
|
|
33
|
+
* * primary: [61, 167, 32], // main color (title font)
|
|
34
|
+
* * shade1: [127, 192, 39], // gradient shade 1
|
|
35
|
+
* * shade2: [194, 218, 47], // gradient shade 2
|
|
36
|
+
* * bgColor: false, // background color
|
|
37
|
+
* * paddingX: 2, // nb spaces added before an outputted str
|
|
38
|
+
* * paddingY: 2, //
|
|
39
|
+
* * fontColor: false, // default font color
|
|
40
|
+
* * pageWidth: 53, // page size in character
|
|
41
|
+
* * debugModeColor: [147, 212, 6], // usually orange
|
|
42
|
+
* * }
|
|
43
|
+
* * },
|
|
44
|
+
*/
|
|
45
|
+
function registerConfig(customConfig) {
|
|
46
|
+
if (!(0, isset_1.isset)(customConfig.terminal))
|
|
47
|
+
customConfig.terminal = {};
|
|
48
|
+
const newconfig = Object.assign(Object.assign({}, config), customConfig);
|
|
49
|
+
newconfig.terminal = Object.assign(Object.assign({}, config.terminal), customConfig.terminal);
|
|
50
|
+
newconfig.terminal.theme = Object.assign(Object.assign({}, config.terminal.theme), (customConfig.terminal.theme || {}));
|
|
51
|
+
config = newconfig;
|
|
52
|
+
config.isProd = config.env.includes('prod');
|
|
53
|
+
}
|
|
54
|
+
exports.registerConfig = registerConfig;
|
|
55
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/private/config.ts"],"names":[],"mappings":";;;AACA,oCAAgC;AAwBhC,IAAI,MAAM,GAAW;IACjB,GAAG,EAAE,aAAa;IAClB,MAAM,EAAE,KAAK;IACb,cAAc,EAAE,EAAE;IAClB,WAAW,EAAE,EAAE;IACf,QAAQ,EAAE;QACN,OAAO,EAAE,KAAK;QACd,KAAK,EAAE;YACH,OAAO,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC;YACtB,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,GAAG,CAAC;YACpB,MAAM,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC;YACrB,QAAQ,EAAE,CAAC;YACX,QAAQ,EAAE,CAAC;YACX,SAAS,EAAE,EAAE;YACb,cAAc,EAAE,CAAC,GAAG,EAAE,EAAE,EAAE,GAAG,CAAC;SACjC;KACJ;CACJ,CAAA;AAED,uCAAuC;AACvC,SAAgB,QAAQ,KAAK,OAAO,MAAM,CAAA,CAAC,CAAC;AAA5C,4BAA4C;AAG5C;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,cAAc,CAAC,YAAY;IACvC,IAAI,CAAC,IAAA,aAAK,EAAC,YAAY,CAAC,QAAQ,CAAC;QAAE,YAAY,CAAC,QAAQ,GAAG,EAAE,CAAA;IAC7D,MAAM,SAAS,mCACR,MAAM,GACN,YAAY,CAClB,CAAA;IACD,SAAS,CAAC,QAAQ,mCACX,MAAM,CAAC,QAAQ,GACf,YAAY,CAAC,QAAQ,CAC3B,CAAA;IACD,SAAS,CAAC,QAAQ,CAAC,KAAK,mCACjB,MAAM,CAAC,QAAQ,CAAC,KAAK,GACrB,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,IAAI,EAAE,CAAC,CACzC,CAAA;IACD,MAAM,GAAG,SAAS,CAAA;IAElB,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;AAC/C,CAAC;AAjBD,wCAiBC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dataValidationUtilErrorHandler = void 0;
|
|
4
|
+
class dataValidationUtilErrorHandler extends Error {
|
|
5
|
+
constructor(msg, code, extraInfos) {
|
|
6
|
+
super(msg);
|
|
7
|
+
this.message = msg;
|
|
8
|
+
this.msg = msg;
|
|
9
|
+
this.name = `${code} ${msg}`;
|
|
10
|
+
this.fromDataValidation = true; // will be catched by express error handler
|
|
11
|
+
this.code = code;
|
|
12
|
+
this.extraInfos = extraInfos;
|
|
13
|
+
this.errorDescription = Object.assign({ msg,
|
|
14
|
+
code }, extraInfos);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.dataValidationUtilErrorHandler = dataValidationUtilErrorHandler;
|
|
18
|
+
//# sourceMappingURL=error-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handler.js","sourceRoot":"","sources":["../../../src/private/error-handler.ts"],"names":[],"mappings":";;;AAAA,MAAa,8BAA+B,SAAQ,KAAK;IAMrD,YAAY,GAAG,EAAE,IAAI,EAAE,UAAW;QAC9B,KAAK,CAAC,GAAG,CAAC,CAAA;QACV,IAAI,CAAC,OAAO,GAAG,GAAG,CAAA;QAClB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,GAAG,IAAI,IAAI,GAAG,EAAE,CAAA;QAC5B,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAA,CAAC,2CAA2C;QAC1E,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,gBAAgB,mBACjB,GAAG;YACH,IAAI,IACD,UAAU,CAChB,CAAA;IACL,CAAC;CACJ;AApBD,wEAoBC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/private/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare function escapeRegexp(str: string, config?: {
|
|
2
|
+
parseStarChar?: boolean;
|
|
3
|
+
}): string;
|
|
4
|
+
/** Get first match of the first capturing group of regexp
|
|
5
|
+
* Eg: const basePath = firstMatch(apiFile, /basePath = '(.*?)'/); will get what is inside quotes
|
|
6
|
+
*/
|
|
7
|
+
export declare function firstMatch(str: string, regExp: RegExp): string | undefined;
|
|
8
|
+
/** Get all matches from regexp with g flag
|
|
9
|
+
* Eg: [ [full, match1, m2], [f, m1, m2]... ]
|
|
10
|
+
* NOTE: the G flag will be appended to regexp
|
|
11
|
+
*/
|
|
12
|
+
export declare function allMatches(str: string, reg: RegExp): string[];
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.allMatches = exports.firstMatch = exports.escapeRegexp = void 0;
|
|
4
|
+
//----------------------------------------
|
|
5
|
+
// REGEXP UTILS
|
|
6
|
+
//----------------------------------------
|
|
7
|
+
const logger_utils_1 = require("./logger-utils");
|
|
8
|
+
function escapeRegexp(str, config = {}) {
|
|
9
|
+
const { parseStarChar = false } = config;
|
|
10
|
+
if (parseStarChar)
|
|
11
|
+
return str.replace(/[-[\]{}()+?.,\\^$|#\s]/g, '\\$&').replace(/\*/g, '.*');
|
|
12
|
+
else
|
|
13
|
+
return str.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
|
|
14
|
+
}
|
|
15
|
+
exports.escapeRegexp = escapeRegexp;
|
|
16
|
+
/** Get first match of the first capturing group of regexp
|
|
17
|
+
* Eg: const basePath = firstMatch(apiFile, /basePath = '(.*?)'/); will get what is inside quotes
|
|
18
|
+
*/
|
|
19
|
+
function firstMatch(str, regExp) { return (str.match(regExp) || [])[1]; }
|
|
20
|
+
exports.firstMatch = firstMatch;
|
|
21
|
+
/** Get all matches from regexp with g flag
|
|
22
|
+
* Eg: [ [full, match1, m2], [f, m1, m2]... ]
|
|
23
|
+
* NOTE: the G flag will be appended to regexp
|
|
24
|
+
*/
|
|
25
|
+
function allMatches(str, reg) {
|
|
26
|
+
let i = 0;
|
|
27
|
+
let matches;
|
|
28
|
+
const arr = [];
|
|
29
|
+
if (typeof str !== 'string')
|
|
30
|
+
logger_utils_1.C.error('Not a string provided as first argument for allMatches()');
|
|
31
|
+
else {
|
|
32
|
+
reg = new RegExp(reg, 'g');
|
|
33
|
+
while ((matches = reg.exec(str))) {
|
|
34
|
+
arr.push(matches);
|
|
35
|
+
if (i++ > 99) {
|
|
36
|
+
logger_utils_1.C.error('error', 'Please provide the G flag in regexp for allMatches');
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return arr;
|
|
42
|
+
}
|
|
43
|
+
exports.allMatches = allMatches;
|
|
44
|
+
//# sourceMappingURL=regexp-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regexp-utils.js","sourceRoot":"","sources":["../../src/regexp-utils.ts"],"names":[],"mappings":";;;AAAA,0CAA0C;AAC1C,eAAe;AACf,0CAA0C;AAC1C,iDAAkC;AAElC,SAAgB,YAAY,CAAC,GAAW,EAAE,SAAsC,EAAE;IAC9E,MAAM,EAAE,aAAa,GAAG,KAAK,EAAE,GAAG,MAAM,CAAA;IACxC,IAAI,aAAa;QAAE,OAAO,GAAG,CAAC,OAAO,CAAC,yBAAyB,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;;QACxF,OAAO,GAAG,CAAC,OAAO,CAAC,0BAA0B,EAAE,MAAM,CAAC,CAAA;AAC/D,CAAC;AAJD,oCAIC;AAED;;GAEG;AACH,SAAgB,UAAU,CAAC,GAAW,EAAE,MAAc,IAAwB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA,CAAC,CAAC;AAAnH,gCAAmH;AAEnH;;;GAGG;AACH,SAAgB,UAAU,CAAC,GAAW,EAAE,GAAW;IAC/C,IAAI,CAAC,GAAG,CAAC,CAAA;IACT,IAAI,OAAO,CAAA;IACX,MAAM,GAAG,GAAG,EAAE,CAAA;IACd,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,gBAAC,CAAC,KAAK,CAAC,0DAA0D,CAAC,CAAA;SAC3F;QACD,GAAG,GAAG,IAAI,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;QAC1B,OAAO,CAAC,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE;YAC9B,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;YACjB,IAAI,CAAC,EAAE,GAAG,EAAE,EAAE;gBACV,gBAAC,CAAC,KAAK,CAAC,OAAO,EAAE,oDAAoD,CAAC,CAAA;gBACtE,MAAK;aACR;SACJ;KACJ;IACD,OAAO,GAAG,CAAA;AACd,CAAC;AAhBD,gCAgBC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function removeCircularJSONstringify(object: any, indent?: number): string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeCircularJSONstringify = void 0;
|
|
4
|
+
function removeCircularJSONstringify(object, indent = 2) {
|
|
5
|
+
const getCircularReplacer = () => {
|
|
6
|
+
const seen = new WeakSet();
|
|
7
|
+
return (key, value) => {
|
|
8
|
+
if (typeof value === 'object' && value !== null) {
|
|
9
|
+
if (seen.has(value)) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
seen.add(value);
|
|
13
|
+
}
|
|
14
|
+
return value;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
return JSON.stringify(object, getCircularReplacer(), indent);
|
|
18
|
+
}
|
|
19
|
+
exports.removeCircularJSONstringify = removeCircularJSONstringify;
|
|
20
|
+
//# sourceMappingURL=remove-circular-json-stringify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove-circular-json-stringify.js","sourceRoot":"","sources":["../../src/remove-circular-json-stringify.ts"],"names":[],"mappings":";;;AACA,SAAgB,2BAA2B,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC;IAC1D,MAAM,mBAAmB,GAAG,GAAG,EAAE;QAC7B,MAAM,IAAI,GAAG,IAAI,OAAO,EAAE,CAAA;QAC1B,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;YAClB,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE;gBAC7C,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;oBACjB,OAAM;iBACT;gBACD,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;aAClB;YACD,OAAO,KAAK,CAAA;QAChB,CAAC,CAAA;IACL,CAAC,CAAA;IAED,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,mBAAmB,EAAE,EAAE,MAAM,CAAC,CAAA;AAChE,CAAC;AAfD,kEAeC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { ObjectGeneric } from "./private/types";
|
|
2
|
+
/**Eg: camelCase */
|
|
3
|
+
export declare function camelCase(...wordBits: any[]): string;
|
|
4
|
+
/**Eg: snake_case
|
|
5
|
+
* trimmed but not lowerCased
|
|
6
|
+
*/
|
|
7
|
+
export declare function snakeCase(...wordBits: any[]): string;
|
|
8
|
+
/**Eg: kebab-case
|
|
9
|
+
* trimmed AND lowerCased
|
|
10
|
+
* undefined, null... => ''
|
|
11
|
+
*/
|
|
12
|
+
export declare function kebabCase(...wordBits: any[]): string;
|
|
13
|
+
/**Eg: PascalCase undefined, null... => '' */
|
|
14
|
+
export declare function pascalCase(...wordBits: any[]): string;
|
|
15
|
+
/**Eg: Titlecase undefined, null... => '' */
|
|
16
|
+
export declare function titleCase(...wordBits: any[]): string;
|
|
17
|
+
/**Eg: UPPERCASE undefined, null... => '' */
|
|
18
|
+
export declare function upperCase(...wordBits: any[]): string;
|
|
19
|
+
/**Eg: lowercase undefined, null... => '' */
|
|
20
|
+
export declare function lowerCase(...wordBits: any[]): string;
|
|
21
|
+
export declare function capitalize1st(str?: string): string;
|
|
22
|
+
export declare function camelCaseToWords(str: any): any;
|
|
23
|
+
/** GIVEN A STRING '{ blah;2}, ['nested,(what,ever)']' AND A SEPARATOR ",""
|
|
24
|
+
* This will return the content separated by first level of separators
|
|
25
|
+
* @return ["{ blah;2}", "['nested,(what,ever)']"]
|
|
26
|
+
*/
|
|
27
|
+
export declare function getValuesBetweenSeparator(str: string, separator: string, removeTrailingSpaces?: boolean): any;
|
|
28
|
+
/** GIVEN A STRING "a: [ 'str', /[^]]/, '[aa]]]str', () => [ nestedArray ] ], b: ['arr']"
|
|
29
|
+
* @return matching: [ "'str', /[^]]/, '[aa]]]str', () => [ nestedArray ]", "'arr'" ], between: [ "a:", ", b: " ]
|
|
30
|
+
* @param str base string
|
|
31
|
+
* @param openingOrSeparator opening character OR separator if closing not set
|
|
32
|
+
* @param closing
|
|
33
|
+
* @param ignoreBetweenOpen default ['\'', '`', '"', '/'], when reaching an opening char, it will ignore all until it find the corresponding closing char
|
|
34
|
+
* @param ignoreBetweenClose default ['\'', '`', '"', '/'] list of corresponding closing chars
|
|
35
|
+
*/
|
|
36
|
+
export declare function getValuesBetweenStrings(str: string, openingOrSeparator: any, closing: any, ignoreBetweenOpen?: string[], ignoreBetweenClose?: string[], removeTrailingSpaces?: boolean): {
|
|
37
|
+
inner: any;
|
|
38
|
+
outer: any;
|
|
39
|
+
};
|
|
40
|
+
/** Remove accentued character from string and eventually special chars and numbers
|
|
41
|
+
* @param {String} str input string
|
|
42
|
+
* @param {Object} config { removeSpecialChars: false, removeNumbers: false, removeSpaces: false }
|
|
43
|
+
* @returns String with all accentued char replaced by their non accentued version + config formattting
|
|
44
|
+
*/
|
|
45
|
+
export declare function convertAccentedCharacters(str: any, config?: {
|
|
46
|
+
removeNumbers?: boolean;
|
|
47
|
+
removeSpecialChars?: boolean;
|
|
48
|
+
removeSpaces?: boolean;
|
|
49
|
+
}): any;
|
|
50
|
+
/** minLength 8 if unique
|
|
51
|
+
* @param {Number} length default: 20
|
|
52
|
+
* @param {Boolean} unique default: true. Generate a real unique token base on the date. min length will be min 8 in this case
|
|
53
|
+
* @param {string} mode one of ['alphanumeric', 'hexadecimal']
|
|
54
|
+
* NOTE: to generate a mongoDB Random Id, use the params: 24, true, 'hexadecimal'
|
|
55
|
+
*/
|
|
56
|
+
export declare function generateToken(length?: number, unique?: boolean, mode?: 'alphanumeric' | 'hexadecimal'): any;
|
|
57
|
+
export declare function generateObjectId(): any;
|
|
58
|
+
/** Useful to join differents bits of url with normalizing slashes
|
|
59
|
+
* * urlPathJoin('https://', 'www.kikou.lol/', '/user', '//2//') => https://www.kikou.lol/user/2/
|
|
60
|
+
* * urlPathJoin('http:/', 'kikou.lol') => https://www.kikou.lol
|
|
61
|
+
*/
|
|
62
|
+
export declare function urlPathJoin(...bits: string[]): string;
|
|
63
|
+
export declare type MiniTemplaterOptions = {
|
|
64
|
+
valueWhenNotSet?: string;
|
|
65
|
+
regexp?: RegExp;
|
|
66
|
+
valueWhenContentUndefined?: string;
|
|
67
|
+
};
|
|
68
|
+
/** Replace variables in a string like: `Hello {{userName}}!`
|
|
69
|
+
* @param {String} content
|
|
70
|
+
* @param {Object} varz object with key => value === toReplace => replacer
|
|
71
|
+
* @param {Object} options
|
|
72
|
+
* * valueWhenNotSet => replacer for undefined values. Default: ''
|
|
73
|
+
* * regexp => must be 'g' and first capturing group matching the value to replace. Default: /{{\s*([^}]*)\s*}}/g
|
|
74
|
+
*/
|
|
75
|
+
export declare function miniTemplater(content: string, varz: ObjectGeneric, options?: MiniTemplaterOptions): string;
|
|
76
|
+
/** Clean output for outside world. All undefined / null / NaN / Infinity values are changed to '-' */
|
|
77
|
+
export declare function cln(val: any, replacerInCaseItIsUndefinNaN?: string): any;
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cln = exports.miniTemplater = exports.urlPathJoin = exports.generateObjectId = exports.generateToken = exports.convertAccentedCharacters = exports.getValuesBetweenStrings = exports.getValuesBetweenSeparator = exports.camelCaseToWords = exports.capitalize1st = exports.lowerCase = exports.upperCase = exports.titleCase = exports.pascalCase = exports.kebabCase = exports.snakeCase = exports.camelCase = void 0;
|
|
4
|
+
//----------------------------------------
|
|
5
|
+
// STRING UTILS
|
|
6
|
+
//----------------------------------------
|
|
7
|
+
const error_utils_1 = require("./error-utils");
|
|
8
|
+
const isset_1 = require("./isset");
|
|
9
|
+
/**Eg: camelCase */
|
|
10
|
+
function camelCase(...wordBits) {
|
|
11
|
+
return wordBits.filter(e => e).map((w, i) => i === 0 ? w : capitalize1st(w)).join('');
|
|
12
|
+
}
|
|
13
|
+
exports.camelCase = camelCase;
|
|
14
|
+
/**Eg: snake_case
|
|
15
|
+
* trimmed but not lowerCased
|
|
16
|
+
*/
|
|
17
|
+
function snakeCase(...wordBits) {
|
|
18
|
+
return wordBits.filter(e => e).map(w => w.trim()).join('_');
|
|
19
|
+
}
|
|
20
|
+
exports.snakeCase = snakeCase;
|
|
21
|
+
/**Eg: kebab-case
|
|
22
|
+
* trimmed AND lowerCased
|
|
23
|
+
* undefined, null... => ''
|
|
24
|
+
*/
|
|
25
|
+
function kebabCase(...wordBits) {
|
|
26
|
+
return wordBits.filter(e => e).map(w => w.trim().toLowerCase()).join('-');
|
|
27
|
+
}
|
|
28
|
+
exports.kebabCase = kebabCase;
|
|
29
|
+
/**Eg: PascalCase undefined, null... => '' */
|
|
30
|
+
function pascalCase(...wordBits) {
|
|
31
|
+
return wordBits.filter(e => e).map((w, i) => capitalize1st(w)).join('');
|
|
32
|
+
}
|
|
33
|
+
exports.pascalCase = pascalCase;
|
|
34
|
+
/**Eg: Titlecase undefined, null... => '' */
|
|
35
|
+
function titleCase(...wordBits) {
|
|
36
|
+
return capitalize1st(wordBits.filter(e => e).map(w => w.trim()).join(''));
|
|
37
|
+
}
|
|
38
|
+
exports.titleCase = titleCase;
|
|
39
|
+
/**Eg: UPPERCASE undefined, null... => '' */
|
|
40
|
+
function upperCase(...wordBits) {
|
|
41
|
+
return wordBits.filter(e => e).map(w => w.trim().toUpperCase()).join('');
|
|
42
|
+
}
|
|
43
|
+
exports.upperCase = upperCase;
|
|
44
|
+
/**Eg: lowercase undefined, null... => '' */
|
|
45
|
+
function lowerCase(...wordBits) {
|
|
46
|
+
return wordBits.filter(e => e).map(w => w.trim().toLowerCase()).join('');
|
|
47
|
+
}
|
|
48
|
+
exports.lowerCase = lowerCase;
|
|
49
|
+
function capitalize1st(str = '') { return str[0].toUpperCase() + str.slice(1); }
|
|
50
|
+
exports.capitalize1st = capitalize1st;
|
|
51
|
+
function camelCaseToWords(str) {
|
|
52
|
+
return str ? str.trim().replace(/([A-Z])/g, '-$1').toLowerCase().split('-') : [];
|
|
53
|
+
}
|
|
54
|
+
exports.camelCaseToWords = camelCaseToWords;
|
|
55
|
+
/** GIVEN A STRING '{ blah;2}, ['nested,(what,ever)']' AND A SEPARATOR ",""
|
|
56
|
+
* This will return the content separated by first level of separators
|
|
57
|
+
* @return ["{ blah;2}", "['nested,(what,ever)']"]
|
|
58
|
+
*/
|
|
59
|
+
function getValuesBetweenSeparator(str, separator, removeTrailingSpaces = true) {
|
|
60
|
+
(0, error_utils_1.err500IfEmptyOrNotSet)({ separator, str });
|
|
61
|
+
const { outer } = getValuesBetweenStrings(str, separator, undefined, undefined, undefined, removeTrailingSpaces);
|
|
62
|
+
return outer;
|
|
63
|
+
}
|
|
64
|
+
exports.getValuesBetweenSeparator = getValuesBetweenSeparator;
|
|
65
|
+
/** GIVEN A STRING "a: [ 'str', /[^]]/, '[aa]]]str', () => [ nestedArray ] ], b: ['arr']"
|
|
66
|
+
* @return matching: [ "'str', /[^]]/, '[aa]]]str', () => [ nestedArray ]", "'arr'" ], between: [ "a:", ", b: " ]
|
|
67
|
+
* @param str base string
|
|
68
|
+
* @param openingOrSeparator opening character OR separator if closing not set
|
|
69
|
+
* @param closing
|
|
70
|
+
* @param ignoreBetweenOpen default ['\'', '`', '"', '/'], when reaching an opening char, it will ignore all until it find the corresponding closing char
|
|
71
|
+
* @param ignoreBetweenClose default ['\'', '`', '"', '/'] list of corresponding closing chars
|
|
72
|
+
*/
|
|
73
|
+
function getValuesBetweenStrings(str, openingOrSeparator, closing, ignoreBetweenOpen = ['\'', '`', '"', '/'], ignoreBetweenClose = ['\'', '`', '"', '/'], removeTrailingSpaces = true) {
|
|
74
|
+
(0, error_utils_1.err500IfEmptyOrNotSet)({ openingOrSeparator, str });
|
|
75
|
+
str = str.replace(/<</g, '§§"').replace(/>>/g, '"§§');
|
|
76
|
+
const arrayValues = [];
|
|
77
|
+
const betweenArray = [];
|
|
78
|
+
let level = 0;
|
|
79
|
+
let ignoreUntil = false;
|
|
80
|
+
let actualValue = '';
|
|
81
|
+
let precedingChar = '';
|
|
82
|
+
let separatorMode = false;
|
|
83
|
+
if (!closing)
|
|
84
|
+
separatorMode = true;
|
|
85
|
+
const separator = separatorMode ? openingOrSeparator : false;
|
|
86
|
+
const openingChars = separatorMode ? ['(', '{', '['] : [openingOrSeparator];
|
|
87
|
+
const closingChars = separatorMode ? [')', '}', ']'] : [closing];
|
|
88
|
+
const pushActualValue = () => {
|
|
89
|
+
if (level === 0)
|
|
90
|
+
betweenArray.push(removeTrailingSpaces ? actualValue.replace(/(?:^\s+|\s+$)/g, '') : actualValue);
|
|
91
|
+
else
|
|
92
|
+
arrayValues.push(removeTrailingSpaces ? actualValue.replace(/(?:^\s+|\s+$)/g, '') : actualValue);
|
|
93
|
+
actualValue = '';
|
|
94
|
+
};
|
|
95
|
+
str.split('').forEach(char => {
|
|
96
|
+
// handle unwanted nested structure like characters in a strings that may be a unmatched closing / opening character
|
|
97
|
+
// Eg: {'azer}aze'}
|
|
98
|
+
if (ignoreUntil && char === ignoreUntil && precedingChar !== '\\')
|
|
99
|
+
ignoreUntil = false;
|
|
100
|
+
else if (ignoreUntil && char !== ignoreUntil)
|
|
101
|
+
true;
|
|
102
|
+
else if (ignoreBetweenOpen.includes(char)) {
|
|
103
|
+
const indexChar = ignoreBetweenOpen.findIndex(char2 => char2 === char);
|
|
104
|
+
ignoreUntil = ignoreBetweenClose[indexChar];
|
|
105
|
+
}
|
|
106
|
+
else if (openingChars.includes(char)) {
|
|
107
|
+
// handle nested structures
|
|
108
|
+
if (!separatorMode && level === 0)
|
|
109
|
+
pushActualValue();
|
|
110
|
+
level++;
|
|
111
|
+
if (!separatorMode)
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
else if (closingChars.includes(char)) {
|
|
115
|
+
// handle nested structures
|
|
116
|
+
if (!separatorMode && level === 1)
|
|
117
|
+
pushActualValue();
|
|
118
|
+
level--;
|
|
119
|
+
}
|
|
120
|
+
else if (separatorMode && level === 0 && char === separator) {
|
|
121
|
+
// SEPARATOR MODE
|
|
122
|
+
pushActualValue();
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
actualValue += char;
|
|
126
|
+
precedingChar = char;
|
|
127
|
+
});
|
|
128
|
+
pushActualValue();
|
|
129
|
+
const replaceValz = arr => arr.map(v => v.replace(/§§"/g, '<<').replace(/"§§/g, '>>')).filter(v => v);
|
|
130
|
+
return { inner: replaceValz(arrayValues), outer: replaceValz(betweenArray) };
|
|
131
|
+
}
|
|
132
|
+
exports.getValuesBetweenStrings = getValuesBetweenStrings;
|
|
133
|
+
/** Remove accentued character from string and eventually special chars and numbers
|
|
134
|
+
* @param {String} str input string
|
|
135
|
+
* @param {Object} config { removeSpecialChars: false, removeNumbers: false, removeSpaces: false }
|
|
136
|
+
* @returns String with all accentued char replaced by their non accentued version + config formattting
|
|
137
|
+
*/
|
|
138
|
+
function convertAccentedCharacters(str, config = {}) {
|
|
139
|
+
let output = str
|
|
140
|
+
.replace(/[àáâãäå]/g, 'a')
|
|
141
|
+
.replace(/ç/g, 'c')
|
|
142
|
+
.replace(/[èéêë]/g, 'e')
|
|
143
|
+
.replace(/[ìíîï]/g, 'i')
|
|
144
|
+
.replace(/[ôö]/g, 'o')
|
|
145
|
+
.replace(/[ùúû]/g, 'u')
|
|
146
|
+
.replace(/(^\s*|\s*$)/g, '');
|
|
147
|
+
if (config.removeNumbers === true)
|
|
148
|
+
output = output.replace(/\d+/g, '');
|
|
149
|
+
if (config.removeSpecialChars === true)
|
|
150
|
+
output = output.replace(/[^A-Za-z0-9 ]/g, '');
|
|
151
|
+
if (config.removeSpaces === true)
|
|
152
|
+
output = output.replace(/\s+/g, '');
|
|
153
|
+
return output;
|
|
154
|
+
}
|
|
155
|
+
exports.convertAccentedCharacters = convertAccentedCharacters;
|
|
156
|
+
let generatedTokens = []; // cache to avoid collision
|
|
157
|
+
let lastTs = new Date().getTime();
|
|
158
|
+
/** minLength 8 if unique
|
|
159
|
+
* @param {Number} length default: 20
|
|
160
|
+
* @param {Boolean} unique default: true. Generate a real unique token base on the date. min length will be min 8 in this case
|
|
161
|
+
* @param {string} mode one of ['alphanumeric', 'hexadecimal']
|
|
162
|
+
* NOTE: to generate a mongoDB Random Id, use the params: 24, true, 'hexadecimal'
|
|
163
|
+
*/
|
|
164
|
+
function generateToken(length = 20, unique = true, mode = 'alphanumeric') {
|
|
165
|
+
let charConvNumeric = mode === 'alphanumeric' ? 36 : 16;
|
|
166
|
+
if (unique && length < 8)
|
|
167
|
+
length = 8;
|
|
168
|
+
let token;
|
|
169
|
+
let tokenTs;
|
|
170
|
+
do {
|
|
171
|
+
tokenTs = (new Date()).getTime();
|
|
172
|
+
token = unique ? tokenTs.toString(charConvNumeric) : '';
|
|
173
|
+
while (token.length < length)
|
|
174
|
+
token += Math.random().toString(charConvNumeric).substr(2, 1); // char alphaNumeric aléatoire
|
|
175
|
+
} while (generatedTokens.includes(token));
|
|
176
|
+
if (lastTs < tokenTs)
|
|
177
|
+
generatedTokens = []; // reset generated token on new timestamp because cannot collide
|
|
178
|
+
generatedTokens.push(token);
|
|
179
|
+
return token;
|
|
180
|
+
}
|
|
181
|
+
exports.generateToken = generateToken;
|
|
182
|
+
function generateObjectId() {
|
|
183
|
+
return generateToken(24, true, 'hexadecimal');
|
|
184
|
+
}
|
|
185
|
+
exports.generateObjectId = generateObjectId;
|
|
186
|
+
/** Useful to join differents bits of url with normalizing slashes
|
|
187
|
+
* * urlPathJoin('https://', 'www.kikou.lol/', '/user', '//2//') => https://www.kikou.lol/user/2/
|
|
188
|
+
* * urlPathJoin('http:/', 'kikou.lol') => https://www.kikou.lol
|
|
189
|
+
*/
|
|
190
|
+
function urlPathJoin(...bits) {
|
|
191
|
+
return bits.join('/').replace(/\/+/g, '/').replace(/(https?:)\/\/?/, '$1//');
|
|
192
|
+
}
|
|
193
|
+
exports.urlPathJoin = urlPathJoin;
|
|
194
|
+
/** Replace variables in a string like: `Hello {{userName}}!`
|
|
195
|
+
* @param {String} content
|
|
196
|
+
* @param {Object} varz object with key => value === toReplace => replacer
|
|
197
|
+
* @param {Object} options
|
|
198
|
+
* * valueWhenNotSet => replacer for undefined values. Default: ''
|
|
199
|
+
* * regexp => must be 'g' and first capturing group matching the value to replace. Default: /{{\s*([^}]*)\s*}}/g
|
|
200
|
+
*/
|
|
201
|
+
function miniTemplater(content, varz, options = {}) {
|
|
202
|
+
options = Object.assign({ valueWhenNotSet: '', regexp: /{{\s*([^}]*)\s*}}/g, valueWhenContentUndefined: '' }, options);
|
|
203
|
+
return (0, isset_1.isset)(content) ? content.replace(options.regexp, (m, $1) => (0, isset_1.isset)(varz[$1]) ? varz[$1] : options.valueWhenNotSet) : options.valueWhenContentUndefined;
|
|
204
|
+
}
|
|
205
|
+
exports.miniTemplater = miniTemplater;
|
|
206
|
+
/** Clean output for outside world. All undefined / null / NaN / Infinity values are changed to '-' */
|
|
207
|
+
function cln(val, replacerInCaseItIsUndefinNaN = '-') { return ['undefined', undefined, 'indéfini', 'NaN', NaN, Infinity, null].includes(val) ? replacerInCaseItIsUndefinNaN : val; }
|
|
208
|
+
exports.cln = cln;
|
|
209
|
+
//# sourceMappingURL=string-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-utils.js","sourceRoot":"","sources":["../../src/string-utils.ts"],"names":[],"mappings":";;;AAAA,0CAA0C;AAC1C,eAAe;AACf,0CAA0C;AAC1C,+CAAqD;AAErD,mCAA+B;AAE/B,mBAAmB;AACnB,SAAgB,SAAS,CAAC,GAAG,QAAQ;IACjC,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAA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.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assert = exports.restTestMini = void 0;
|
|
4
|
+
//----------------------------------------
|
|
5
|
+
// TESTS UTILS
|
|
6
|
+
//----------------------------------------
|
|
7
|
+
const logger_utils_1 = require("./logger-utils");
|
|
8
|
+
const isset_1 = require("./isset");
|
|
9
|
+
const validation_utils_1 = require("./validation-utils");
|
|
10
|
+
const is_object_1 = require("./is-object");
|
|
11
|
+
exports.restTestMini = {
|
|
12
|
+
throwOnErr: false,
|
|
13
|
+
reset(throwOnErr = false) {
|
|
14
|
+
exports.restTestMini.nbSuccess = 0;
|
|
15
|
+
exports.restTestMini.nbError = 0;
|
|
16
|
+
exports.restTestMini.lastErrors = [];
|
|
17
|
+
exports.restTestMini.throwOnErr = throwOnErr;
|
|
18
|
+
},
|
|
19
|
+
newErr(err) {
|
|
20
|
+
exports.restTestMini.nbError++;
|
|
21
|
+
exports.restTestMini.lastErrors.push(err);
|
|
22
|
+
if (exports.restTestMini.throwOnErr)
|
|
23
|
+
throw new Error(err);
|
|
24
|
+
else
|
|
25
|
+
logger_utils_1.C.error(false, err);
|
|
26
|
+
},
|
|
27
|
+
printStats() {
|
|
28
|
+
// TODO print last errz
|
|
29
|
+
logger_utils_1.C.info(`ERRORS RESUME =========`);
|
|
30
|
+
if (exports.restTestMini.lastErrors.length)
|
|
31
|
+
logger_utils_1.C.log('\n\n\n');
|
|
32
|
+
for (const lastErr of exports.restTestMini.lastErrors)
|
|
33
|
+
logger_utils_1.C.error(false, lastErr);
|
|
34
|
+
logger_utils_1.C.log('\n\n\n');
|
|
35
|
+
logger_utils_1.C.info(`STATS =========`);
|
|
36
|
+
logger_utils_1.C.info(`Total: ${exports.restTestMini.nbSuccess + exports.restTestMini.nbError}`);
|
|
37
|
+
logger_utils_1.C.success(`Success: ${exports.restTestMini.nbSuccess}`);
|
|
38
|
+
logger_utils_1.C.error(false, ` Errors: ${exports.restTestMini.nbError}`);
|
|
39
|
+
},
|
|
40
|
+
nbSuccess: 0,
|
|
41
|
+
nbError: 0,
|
|
42
|
+
lastErrors: []
|
|
43
|
+
};
|
|
44
|
+
/** if validatorObject param is not set then it will consider checking that the value is set
|
|
45
|
+
*
|
|
46
|
+
* @param description
|
|
47
|
+
* @param value
|
|
48
|
+
* @param validatorObject
|
|
49
|
+
*/
|
|
50
|
+
function assert(description, value, validatorObject) {
|
|
51
|
+
try {
|
|
52
|
+
const validatorObjReal = {
|
|
53
|
+
value,
|
|
54
|
+
name: description,
|
|
55
|
+
};
|
|
56
|
+
if ((0, is_object_1.isObject)(validatorObject))
|
|
57
|
+
Object.assign(validatorObjReal, validatorObject);
|
|
58
|
+
else if ((0, isset_1.isset)(validatorObject))
|
|
59
|
+
validatorObjReal.eq = validatorObject;
|
|
60
|
+
const issetCheck = !(0, isset_1.isset)(validatorObjReal); // isEmpty()
|
|
61
|
+
const [errMsg, , extraInfos] = (0, validation_utils_1.validatorReturnErrArray)(validatorObjReal);
|
|
62
|
+
const msg2 = description + ` ${issetCheck ? 'isset' : `${JSON.stringify(validatorObject)}`}`;
|
|
63
|
+
if ((0, isset_1.isset)(errMsg)) {
|
|
64
|
+
const err = msg2 + `\n ${errMsg}\n ${JSON.stringify(extraInfos)}`;
|
|
65
|
+
exports.restTestMini.newErr(err);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
exports.restTestMini.nbSuccess++;
|
|
69
|
+
logger_utils_1.C.success(msg2);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
exports.restTestMini.newErr(err);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.assert = assert;
|
|
77
|
+
//# sourceMappingURL=tests-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tests-utils.js","sourceRoot":"","sources":["../../src/tests-utils.ts"],"names":[],"mappings":";;;AAAA,0CAA0C;AAC1C,cAAc;AACd,0CAA0C;AAC1C,iDAAkC;AAElC,mCAA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
export declare function timeout(ms: any, fn?: () => void): Promise<void>;
|
|
2
|
+
export declare function runAsync(callback: any, milliseconds$?: number): Promise<void>;
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {Function} callback function that shall return ===true asynchronously
|
|
6
|
+
* @param {Number} timeoutSec default:10; general timeout in seconds
|
|
7
|
+
* @param {Boolean|String} errorAfterNSeconds default:true output an error in case of timeout, can be the displayed error message
|
|
8
|
+
* @param {*} cliOutput write a cli progress to show that a process is running
|
|
9
|
+
*/
|
|
10
|
+
export declare function waitUntilTrue(callback: any, timeoutSec?: number, errorAfterNSeconds?: boolean, cliOutput?: boolean): Promise<void>;
|
|
11
|
+
/** Allow to perform an action in a delayed loop, useful for example to avoid reaching limits on servers. This function can be securely called multiple times.
|
|
12
|
+
* @param {Function} callback
|
|
13
|
+
* @param {Number} time default: 500ms;
|
|
14
|
+
* @param {Function} errorCallback default: e => C.error(e)
|
|
15
|
+
*/
|
|
16
|
+
export declare function executeInDelayedLoop(callback: any, time?: number, errorCallback?: (e: any) => any): Promise<void>;
|