@beecode/msh-util 1.2.0 → 2.0.0-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{lib → dist}/array-util.d.ts +2 -2
- package/{lib → dist}/array-util.d.ts.map +1 -1
- package/dist/array-util.js +27 -0
- package/{lib → dist}/class-factory-pattern.d.ts.map +1 -1
- package/dist/class-factory-pattern.js +26 -0
- package/{lib → dist}/express/error-handler.d.ts.map +1 -1
- package/dist/express/error-handler.js +26 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/{lib → dist}/joi-util.d.ts.map +1 -1
- package/dist/joi-util.js +62 -0
- package/{lib → dist}/memoize-factory.d.ts +1 -1
- package/dist/memoize-factory.d.ts.map +1 -0
- package/dist/memoize-factory.js +24 -0
- package/{lib → dist}/object-util.d.ts.map +1 -1
- package/dist/object-util.js +115 -0
- package/dist/regex-util.js +12 -0
- package/{lib → dist}/single-threshold-promise.d.ts +1 -1
- package/dist/single-threshold-promise.d.ts.map +1 -0
- package/dist/single-threshold-promise.js +46 -0
- package/{lib → dist}/singleton/async.d.ts +1 -1
- package/dist/singleton/async.d.ts.map +1 -0
- package/dist/singleton/async.js +75 -0
- package/{lib → dist}/singleton/pattern.d.ts +1 -1
- package/dist/singleton/pattern.d.ts.map +1 -0
- package/dist/singleton/pattern.js +41 -0
- package/dist/string-util.js +18 -0
- package/dist/time-util.js +90 -0
- package/dist/time-zone.d.ts +467 -0
- package/dist/time-zone.d.ts.map +1 -0
- package/dist/time-zone.js +468 -0
- package/dist/timeout.js +17 -0
- package/dist/type-util.js +54 -0
- package/package.json +160 -99
- package/lib/array-util.js +0 -30
- package/lib/array-util.js.map +0 -1
- package/lib/class-factory-pattern.js +0 -30
- package/lib/class-factory-pattern.js.map +0 -1
- package/lib/express/error-handler.js +0 -28
- package/lib/express/error-handler.js.map +0 -1
- package/lib/index.d.ts +0 -14
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -30
- package/lib/index.js.map +0 -1
- package/lib/joi-util.js +0 -63
- package/lib/joi-util.js.map +0 -1
- package/lib/memoize-factory.d.ts.map +0 -1
- package/lib/memoize-factory.js +0 -28
- package/lib/memoize-factory.js.map +0 -1
- package/lib/object-util.js +0 -118
- package/lib/object-util.js.map +0 -1
- package/lib/regex-util.js +0 -15
- package/lib/regex-util.js.map +0 -1
- package/lib/single-threshold-promise.d.ts.map +0 -1
- package/lib/single-threshold-promise.js +0 -49
- package/lib/single-threshold-promise.js.map +0 -1
- package/lib/singleton/async.d.ts.map +0 -1
- package/lib/singleton/async.js +0 -78
- package/lib/singleton/async.js.map +0 -1
- package/lib/singleton/pattern.d.ts.map +0 -1
- package/lib/singleton/pattern.js +0 -45
- package/lib/singleton/pattern.js.map +0 -1
- package/lib/string-util.js +0 -21
- package/lib/string-util.js.map +0 -1
- package/lib/time-util.js +0 -97
- package/lib/time-util.js.map +0 -1
- package/lib/timeout.js +0 -21
- package/lib/timeout.js.map +0 -1
- package/lib/type-util.js +0 -57
- package/lib/type-util.js.map +0 -1
- package/lib/types/any-function/index.d.ts +0 -2
- package/lib/types/any-function/index.d.ts.map +0 -1
- package/lib/types/any-function/index.js +0 -3
- package/lib/types/any-function/index.js.map +0 -1
- package/lib/types/any-function/no-params.d.ts +0 -2
- package/lib/types/any-function/no-params.d.ts.map +0 -1
- package/lib/types/any-function/no-params.js +0 -3
- package/lib/types/any-function/no-params.js.map +0 -1
- package/lib/types/any-function/promise-no-params.d.ts +0 -2
- package/lib/types/any-function/promise-no-params.d.ts.map +0 -1
- package/lib/types/any-function/promise-no-params.js +0 -3
- package/lib/types/any-function/promise-no-params.js.map +0 -1
- package/lib/types/any-function/promise.d.ts +0 -2
- package/lib/types/any-function/promise.d.ts.map +0 -1
- package/lib/types/any-function/promise.js +0 -3
- package/lib/types/any-function/promise.js.map +0 -1
- /package/{lib → dist}/class-factory-pattern.d.ts +0 -0
- /package/{lib → dist}/express/error-handler.d.ts +0 -0
- /package/{lib → dist}/joi-util.d.ts +0 -0
- /package/{lib → dist}/object-util.d.ts +0 -0
- /package/{lib → dist}/regex-util.d.ts +0 -0
- /package/{lib → dist}/regex-util.d.ts.map +0 -0
- /package/{lib → dist}/string-util.d.ts +0 -0
- /package/{lib → dist}/string-util.d.ts.map +0 -0
- /package/{lib → dist}/time-util.d.ts +0 -0
- /package/{lib → dist}/time-util.d.ts.map +0 -0
- /package/{lib → dist}/timeout.d.ts +0 -0
- /package/{lib → dist}/timeout.d.ts.map +0 -0
- /package/{lib → dist}/type-util.d.ts +0 -0
- /package/{lib → dist}/type-util.d.ts.map +0 -0
package/lib/object-util.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ObjectUtil = void 0;
|
|
7
|
-
const lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep"));
|
|
8
|
-
const util_1 = __importDefault(require("util"));
|
|
9
|
-
class ObjectUtil {
|
|
10
|
-
/**
|
|
11
|
-
* Deep clone object. Returned object will have no references to the object passed through params
|
|
12
|
-
* @template T
|
|
13
|
-
* @param {T} objectToClone
|
|
14
|
-
* @return {T}
|
|
15
|
-
*/
|
|
16
|
-
deepClone(objectToClone) {
|
|
17
|
-
return (0, lodash_clonedeep_1.default)(objectToClone);
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Pick only properties from the property list. It is only allowed to pick properties from the first level
|
|
21
|
-
* @template T
|
|
22
|
-
* @template L
|
|
23
|
-
* @param {T} obj
|
|
24
|
-
* @param {L[]} keyList
|
|
25
|
-
* @return {Pick<T, L>}
|
|
26
|
-
*/
|
|
27
|
-
pickByList(obj, keyList) {
|
|
28
|
-
return keyList.reduce((pickedObj, key) => {
|
|
29
|
-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
30
|
-
pickedObj[key] = obj[key];
|
|
31
|
-
}
|
|
32
|
-
return pickedObj;
|
|
33
|
-
}, {}); // eslint-disable-line @typescript-eslint/prefer-reduce-type-parameter
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Pick objects properties using keys from the second object.
|
|
37
|
-
* @template T
|
|
38
|
-
* @template L
|
|
39
|
-
* @param {T} obj
|
|
40
|
-
* @param {Partial<T>} objWithPickKeys
|
|
41
|
-
* @return {Pick<T, L>}
|
|
42
|
-
*/
|
|
43
|
-
pickByObjectKeys(obj, objWithPickKeys) {
|
|
44
|
-
const keys = Object.keys(objWithPickKeys);
|
|
45
|
-
return this.pickByList(obj, keys);
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* This function will do stringify deeper that JSON.stringify.
|
|
49
|
-
* @param {any} entity - entity thant needs to be stringify
|
|
50
|
-
* @param {object} [options] - available options
|
|
51
|
-
* @param {boolean} [options.isSortable=false] - if object property should be sorted
|
|
52
|
-
* @param {boolean} [options.isPrettyPrinted=false] - if object and array properties should be printed in a new row
|
|
53
|
-
* @param {number} [options.prettyPrintCompactLevel=0] - if pretty print is on define the level of deepest children that are not
|
|
54
|
-
* going to be pretty. It doesn't matter if the siblings doesn't have the same depth.
|
|
55
|
-
* @return {string} - strung result
|
|
56
|
-
* @example
|
|
57
|
-
* console.log(new ObjectUtil().deepStringify(null)) // 'null'
|
|
58
|
-
* console.log(new ObjectUtil().deepStringify(undefined)) // 'undefined'
|
|
59
|
-
* console.log(new ObjectUtil().deepStringify({ a: 1 })) // '{\n\ta: 1\n}'
|
|
60
|
-
* // `{
|
|
61
|
-
* // a:1
|
|
62
|
-
* // }`
|
|
63
|
-
* console.log(new ObjectUtil().deepStringify({ b: 1, a: 2 }, {isSorted:true, compact: true})) // { a: 2, b: 1 }
|
|
64
|
-
*/
|
|
65
|
-
deepStringify(entity, options) {
|
|
66
|
-
const { isSorted = false, isPrettyPrinted = false, prettyPrintCompactLevel = 0 } = options !== null && options !== void 0 ? options : {};
|
|
67
|
-
const compact = this._deepStringifyCompact({ isPrettyPrinted, prettyPrintCompactLevel });
|
|
68
|
-
return util_1.default.inspect(entity, {
|
|
69
|
-
breakLength: Infinity,
|
|
70
|
-
compact,
|
|
71
|
-
depth: Infinity,
|
|
72
|
-
maxArrayLength: Infinity,
|
|
73
|
-
maxStringLength: Infinity,
|
|
74
|
-
sorted: isSorted,
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
_deepStringifyCompact(params) {
|
|
78
|
-
const { isPrettyPrinted, prettyPrintCompactLevel } = params;
|
|
79
|
-
if (!isPrettyPrinted) {
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
return prettyPrintCompactLevel;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* We are converting objects to string (or null or undefined) and comparing if the result is equal
|
|
86
|
-
* @param a
|
|
87
|
-
* @param b
|
|
88
|
-
* @return {boolean}
|
|
89
|
-
*/
|
|
90
|
-
deepEqual(a, b) {
|
|
91
|
-
return this.deepStringify(a, { isSorted: true }) === this.deepStringify(b, { isSorted: true });
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* This function is going to convert any null to undefined in the object that is passed to it.
|
|
95
|
-
* @template T
|
|
96
|
-
* @param {T} objectWithNulls
|
|
97
|
-
* @return {T}
|
|
98
|
-
* @example
|
|
99
|
-
* console.log(new ObjectUtil().deepNullToUndefined({ a: null, b: { c: null } })) // { a: undefined, b: { c: undefined } }
|
|
100
|
-
*/
|
|
101
|
-
deepNullToUndefined(objectWithNulls) {
|
|
102
|
-
return Object.entries(objectWithNulls).reduce((acc, cur) => {
|
|
103
|
-
const [key, value] = cur;
|
|
104
|
-
if (value === null) {
|
|
105
|
-
acc[key] = undefined;
|
|
106
|
-
}
|
|
107
|
-
else if (typeof value === 'object' && !(value instanceof Date)) {
|
|
108
|
-
acc[key] = this.deepNullToUndefined(value);
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
acc[key] = value;
|
|
112
|
-
}
|
|
113
|
-
return acc;
|
|
114
|
-
}, {});
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
exports.ObjectUtil = ObjectUtil;
|
|
118
|
-
//# sourceMappingURL=object-util.js.map
|
package/lib/object-util.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"object-util.js","sourceRoot":"","sources":["../src/object-util.ts"],"names":[],"mappings":";;;;;;AAAA,wEAAwC;AACxC,gDAAuB;AAIvB,MAAa,UAAU;IACtB;;;;;OAKG;IACH,SAAS,CAAuB,aAAgB;QAC/C,OAAO,IAAA,0BAAS,EAAC,aAAa,CAAC,CAAA;IAChC,CAAC;IAED;;;;;;;OAOG;IACH,UAAU,CAAsC,GAAM,EAAE,OAAuB;QAC9E,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,EAAE;YACxC,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE;gBACnD,SAAS,CAAC,GAAQ,CAAC,GAAG,GAAG,CAAC,GAAQ,CAAC,CAAA;aACnC;YAED,OAAO,SAAS,CAAA;QACjB,CAAC,EAAE,EAAgB,CAAC,CAAA,CAAC,sEAAsE;IAC5F,CAAC;IAED;;;;;;;OAOG;IACH,gBAAgB,CAAsC,GAAM,EAAE,eAAwC;QACrG,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,eAAe,CAAQ,CAAA;QAEhD,OAAO,IAAI,CAAC,UAAU,CAAO,GAAG,EAAE,IAAI,CAAC,CAAA;IACxC,CAAC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,aAAa,CACZ,MAAW,EACX,OAA6F;QAE7F,MAAM,EAAE,QAAQ,GAAG,KAAK,EAAE,eAAe,GAAG,KAAK,EAAE,uBAAuB,GAAG,C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AC,mBAAmB,CAAC,KAAK,CAAC,CAAA;aAC1C;iBAAM;gBACN,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;aAChB;YAED,OAAO,GAAG,CAAA;QACX,CAAC,EAAE,EAAE,CAAC,CAAA;IACP,CAAC;CACD;AAzHD,gCAyHC"}
|
package/lib/regex-util.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.regexUtil = void 0;
|
|
4
|
-
exports.regexUtil = {
|
|
5
|
-
/**
|
|
6
|
-
* This is a UUID regex expression. This is usually used in express router to constrict the values passed as a path parameter (if you are using UUID as your identifier).
|
|
7
|
-
* @return {string}
|
|
8
|
-
* @example
|
|
9
|
-
* const { uuid } = regexUtil
|
|
10
|
-
* router.route(`/users/:userId(${uuid})`).get(getUsersById)
|
|
11
|
-
* //...
|
|
12
|
-
*/
|
|
13
|
-
uuid: `\\b[0-9a-f]{8}\\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\\b[0-9a-f]{12}\\b`,
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=regex-util.js.map
|
package/lib/regex-util.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"regex-util.js","sourceRoot":"","sources":["../src/regex-util.ts"],"names":[],"mappings":";;;AAAa,QAAA,SAAS,GAAG;IACxB;;;;;;;OAOG;IACH,IAAI,EAAE,0EAAmF;CACzF,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"single-threshold-promise.d.ts","sourceRoot":"","sources":["../src/single-threshold-promise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,0CAA0C,CAAA;AAErF;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,sBAAsB,CAAC,CAAC;IACpC,SAAS,CAAC,MAAM,EAAE;QACjB,QAAQ,CAAC,EAAE;YAAE,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;YAAC,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,IAAI,CAAA;SAAE,EAAE,CAAA;KAC7F,CAAK;IAEN,SAAS,CAAC,UAAU,EAAE,0BAA0B,CAAC,CAAC,CAAC,CAAA;gBAEvC,SAAS,EAAE,0BAA0B,CAAC,CAAC,CAAC;IAIpD,SAAS,CAAC,eAAe,IAAI,IAAI;IAO3B,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC;CAkB3B"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SingleThresholdPromise = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* SingleThresholdPromise returns a single promise, and subsequent calls made before the promise resolves will return the same promise.
|
|
6
|
-
* @example
|
|
7
|
-
* export const refreshTokenSingleThreshold = new SingleThresholdPromise(async () => {
|
|
8
|
-
* const oldRefreshToken = await refreshTokenService.get()
|
|
9
|
-
* const { accessToken, refreshToken } = await authService.refreshToken({
|
|
10
|
-
* refreshToken: oldRefreshToken,
|
|
11
|
-
* })
|
|
12
|
-
* return { accessToken, refreshToken }
|
|
13
|
-
* })
|
|
14
|
-
*
|
|
15
|
-
* export const authService = {
|
|
16
|
-
* refreshToken: async (): Promise<{ accessToken: string; refreshToken:string }> => {
|
|
17
|
-
* return refreshTokenSingleThreshold.promise()
|
|
18
|
-
* }
|
|
19
|
-
* }
|
|
20
|
-
*/
|
|
21
|
-
class SingleThresholdPromise {
|
|
22
|
-
constructor(factoryFn) {
|
|
23
|
-
this._cache = {};
|
|
24
|
-
this._factoryFn = factoryFn;
|
|
25
|
-
}
|
|
26
|
-
_rejectPromises() {
|
|
27
|
-
if (this._cache.promises) {
|
|
28
|
-
this._cache.promises.forEach((promise) => promise.reject(new Error('Cache was cleaned')));
|
|
29
|
-
}
|
|
30
|
-
delete this._cache.promises;
|
|
31
|
-
}
|
|
32
|
-
async promise() {
|
|
33
|
-
if ('promises' in this._cache) {
|
|
34
|
-
return new Promise((resolve, reject) => {
|
|
35
|
-
this._cache.promises.push({ reject, resolve });
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
this._cache.promises = [];
|
|
39
|
-
const result = await this._factoryFn().catch((err) => {
|
|
40
|
-
this._rejectPromises();
|
|
41
|
-
throw err;
|
|
42
|
-
});
|
|
43
|
-
this._cache.promises.forEach((promise) => promise.resolve(result));
|
|
44
|
-
delete this._cache.promises;
|
|
45
|
-
return result;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
exports.SingleThresholdPromise = SingleThresholdPromise;
|
|
49
|
-
//# sourceMappingURL=single-threshold-promise.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"single-threshold-promise.js","sourceRoot":"","sources":["../src/single-threshold-promise.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAa,sBAAsB;IAOlC,YAAY,SAAwC;QAN1C,WAAM,GAEZ,EAAE,CAAA;QAKL,IAAI,CAAC,UAAU,GAAG,SAAS,CAAA;IAC5B,CAAC;IAES,eAAe;QACxB,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;YACzB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAA;SACzF;QACD,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAA;IAC5B,CAAC;IAED,KAAK,CAAC,OAAO;QACZ,IAAI,UAAU,IAAI,IAAI,CAAC,MAAM,EAAE;YAC9B,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBACzC,IAA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;IAKlB,SAAS,CAAC,eAAe,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,KAAK,CAAA;KAAE,GAAG,IAAI;IASzD;;;;OAIG;IACG,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC;IAuB3B;;;;OAIG;IACH,MAAM,IAAI,CAAC,GAAG,SAAS;CAOvB"}
|
package/lib/singleton/async.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SingletonAsync = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* This is a singleton wrapper that is used to wrap around async function. We have additional functionality to clear the cache
|
|
6
|
-
* and reject any subscriptions to initial promise. And we can also check if there is anything i cache
|
|
7
|
-
* @example
|
|
8
|
-
* export const configSingleton = new SingletonAsync(async () => {
|
|
9
|
-
* await timeout(3000)
|
|
10
|
-
* return {
|
|
11
|
-
* env: process.env.NODE_ENV
|
|
12
|
-
* } as const
|
|
13
|
-
* })
|
|
14
|
-
*
|
|
15
|
-
* // using
|
|
16
|
-
* // cache value before we call promise
|
|
17
|
-
* console.log(configSingleton().cache()) // undefined
|
|
18
|
-
* console.log('NODE_ENV: ', await configSingleton().promise().env) // NODE_ENV: prod
|
|
19
|
-
* // cache value after we call promise
|
|
20
|
-
* console.log(configSingleton().cache()) // { env: 'prod' }
|
|
21
|
-
*/
|
|
22
|
-
class SingletonAsync {
|
|
23
|
-
constructor(factory) {
|
|
24
|
-
this._cache = {};
|
|
25
|
-
this._factory = factory;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Empty cached value and reject any subscribed promise that is waiting for the initial promise to be resolved.
|
|
29
|
-
*/
|
|
30
|
-
cleanCache() {
|
|
31
|
-
delete this._cache.singleton;
|
|
32
|
-
this._rejectPromises({ error: new Error('Cache was cleaned') });
|
|
33
|
-
}
|
|
34
|
-
_rejectPromises(params) {
|
|
35
|
-
const { error } = params;
|
|
36
|
-
if (this._cache.promises) {
|
|
37
|
-
this._cache.promises.forEach((promise) => promise.reject(error));
|
|
38
|
-
}
|
|
39
|
-
delete this._cache.promises;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Return singleton value in a promise. If there is no cached value then try to get it from factory.
|
|
43
|
-
* @template T
|
|
44
|
-
* @returns {Promise<T>}
|
|
45
|
-
*/
|
|
46
|
-
async promise() {
|
|
47
|
-
if ('singleton' in this._cache) {
|
|
48
|
-
return this._cache.singleton;
|
|
49
|
-
}
|
|
50
|
-
if ('promises' in this._cache) {
|
|
51
|
-
return new Promise((resolve, reject) => {
|
|
52
|
-
this._cache.promises.push({ reject, resolve });
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
this._cache.promises = [];
|
|
56
|
-
const result = await this._factory().catch((error) => {
|
|
57
|
-
this._rejectPromises({ error });
|
|
58
|
-
throw error;
|
|
59
|
-
});
|
|
60
|
-
this._cache.singleton = result;
|
|
61
|
-
this._cache.promises.forEach((promise) => promise.resolve(result));
|
|
62
|
-
delete this._cache.promises;
|
|
63
|
-
return result;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Return cached value, if there is no value cached return undefined.
|
|
67
|
-
* @template T
|
|
68
|
-
* @returns {T | undefined}
|
|
69
|
-
*/
|
|
70
|
-
cached() {
|
|
71
|
-
if ('singleton' in this._cache) {
|
|
72
|
-
return this._cache.singleton;
|
|
73
|
-
}
|
|
74
|
-
return undefined;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
exports.SingletonAsync = SingletonAsync;
|
|
78
|
-
//# sourceMappingURL=async.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"async.js","sourceRoot":"","sources":["../../src/singleton/async.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAa,cAAc;IAQ1B,YAAY,OAAsC;QAPxC,WAAM,GAGZ,EAAE,CAAA;QAKL,IAAI,CAAC,QAAQ,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AE9B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAA;QAClE,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAA;QAE3B,OAAO,MAAM,CAAA;IACd,CAAC;IAED;;;;OAIG;IACH,MAAM;QACL,IAAI,WAAW,IAAI,IAAI,CAAC,MAAM,EAAE;YAC/B,OAAO,IAAI,CAAC,MAAM,CAAC,SAAU,CAAA;SAC7B;QAED,OAAO,SAAS,CAAA;IACjB,CAAC;CACD;AArED,wCAqEC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pattern.d.ts","sourceRoot":"","sources":["../../src/singleton/pattern.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAA;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,gBAAgB,kEAU5B,CAAA"}
|
package/lib/singleton/pattern.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.singletonPattern = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Singleton patter wrapper function
|
|
6
|
-
* @param {AnyFunctionNoParams<R>} factoryFn Factory function that is used to generate value that is going to be cached and return by
|
|
7
|
-
* singleton.
|
|
8
|
-
* @return {AnyFunctionNoParams<R>} Function result that returns cached value.
|
|
9
|
-
* @example
|
|
10
|
-
* export class SomeClass {
|
|
11
|
-
* constructor(protected _param: string){ }
|
|
12
|
-
* get param(): string {
|
|
13
|
-
* return this._param
|
|
14
|
-
* }
|
|
15
|
-
* }
|
|
16
|
-
* export const someClassSingleton = singletonPattern((): SomeClass => {
|
|
17
|
-
* return new SomeClass('some param value')
|
|
18
|
-
* })
|
|
19
|
-
*
|
|
20
|
-
* // using
|
|
21
|
-
* console.log('param: ', someClassSingleton().param) // param: some param value
|
|
22
|
-
*
|
|
23
|
-
* ///////////////////////////////////////////
|
|
24
|
-
* // Or we can use it with simple function //
|
|
25
|
-
* ///////////////////////////////////////////
|
|
26
|
-
* export const config = singletonPattern(() => {
|
|
27
|
-
* return {
|
|
28
|
-
* env: process.NODE_ENV,
|
|
29
|
-
* } as const
|
|
30
|
-
* })
|
|
31
|
-
*
|
|
32
|
-
* // using
|
|
33
|
-
* console.log('NODE_ENV: ', config().env) // NODE_ENV: prod
|
|
34
|
-
*/
|
|
35
|
-
const singletonPattern = (factoryFn) => {
|
|
36
|
-
const cache = {};
|
|
37
|
-
return () => {
|
|
38
|
-
if ('singleton' in cache) {
|
|
39
|
-
return cache.singleton;
|
|
40
|
-
}
|
|
41
|
-
return (cache.singleton = factoryFn());
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
exports.singletonPattern = singletonPattern;
|
|
45
|
-
//# sourceMappingURL=pattern.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pattern.js","sourceRoot":"","sources":["../../src/singleton/pattern.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACI,MAAM,gBAAgB,GAAG,CAAI,SAAiC,EAA0B,EAAE;IAChG,MAAM,KAAK,GAAsB,EAAE,CAAA;IAEnC,OAAO,GAAM,EAAE;QACd,IAAI,WAAW,IAAI,KAAK,EAAE;YACzB,OAAO,KAAK,CAAC,SAAU,CAAA;SACvB;QAED,OAAO,CAAC,KAAK,CAAC,SAAS,GAAG,SAAS,EAAE,CAAC,CAAA;IACvC,CAAC,CAAA;AACF,CAAC,CAAA;AAVY,QAAA,gBAAgB,oBAU5B"}
|
package/lib/string-util.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stringUtil = void 0;
|
|
4
|
-
exports.stringUtil = {
|
|
5
|
-
/**
|
|
6
|
-
* Generate random UUID
|
|
7
|
-
* @return {string}
|
|
8
|
-
* @example
|
|
9
|
-
* console.log(stringUtil.uuid()) // "69bfda25-df3f-46b4-8bbb-955cf5193426"
|
|
10
|
-
*/
|
|
11
|
-
generateUUID: () => {
|
|
12
|
-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
13
|
-
const r = (Math.random() * 16) | 0;
|
|
14
|
-
if (c == 'x') {
|
|
15
|
-
return r.toString(16);
|
|
16
|
-
}
|
|
17
|
-
return ((r & 0x3) | 0x8).toString(16);
|
|
18
|
-
});
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
//# sourceMappingURL=string-util.js.map
|
package/lib/string-util.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"string-util.js","sourceRoot":"","sources":["../src/string-util.ts"],"names":[],"mappings":";;;AAAa,QAAA,UAAU,GAAG;IACzB;;;;;OAKG;IACH,YAAY,EAAE,GAAW,EAAE;QAC1B,OAAO,sCAAsC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;YACpE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAA;YAClC,IAAI,CAAC,IAAI,GAAG,EAAE;gBACb,OAAO,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;aACrB;YAED,OAAO,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;QACtC,CAAC,CAAC,CAAA;IACH,CAAC;CACD,CAAA"}
|
package/lib/time-util.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.TimeUtil = exports.DurationUnit = void 0;
|
|
7
|
-
const add_1 = __importDefault(require("date-fns/add"));
|
|
8
|
-
const addMilliseconds_1 = __importDefault(require("date-fns/addMilliseconds"));
|
|
9
|
-
const format_1 = __importDefault(require("date-fns/format"));
|
|
10
|
-
const parse_1 = __importDefault(require("date-fns/parse"));
|
|
11
|
-
var DurationUnit;
|
|
12
|
-
(function (DurationUnit) {
|
|
13
|
-
DurationUnit["MILLISECOND"] = "MILLISECOND";
|
|
14
|
-
DurationUnit["SECOND"] = "SECOND";
|
|
15
|
-
DurationUnit["MINUTE"] = "MINUTE";
|
|
16
|
-
DurationUnit["HOUR"] = "HOUR";
|
|
17
|
-
DurationUnit["DAY"] = "DAY";
|
|
18
|
-
DurationUnit["WEEK"] = "WEEK";
|
|
19
|
-
DurationUnit["MONTH"] = "MONTH";
|
|
20
|
-
DurationUnit["YEAR"] = "YEAR";
|
|
21
|
-
})(DurationUnit = exports.DurationUnit || (exports.DurationUnit = {}));
|
|
22
|
-
class TimeUtil {
|
|
23
|
-
/**
|
|
24
|
-
* return date object with the current time
|
|
25
|
-
* @return {Date}
|
|
26
|
-
* @example
|
|
27
|
-
* console.log(new TimeUtil().now().toISOString()) // 2023-03-08T19:45:01.991Z
|
|
28
|
-
*/
|
|
29
|
-
now() {
|
|
30
|
-
return new Date();
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Convert date object to unix timestamp (milliseconds)
|
|
34
|
-
* @param {Date} date
|
|
35
|
-
* @return {number}
|
|
36
|
-
* @example
|
|
37
|
-
* // timeUtil.now().toISOString() === 2023-03-08T19:45:01.991Z
|
|
38
|
-
* const timeUtil = new TimeUtil()
|
|
39
|
-
* console.log(timeUtil.dateToUnix(timeUtil.now())) // 1678304701991
|
|
40
|
-
*/
|
|
41
|
-
dateToUnix(date) {
|
|
42
|
-
return +(0, format_1.default)(date, 'T');
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Convert date object to unix timestamp (seconds)
|
|
46
|
-
* @param {Date} date
|
|
47
|
-
* @return {number}
|
|
48
|
-
* @example
|
|
49
|
-
* // timeUtil.now().toISOString() === 2023-03-08T19:45:01.991Z
|
|
50
|
-
* const timeUtil = new TimeUtil()
|
|
51
|
-
* console.log(timeUtil.dateToUnix(timeUtil.now())) // 1678304701
|
|
52
|
-
*/
|
|
53
|
-
dateToUnixSec(date) {
|
|
54
|
-
return +(0, format_1.default)(date, 't');
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Convert unix timestamp (milliseconds) to date object
|
|
58
|
-
* @param {number} unix
|
|
59
|
-
* @return {Date}
|
|
60
|
-
* @example
|
|
61
|
-
* const timeUtil = new TimeUtil()
|
|
62
|
-
* console.log(timeUtil.unixToDate(1678304701991).toISOString()) // 2023-03-08T19:45:01.991Z
|
|
63
|
-
*/
|
|
64
|
-
unixToDate(unix) {
|
|
65
|
-
return (0, parse_1.default)(unix.toString(), 'T', this.now());
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Convert unix timestamp (seconds) to date object
|
|
69
|
-
* @param {number} unix
|
|
70
|
-
* @return {Date}
|
|
71
|
-
* @example
|
|
72
|
-
* const timeUtil = new TimeUtil()
|
|
73
|
-
* console.log(timeUtil.unixToDate(1678304701).toISOString()) // 2023-03-08T19:45:01.000Z
|
|
74
|
-
*/
|
|
75
|
-
unixSecToDate(unix) {
|
|
76
|
-
return (0, parse_1.default)(unix.toString(), 't', this.now());
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Change the value of date by unit/value pare.
|
|
80
|
-
* @param {{units: DurationUnitType, value: number, date: Date}} params
|
|
81
|
-
* @return {Date}
|
|
82
|
-
* @example
|
|
83
|
-
* // timeUtil.now().toISOString() === 2023-03-08T19:45:01.991Z
|
|
84
|
-
* const timeUtil = new TimeUtil()
|
|
85
|
-
* console.log(timeUtil.addToDate({date: timeUtil.now(), unit: 'DAY', value: 1 }).toISOString()) // 2023-03-09T19:45:01.991Z
|
|
86
|
-
* console.log(timeUtil.addToDate({date: timeUtil.now(), unit: DurationUnit.MONTH, value: -1 }).toISOString()) //2023-02-08T19:45:01.991Z
|
|
87
|
-
*/
|
|
88
|
-
addToDate(params) {
|
|
89
|
-
const { date, unit, value } = params;
|
|
90
|
-
if (`${unit}` === 'MILLISECOND') {
|
|
91
|
-
return (0, addMilliseconds_1.default)(date, value);
|
|
92
|
-
}
|
|
93
|
-
return (0, add_1.default)(date, { [`${unit.toLowerCase()}s`]: value });
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
exports.TimeUtil = TimeUtil;
|
|
97
|
-
//# sourceMappingURL=time-util.js.map
|
package/lib/time-util.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"time-util.js","sourceRoot":"","sources":["../src/time-util.ts"],"names":[],"mappings":";;;;;;AAAA,uDAA8B;AAC9B,+EAAsD;AACtD,6DAAoC;AACpC,2DAAkC;AAElC,IAAY,YASX;AATD,WAAY,YAAY;IACvB,2CAA2B,CAAA;IAC3B,iCAAiB,CAAA;IACjB,iCAAiB,CAAA;IACjB,6BAAa,CAAA;IACb,2BAAW,CAAA;IACX,6BAAa,CAAA;IACb,+BAAe,CAAA;IACf,6BAAa,CAAA;AACd,CAAC,EATW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QASvB;AAID,MAAa,QAAQ;IACpB;;;;;OAKG;IACH,GAAG;QACF,OAAO,IAAI,IAAI,EAAE,CAAA;IAClB,CAAC;IAED;;;;;;;;OAQG;IACH,UAAU,CAAC,IAAU;QACpB,OAAO,CAAC,IAAA,gBAAM,EAAC,IAAI,EAAE,GAAG,CAAC,CAAA;IAC1B,CAAC;IAED;;;;;;;;OAQG;IACH,aAAa,CAAC,IAAU;QACvB,OAAO,CAAC,IAAA,gBAAM,EAAC,IAAI,EAAE,GAAG,CAAC,CAAA;IAC1B,CAAC;IAED;;;;;;;OAOG;IACH,UAAU,CAAC,IAAY;QACtB,OAAO,IAAA,eAAK,EAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;IAC/C,CAAC;IAED;;;;;;;OAOG;IACH,aAAa,CAAC,IAAY;QACzB,OAAO,IAAA,eAAK,EAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;IAC/C,CAAC;IAED;;;;;;;;;OASG;IACH,SAAS,CAAC,MAA4E;QACrF,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,CAAA;QACpC,IAAI,GAAG,IAAI,EAAE,KAAK,aAAa,EAAE;YAChC,OAAO,IAAA,yBAAe,EAAC,IAAI,EAAE,KAAK,CAAC,CAAA;SACnC;QAED,OAAO,IAAA,aAAG,EAAC,IAAI,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,WAAW,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC,CAAA;IACxD,CAAC;CACD;AA/ED,4BA+EC"}
|
package/lib/timeout.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.timeout = void 0;
|
|
4
|
-
/**
|
|
5
|
-
*
|
|
6
|
-
* @param {number} ms The time, in milliseconds that the timer should wait before the specified function or code is executed. If this parameter is omitted, a value of 0 is used, meaning execute "immediately", or more accurately, the next event cycle.
|
|
7
|
-
* @return {Promise<void>}
|
|
8
|
-
* @example
|
|
9
|
-
* const lightBlink = (): void => {
|
|
10
|
-
* turnLightOn()
|
|
11
|
-
* timeout(3000) // wait for 3 seconds
|
|
12
|
-
* turnLightOff()
|
|
13
|
-
* timeout(3000) // wait for 3 seconds
|
|
14
|
-
* turnLightOn()
|
|
15
|
-
* }
|
|
16
|
-
*/
|
|
17
|
-
const timeout = (ms) => {
|
|
18
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
19
|
-
};
|
|
20
|
-
exports.timeout = timeout;
|
|
21
|
-
//# sourceMappingURL=timeout.js.map
|
package/lib/timeout.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"timeout.js","sourceRoot":"","sources":["../src/timeout.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;GAYG;AACI,MAAM,OAAO,GAAG,CAAC,EAAU,EAAiB,EAAE;IACpD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAA;AACzD,CAAC,CAAA;AAFY,QAAA,OAAO,WAEnB"}
|
package/lib/type-util.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.typeUtil = void 0;
|
|
4
|
-
exports.typeUtil = {
|
|
5
|
-
/**
|
|
6
|
-
* This is the similar to exhaustiveMessage, but instead of message we are returning error so we can throw it
|
|
7
|
-
* @param {string} message
|
|
8
|
-
* @param {never} _
|
|
9
|
-
* @return {Error}
|
|
10
|
-
* @example
|
|
11
|
-
* export type Animal = 'cat' | 'dog' | 'bird';
|
|
12
|
-
*
|
|
13
|
-
* export const makeSound = (animal: Animal): string => {
|
|
14
|
-
* switch (animal) {
|
|
15
|
-
* case 'cat':
|
|
16
|
-
* return 'Meow'
|
|
17
|
-
* case 'dog':
|
|
18
|
-
* return 'Woof'
|
|
19
|
-
* case 'bird':
|
|
20
|
-
* return 'Tweet'
|
|
21
|
-
* default:
|
|
22
|
-
* throw typeUtil.exhaustiveError('Unknown animal [animal]', animal)
|
|
23
|
-
* }
|
|
24
|
-
* }
|
|
25
|
-
*/
|
|
26
|
-
exhaustiveError: (message, _) => {
|
|
27
|
-
return new Error(message);
|
|
28
|
-
},
|
|
29
|
-
/**
|
|
30
|
-
* In TypeScript, exhaustiveMessage is a technique that can be used with switch statements to ensure that all possible cases are handled.
|
|
31
|
-
*
|
|
32
|
-
* When using switch statements, it is common to have a default case that handles any unanticipated cases. However, sometimes it is important to ensure that all cases are explicitly handled to avoid potential errors or bugs in the code.
|
|
33
|
-
* @param {string} message
|
|
34
|
-
* @param {never} _
|
|
35
|
-
* @return {string}
|
|
36
|
-
* @example
|
|
37
|
-
* export type Animal = 'cat' | 'dog' | 'bird';
|
|
38
|
-
*
|
|
39
|
-
* export const makeSound = (animal: Animal): string => {
|
|
40
|
-
* switch (animal) {
|
|
41
|
-
* case 'cat':
|
|
42
|
-
* return 'Meow'
|
|
43
|
-
* case 'dog':
|
|
44
|
-
* return 'Woof'
|
|
45
|
-
* case 'bird':
|
|
46
|
-
* return 'Tweet'
|
|
47
|
-
* default:
|
|
48
|
-
* console.error(new TypeUtil().exhaustiveMessage('Unknown animal [animal]', animal))
|
|
49
|
-
* return 'unknown sound'
|
|
50
|
-
* }
|
|
51
|
-
* }
|
|
52
|
-
*/
|
|
53
|
-
exhaustiveMessage: (message, _) => {
|
|
54
|
-
return message;
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
//# sourceMappingURL=type-util.js.map
|
package/lib/type-util.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"type-util.js","sourceRoot":"","sources":["../src/type-util.ts"],"names":[],"mappings":";;;AAAa,QAAA,QAAQ,GAAG;IACvB;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,eAAe,EAAE,CAAC,OAAe,EAAE,CAAQ,EAAS,EAAE;QACrD,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,CAAA;IAC1B,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,iBAAiB,EAAE,CAAC,OAAe,EAAE,CAAQ,EAAU,EAAE;QACxD,OAAO,OAAO,CAAA;IACf,CAAC;CACD,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/any-function/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/any-function/index.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"no-params.d.ts","sourceRoot":"","sources":["../../../src/types/any-function/no-params.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,MAAM,CAAC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"no-params.js","sourceRoot":"","sources":["../../../src/types/any-function/no-params.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"promise-no-params.d.ts","sourceRoot":"","sources":["../../../src/types/any-function/promise-no-params.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,0BAA0B,CAAC,CAAC,IAAI,MAAM,OAAO,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"promise-no-params.js","sourceRoot":"","sources":["../../../src/types/any-function/promise-no-params.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../../../src/types/any-function/promise.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"promise.js","sourceRoot":"","sources":["../../../src/types/any-function/promise.ts"],"names":[],"mappings":""}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|