@nu-art/ts-common 0.204.142 → 0.204.144
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/core/debug-flags.js +2 -2
- package/core/error-handling.js +1 -1
- package/core/exceptions/exceptions.js +2 -2
- package/core/logger/LogClient.js +2 -2
- package/core/logger/Logger.js +2 -2
- package/core/logger/types.js +1 -1
- package/core/logger/utils.js +4 -5
- package/core/module-manager.d.ts +10 -10
- package/core/module-manager.js +2 -2
- package/mem-storage/MemStorage.d.ts +1 -1
- package/modules/CSVModule.d.ts +0 -2
- package/modules/CSVModuleV3.d.ts +1 -1
- package/modules/csv-serializer.js +1 -2
- package/package.json +1 -1
- package/replacer-v2/ReplacerV2.js +1 -1
- package/testing/consts.d.ts +1 -3
- package/testing/consts.js +2 -2
- package/tools/Replacer.js +1 -1
- package/tools/get-log-style.js +1 -2
- package/utils/array-tools.js +33 -34
- package/utils/crypto-tools.d.ts +0 -1
- package/utils/crypto-tools.js +3 -4
- package/utils/date-time-tools.js +17 -17
- package/utils/db-object-tools.js +6 -6
- package/utils/exception-tools.js +1 -2
- package/utils/filter-tools.js +1 -1
- package/utils/hash-tools.d.ts +0 -1
- package/utils/hash-tools.js +7 -8
- package/utils/json-tools.js +2 -3
- package/utils/merge-tools.js +3 -4
- package/utils/object-tools.js +11 -12
- package/utils/query-params.js +2 -3
- package/utils/random-tools.js +3 -4
- package/utils/string-tools.js +13 -14
- package/utils/tools.js +7 -7
- package/utils/version-tools.d.ts +5 -0
- package/utils/version-tools.js +15 -6
- package/validator/type-validators.d.ts +7 -7
- package/validator/validator-core.d.ts +1 -1
package/utils/date-time-tools.js
CHANGED
|
@@ -20,7 +20,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
20
20
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.
|
|
23
|
+
exports.DateTimeFormat_DDMMYYYY = exports.DateTimeFormat_yyyyMMDD = exports.DateTimeFormat_yyyyMMDDTHHmmss = exports.DateTimeFormat = exports.sleep = exports.Weekdays = exports.Format_YYYYMMDD_HHmmss = exports.Format_HHmmss_DDMMYYYY = exports.Month = exports.Year = exports.Week = exports.Day = exports.Hour = exports.Minute = exports.Second = void 0;
|
|
24
|
+
exports.timeout = timeout;
|
|
25
|
+
exports._setTimeout = _setTimeout;
|
|
26
|
+
exports._clearTimeout = _clearTimeout;
|
|
27
|
+
exports._setInterval = _setInterval;
|
|
28
|
+
exports._clearInterval = _clearInterval;
|
|
29
|
+
exports.auditBy = auditBy;
|
|
30
|
+
exports.currentTimeMillis = currentTimeMillis;
|
|
31
|
+
exports.specificTimeTodayMillis = specificTimeTodayMillis;
|
|
32
|
+
exports.currentLocalTimeMillis = currentLocalTimeMillis;
|
|
33
|
+
exports.currentTimeMillisWithTimeZone = currentTimeMillisWithTimeZone;
|
|
34
|
+
exports.createReadableTimestampObject = createReadableTimestampObject;
|
|
35
|
+
exports.formatTimestamp = formatTimestamp;
|
|
36
|
+
exports.parseTimeString = parseTimeString;
|
|
37
|
+
exports.normalizeTimestamp = normalizeTimestamp;
|
|
38
|
+
exports.isSameDay = isSameDay;
|
|
39
|
+
exports.deltaDays = deltaDays;
|
|
24
40
|
const moment_1 = __importDefault(require("moment"));
|
|
25
41
|
const moment_2 = require("moment");
|
|
26
42
|
exports.Second = 1000;
|
|
@@ -36,28 +52,23 @@ exports.Weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Fri
|
|
|
36
52
|
async function timeout(sleepMs) {
|
|
37
53
|
return new Promise(resolve => setTimeout(resolve, sleepMs, undefined));
|
|
38
54
|
}
|
|
39
|
-
exports.timeout = timeout;
|
|
40
55
|
exports.sleep = timeout;
|
|
41
56
|
function _setTimeout(handler, sleepMs = 0, ...args) {
|
|
42
57
|
return setTimeout(handler, sleepMs, ...args);
|
|
43
58
|
}
|
|
44
|
-
exports._setTimeout = _setTimeout;
|
|
45
59
|
function _clearTimeout(handlerId) {
|
|
46
60
|
if (!handlerId)
|
|
47
61
|
return;
|
|
48
62
|
return clearTimeout(handlerId);
|
|
49
63
|
}
|
|
50
|
-
exports._clearTimeout = _clearTimeout;
|
|
51
64
|
function _setInterval(handler, sleepMs = 0, ...args) {
|
|
52
65
|
return setInterval(handler, sleepMs, ...args);
|
|
53
66
|
}
|
|
54
|
-
exports._setInterval = _setInterval;
|
|
55
67
|
function _clearInterval(handlerId) {
|
|
56
68
|
if (!handlerId)
|
|
57
69
|
return;
|
|
58
70
|
return clearInterval(handlerId);
|
|
59
71
|
}
|
|
60
|
-
exports._clearInterval = _clearInterval;
|
|
61
72
|
/**
|
|
62
73
|
* @param comment @deprecated
|
|
63
74
|
*/
|
|
@@ -70,28 +81,23 @@ function auditBy(user, comment, timestamp = currentTimeMillis()) {
|
|
|
70
81
|
_auditBy.comment = comment;
|
|
71
82
|
return _auditBy;
|
|
72
83
|
}
|
|
73
|
-
exports.auditBy = auditBy;
|
|
74
84
|
function currentTimeMillis() {
|
|
75
85
|
return Date.now();
|
|
76
86
|
}
|
|
77
|
-
exports.currentTimeMillis = currentTimeMillis;
|
|
78
87
|
function specificTimeTodayMillis(hours, minutes) {
|
|
79
88
|
const date = new Date();
|
|
80
89
|
date.setHours(hours);
|
|
81
90
|
date.setMinutes(minutes);
|
|
82
91
|
return date.getTime();
|
|
83
92
|
}
|
|
84
|
-
exports.specificTimeTodayMillis = specificTimeTodayMillis;
|
|
85
93
|
function currentLocalTimeMillis() {
|
|
86
94
|
const date = new Date();
|
|
87
95
|
return date.getTime();
|
|
88
96
|
}
|
|
89
|
-
exports.currentLocalTimeMillis = currentLocalTimeMillis;
|
|
90
97
|
function currentTimeMillisWithTimeZone() {
|
|
91
98
|
const date = new Date();
|
|
92
99
|
return date.getTime() + date.getTimezoneOffset();
|
|
93
100
|
}
|
|
94
|
-
exports.currentTimeMillisWithTimeZone = currentTimeMillisWithTimeZone;
|
|
95
101
|
function createReadableTimestampObject(pattern = exports.Format_HHmmss_DDMMYYYY, timestamp = currentTimeMillis(), timezone) {
|
|
96
102
|
const timeObj = {
|
|
97
103
|
timestamp: timestamp,
|
|
@@ -101,7 +107,6 @@ function createReadableTimestampObject(pattern = exports.Format_HHmmss_DDMMYYYY,
|
|
|
101
107
|
timeObj.timezone = timezone;
|
|
102
108
|
return timeObj;
|
|
103
109
|
}
|
|
104
|
-
exports.createReadableTimestampObject = createReadableTimestampObject;
|
|
105
110
|
/**
|
|
106
111
|
* For detailed list of formats visit https://momentjs.com/docs/#/displaying/format/
|
|
107
112
|
*/
|
|
@@ -111,15 +116,12 @@ function formatTimestamp(pattern = exports.Format_HHmmss_DDMMYYYY, timestamp = c
|
|
|
111
116
|
m.utcOffset(-new Date().getTimezoneOffset());
|
|
112
117
|
return m.format(pattern);
|
|
113
118
|
}
|
|
114
|
-
exports.formatTimestamp = formatTimestamp;
|
|
115
119
|
function parseTimeString(timestamp, pattern = exports.Format_HHmmss_DDMMYYYY) {
|
|
116
120
|
return (0, moment_2.utc)(timestamp, pattern).valueOf();
|
|
117
121
|
}
|
|
118
|
-
exports.parseTimeString = parseTimeString;
|
|
119
122
|
function normalizeTimestamp(timestamp, pattern) {
|
|
120
123
|
return parseTimeString(formatTimestamp(pattern, timestamp), pattern);
|
|
121
124
|
}
|
|
122
|
-
exports.normalizeTimestamp = normalizeTimestamp;
|
|
123
125
|
const DateTimeFormat = (format) => {
|
|
124
126
|
return {
|
|
125
127
|
parse: (timestampAsString) => parseTimeString(timestampAsString, format),
|
|
@@ -133,7 +135,6 @@ exports.DateTimeFormat_DDMMYYYY = (0, exports.DateTimeFormat)('DD/MM/YYYY');
|
|
|
133
135
|
function isSameDay(date1, date2) {
|
|
134
136
|
return (0, moment_1.default)(date1).isSame(date2, 'day');
|
|
135
137
|
}
|
|
136
|
-
exports.isSameDay = isSameDay;
|
|
137
138
|
function deltaDays(d1, d2) {
|
|
138
139
|
const date1 = typeof d1 === 'number' ? new Date(d1) : d1;
|
|
139
140
|
const date2 = typeof d2 === 'number' ? new Date(d2) : d2;
|
|
@@ -148,4 +149,3 @@ function deltaDays(d1, d2) {
|
|
|
148
149
|
const date2Offset = new Date(date2.getTime() + (days * exports.Day));
|
|
149
150
|
return isSameDay(date1, date2Offset) ? days : days + 1;
|
|
150
151
|
}
|
|
151
|
-
exports.deltaDays = deltaDays;
|
package/utils/db-object-tools.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.KeysOfDB_Object = void 0;
|
|
4
|
+
exports.dbObjectToId = dbObjectToId;
|
|
5
|
+
exports.removeDBObjectKeys = removeDBObjectKeys;
|
|
6
|
+
exports.deleteKeysObject = deleteKeysObject;
|
|
7
|
+
exports.keepDBObjectKeys = keepDBObjectKeys;
|
|
8
|
+
exports.keepPartialObject = keepPartialObject;
|
|
4
9
|
const object_tools_1 = require("./object-tools");
|
|
5
10
|
const tools_1 = require("./tools");
|
|
6
11
|
exports.KeysOfDB_Object = ['_id', '_v', '__created', '__updated', '__metadata1'];
|
|
7
12
|
function dbObjectToId(i) {
|
|
8
13
|
return i._id;
|
|
9
14
|
}
|
|
10
|
-
exports.dbObjectToId = dbObjectToId;
|
|
11
15
|
function removeDBObjectKeys(instance) {
|
|
12
16
|
return deleteKeysObject(instance, exports.KeysOfDB_Object);
|
|
13
17
|
}
|
|
14
|
-
exports.removeDBObjectKeys = removeDBObjectKeys;
|
|
15
18
|
/**
|
|
16
19
|
* Returns a cloned object with the keys removed.
|
|
17
20
|
*/
|
|
@@ -20,11 +23,9 @@ function deleteKeysObject(instance, keysToRemove) {
|
|
|
20
23
|
keysToRemove.forEach(key => delete _instance[key]);
|
|
21
24
|
return _instance;
|
|
22
25
|
}
|
|
23
|
-
exports.deleteKeysObject = deleteKeysObject;
|
|
24
26
|
function keepDBObjectKeys(instance) {
|
|
25
27
|
return keepPartialObject(instance, exports.KeysOfDB_Object);
|
|
26
28
|
}
|
|
27
|
-
exports.keepDBObjectKeys = keepDBObjectKeys;
|
|
28
29
|
function keepPartialObject(instance, keys) {
|
|
29
30
|
return keys.reduce((objectToRet, key) => {
|
|
30
31
|
if ((0, tools_1.exists)(instance[key]))
|
|
@@ -32,4 +33,3 @@ function keepPartialObject(instance, keys) {
|
|
|
32
33
|
return objectToRet;
|
|
33
34
|
}, {});
|
|
34
35
|
}
|
|
35
|
-
exports.keepPartialObject = keepPartialObject;
|
package/utils/exception-tools.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isCustomException =
|
|
3
|
+
exports.isCustomException = isCustomException;
|
|
4
4
|
const exceptions_1 = require("../core/exceptions/exceptions");
|
|
5
5
|
const allExceptions = [
|
|
6
6
|
exceptions_1.Exception,
|
|
@@ -16,4 +16,3 @@ const allExceptions = [
|
|
|
16
16
|
function isCustomException(e) {
|
|
17
17
|
return allExceptions.some(exc => !!(0, exceptions_1.isErrorOfType)(e, exc));
|
|
18
18
|
}
|
|
19
|
-
exports.isCustomException = isCustomException;
|
package/utils/filter-tools.js
CHANGED
|
@@ -195,6 +195,7 @@ class Filter {
|
|
|
195
195
|
return this;
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
|
+
exports.Filter = Filter;
|
|
198
199
|
Filter.translateStringToRegexFilter = (filter, regexp) => {
|
|
199
200
|
filter = (filter || '').trim();
|
|
200
201
|
filter = filter.toLowerCase();
|
|
@@ -208,4 +209,3 @@ Filter.translateStringToRegexFilter = (filter, regexp) => {
|
|
|
208
209
|
filter.length === 0 ? filter = '.*?' : filter += '.*';
|
|
209
210
|
return new RegExp(filter);
|
|
210
211
|
};
|
|
211
|
-
exports.Filter = Filter;
|
package/utils/hash-tools.d.ts
CHANGED
package/utils/hash-tools.js
CHANGED
|
@@ -17,28 +17,29 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.
|
|
20
|
+
exports.md5 = md5;
|
|
21
|
+
exports.sha1 = sha1;
|
|
22
|
+
exports.sha256 = sha256;
|
|
23
|
+
exports.sha384 = sha384;
|
|
24
|
+
exports.sha512 = sha512;
|
|
25
|
+
exports.encode = encode;
|
|
26
|
+
exports.decode = decode;
|
|
21
27
|
const node_forge_1 = require("node-forge");
|
|
22
28
|
function md5(toBeConverted) {
|
|
23
29
|
return node_forge_1.md.md5.create().update(toBeConverted).digest().toHex().toLowerCase();
|
|
24
30
|
}
|
|
25
|
-
exports.md5 = md5;
|
|
26
31
|
function sha1(toBeConverted) {
|
|
27
32
|
return node_forge_1.md.sha1.create().update(toBeConverted).digest().toHex().toLowerCase();
|
|
28
33
|
}
|
|
29
|
-
exports.sha1 = sha1;
|
|
30
34
|
function sha256(toBeConverted) {
|
|
31
35
|
return node_forge_1.md.sha256.create().update(toBeConverted).digest().toHex().toLowerCase();
|
|
32
36
|
}
|
|
33
|
-
exports.sha256 = sha256;
|
|
34
37
|
function sha384(toBeConverted) {
|
|
35
38
|
return node_forge_1.md.sha384.create().update(toBeConverted).digest().toHex().toLowerCase();
|
|
36
39
|
}
|
|
37
|
-
exports.sha384 = sha384;
|
|
38
40
|
function sha512(toBeConverted) {
|
|
39
41
|
return node_forge_1.md.sha512.create().update(toBeConverted).digest().toHex().toLowerCase();
|
|
40
42
|
}
|
|
41
|
-
exports.sha512 = sha512;
|
|
42
43
|
function encode(data, encoding = "base64") {
|
|
43
44
|
let buffer;
|
|
44
45
|
if (Buffer.isBuffer(data))
|
|
@@ -49,8 +50,6 @@ function encode(data, encoding = "base64") {
|
|
|
49
50
|
buffer = Buffer.from(data.toString(), 'utf8');
|
|
50
51
|
return buffer.toString(encoding);
|
|
51
52
|
}
|
|
52
|
-
exports.encode = encode;
|
|
53
53
|
function decode(encoded, from = "base64", to = "utf8") {
|
|
54
54
|
return Buffer.from(encoded, from).toString(to);
|
|
55
55
|
}
|
|
56
|
-
exports.decode = decode;
|
package/utils/json-tools.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isValidJson = isValidJson;
|
|
4
|
+
exports.prettifyJson = prettifyJson;
|
|
4
5
|
const tools_1 = require("./tools");
|
|
5
6
|
function isValidJson(_string) {
|
|
6
7
|
try {
|
|
@@ -11,8 +12,6 @@ function isValidJson(_string) {
|
|
|
11
12
|
return false;
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
|
-
exports.isValidJson = isValidJson;
|
|
15
15
|
function prettifyJson(obj) {
|
|
16
16
|
return (0, tools_1.__stringify)(obj, true);
|
|
17
17
|
}
|
|
18
|
-
exports.prettifyJson = prettifyJson;
|
package/utils/merge-tools.js
CHANGED
|
@@ -17,7 +17,9 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.
|
|
20
|
+
exports.mergeObject = mergeObject;
|
|
21
|
+
exports.mergeArray = mergeArray;
|
|
22
|
+
exports.merge = merge;
|
|
21
23
|
const object_tools_1 = require("./object-tools");
|
|
22
24
|
const tools_1 = require("./tools");
|
|
23
25
|
const exceptions_1 = require("../core/exceptions/exceptions");
|
|
@@ -35,7 +37,6 @@ function mergeObject(original, override) {
|
|
|
35
37
|
return obj;
|
|
36
38
|
}, returnValue);
|
|
37
39
|
}
|
|
38
|
-
exports.mergeObject = mergeObject;
|
|
39
40
|
function mergeArray(original, override) {
|
|
40
41
|
if (original === override) {
|
|
41
42
|
return override;
|
|
@@ -57,7 +58,6 @@ function mergeArray(original, override) {
|
|
|
57
58
|
// });
|
|
58
59
|
return override;
|
|
59
60
|
}
|
|
60
|
-
exports.mergeArray = mergeArray;
|
|
61
61
|
function merge(original, override) {
|
|
62
62
|
if (!(0, tools_1.exists)(override))
|
|
63
63
|
return undefined;
|
|
@@ -71,4 +71,3 @@ function merge(original, override) {
|
|
|
71
71
|
return mergeObject(original || {}, override);
|
|
72
72
|
return override;
|
|
73
73
|
}
|
|
74
|
-
exports.merge = merge;
|
package/utils/object-tools.js
CHANGED
|
@@ -17,7 +17,17 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.
|
|
20
|
+
exports.getDotNotatedValue = getDotNotatedValue;
|
|
21
|
+
exports.deepClone = deepClone;
|
|
22
|
+
exports._keys = _keys;
|
|
23
|
+
exports._values = _values;
|
|
24
|
+
exports._setTypedProp = _setTypedProp;
|
|
25
|
+
exports.cloneArr = cloneArr;
|
|
26
|
+
exports.cloneObj = cloneObj;
|
|
27
|
+
exports.partialCompare = partialCompare;
|
|
28
|
+
exports.compare = compare;
|
|
29
|
+
exports.assert = assert;
|
|
30
|
+
exports.filterKeys = filterKeys;
|
|
21
31
|
const exceptions_1 = require("../core/exceptions/exceptions");
|
|
22
32
|
const array_tools_1 = require("./array-tools");
|
|
23
33
|
function getDotNotatedValue(key, dotNotatedObject) {
|
|
@@ -26,7 +36,6 @@ function getDotNotatedValue(key, dotNotatedObject) {
|
|
|
26
36
|
return value[_pathPart];
|
|
27
37
|
}, dotNotatedObject);
|
|
28
38
|
}
|
|
29
|
-
exports.getDotNotatedValue = getDotNotatedValue;
|
|
30
39
|
function deepClone(obj) {
|
|
31
40
|
if (typeof obj === 'string' || typeof obj === 'number' || typeof obj === 'boolean' || typeof obj === 'undefined' || obj === null)
|
|
32
41
|
return obj;
|
|
@@ -34,30 +43,24 @@ function deepClone(obj) {
|
|
|
34
43
|
return cloneArr(obj);
|
|
35
44
|
return cloneObj(obj);
|
|
36
45
|
}
|
|
37
|
-
exports.deepClone = deepClone;
|
|
38
46
|
function _keys(instance) {
|
|
39
47
|
return Object.keys(instance);
|
|
40
48
|
}
|
|
41
|
-
exports._keys = _keys;
|
|
42
49
|
function _values(object) {
|
|
43
50
|
return Object.values(object);
|
|
44
51
|
}
|
|
45
|
-
exports._values = _values;
|
|
46
52
|
function _setTypedProp(instance, key, value) {
|
|
47
53
|
instance[key] = value;
|
|
48
54
|
}
|
|
49
|
-
exports._setTypedProp = _setTypedProp;
|
|
50
55
|
function cloneArr(value) {
|
|
51
56
|
return value.map(a => deepClone(a));
|
|
52
57
|
}
|
|
53
|
-
exports.cloneArr = cloneArr;
|
|
54
58
|
function cloneObj(obj) {
|
|
55
59
|
return _keys(obj).reduce((carry, key) => {
|
|
56
60
|
carry[key] = deepClone(obj[key]);
|
|
57
61
|
return carry;
|
|
58
62
|
}, {});
|
|
59
63
|
}
|
|
60
|
-
exports.cloneObj = cloneObj;
|
|
61
64
|
function partialCompare(one, two, keysToFilterOut) {
|
|
62
65
|
one = deepClone(one);
|
|
63
66
|
two = deepClone(two);
|
|
@@ -67,7 +70,6 @@ function partialCompare(one, two, keysToFilterOut) {
|
|
|
67
70
|
});
|
|
68
71
|
return compare(one, two);
|
|
69
72
|
}
|
|
70
|
-
exports.partialCompare = partialCompare;
|
|
71
73
|
/**
|
|
72
74
|
* Returns true for equal.
|
|
73
75
|
*/
|
|
@@ -115,12 +117,10 @@ function compare(one, two, keys) {
|
|
|
115
117
|
}
|
|
116
118
|
return true;
|
|
117
119
|
}
|
|
118
|
-
exports.compare = compare;
|
|
119
120
|
function assert(message, expected, actual) {
|
|
120
121
|
if (!compare(expected, actual))
|
|
121
122
|
throw new exceptions_1.AssertionException(`Assertion Failed:\n -- ${message}\n -- Expected: ${JSON.stringify(expected)}\n -- Actual: ${JSON.stringify(actual)}\n\n`);
|
|
122
123
|
}
|
|
123
|
-
exports.assert = assert;
|
|
124
124
|
function filterKeys(obj, keys = _keys(obj), filter = (k) => obj[k] === undefined || obj[k] === null) {
|
|
125
125
|
if (typeof obj !== 'object' || obj === null) {
|
|
126
126
|
throw new exceptions_1.BadImplementationException('Passed parameter for "obj" must be an object');
|
|
@@ -131,4 +131,3 @@ function filterKeys(obj, keys = _keys(obj), filter = (k) => obj[k] === undefined
|
|
|
131
131
|
});
|
|
132
132
|
return obj;
|
|
133
133
|
}
|
|
134
|
-
exports.filterKeys = filterKeys;
|
package/utils/query-params.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.composeQueryParams = composeQueryParams;
|
|
4
|
+
exports.composeUrl = composeUrl;
|
|
4
5
|
function composeQueryParams(params = {}) {
|
|
5
6
|
return Object.keys(params).map((paramKey) => {
|
|
6
7
|
let param = params[paramKey];
|
|
@@ -11,7 +12,6 @@ function composeQueryParams(params = {}) {
|
|
|
11
12
|
return `${paramKey}=${encodeURIComponent(param)}`;
|
|
12
13
|
}).join('&');
|
|
13
14
|
}
|
|
14
|
-
exports.composeQueryParams = composeQueryParams;
|
|
15
15
|
function composeUrl(url, params = {}, hash = '') {
|
|
16
16
|
const queryAsEncodedString = composeQueryParams(params);
|
|
17
17
|
if (queryAsEncodedString.length)
|
|
@@ -20,4 +20,3 @@ function composeUrl(url, params = {}, hash = '') {
|
|
|
20
20
|
return `${url}${hash.startsWith('#') ? hash : `#${hash}`}`;
|
|
21
21
|
return url;
|
|
22
22
|
}
|
|
23
|
-
exports.composeUrl = composeUrl;
|
package/utils/random-tools.js
CHANGED
|
@@ -17,21 +17,21 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.
|
|
20
|
+
exports.generateHex = generateHex;
|
|
21
|
+
exports.generateUUID = generateUUID;
|
|
22
|
+
exports.generateShortURL = generateShortURL;
|
|
21
23
|
const crypto_1 = require("crypto");
|
|
22
24
|
function generateHex(length) {
|
|
23
25
|
return (0, crypto_1.randomBytes)(Math.ceil(length / 2))
|
|
24
26
|
.toString('hex')
|
|
25
27
|
.slice(0, length).toLowerCase();
|
|
26
28
|
}
|
|
27
|
-
exports.generateHex = generateHex;
|
|
28
29
|
function generateUUID() {
|
|
29
30
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
30
31
|
const r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
31
32
|
return v.toString(16);
|
|
32
33
|
});
|
|
33
34
|
}
|
|
34
|
-
exports.generateUUID = generateUUID;
|
|
35
35
|
/**
|
|
36
36
|
* generate 8 characters long string that is value for short url usage
|
|
37
37
|
*/
|
|
@@ -45,4 +45,3 @@ function generateShortURL() {
|
|
|
45
45
|
}
|
|
46
46
|
return result;
|
|
47
47
|
}
|
|
48
|
-
exports.generateShortURL = generateShortURL;
|
package/utils/string-tools.js
CHANGED
|
@@ -17,12 +17,23 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.
|
|
20
|
+
exports.padNumber = padNumber;
|
|
21
|
+
exports.stringToHashCode = stringToHashCode;
|
|
22
|
+
exports.escape_RegExp = escape_RegExp;
|
|
23
|
+
exports.maxSubstring = maxSubstring;
|
|
24
|
+
exports.getStringSize = getStringSize;
|
|
25
|
+
exports.stringFormat = stringFormat;
|
|
26
|
+
exports.replaceStringAt = replaceStringAt;
|
|
27
|
+
exports.capitalizeAllFirstLetters = capitalizeAllFirstLetters;
|
|
28
|
+
exports.capitalizeFirstLetter = capitalizeFirstLetter;
|
|
29
|
+
exports.createLevenshteinDistanceMatrix = createLevenshteinDistanceMatrix;
|
|
30
|
+
exports.levenshteinDistance = levenshteinDistance;
|
|
31
|
+
exports.normalizeString = normalizeString;
|
|
32
|
+
exports.convertUpperCamelCase = convertUpperCamelCase;
|
|
21
33
|
function padNumber(num, length) {
|
|
22
34
|
const _num = num.toString();
|
|
23
35
|
return _num.length < length ? padNumber('0' + _num, length) : _num;
|
|
24
36
|
}
|
|
25
|
-
exports.padNumber = padNumber;
|
|
26
37
|
function stringToHashCode(stringToHash) {
|
|
27
38
|
let hash = 0;
|
|
28
39
|
if (stringToHash.length === 0)
|
|
@@ -33,11 +44,9 @@ function stringToHashCode(stringToHash) {
|
|
|
33
44
|
}
|
|
34
45
|
return hash;
|
|
35
46
|
}
|
|
36
|
-
exports.stringToHashCode = stringToHashCode;
|
|
37
47
|
function escape_RegExp(string) {
|
|
38
48
|
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
|
|
39
49
|
}
|
|
40
|
-
exports.escape_RegExp = escape_RegExp;
|
|
41
50
|
function maxSubstring(string, maxBytes, direction = 'start') {
|
|
42
51
|
const encoder = new TextEncoder();
|
|
43
52
|
const decoder = new TextDecoder();
|
|
@@ -54,7 +63,6 @@ function maxSubstring(string, maxBytes, direction = 'start') {
|
|
|
54
63
|
}
|
|
55
64
|
return decoder.decode(slicedBytes);
|
|
56
65
|
}
|
|
57
|
-
exports.maxSubstring = maxSubstring;
|
|
58
66
|
/**
|
|
59
67
|
* Calculate the size of a string in the specified unit.
|
|
60
68
|
* @param str - The input string whose size is to be calculated.
|
|
@@ -77,19 +85,16 @@ function getStringSize(str, unit = 'KB') {
|
|
|
77
85
|
throw new Error('Invalid unit. Please specify "KB", "MB", or "GB".');
|
|
78
86
|
}
|
|
79
87
|
}
|
|
80
|
-
exports.getStringSize = getStringSize;
|
|
81
88
|
function stringFormat(input, params = []) {
|
|
82
89
|
return (params === null || params === void 0 ? void 0 : params.reduce((toRet, param, index) => {
|
|
83
90
|
return toRet.replace(new RegExp(`\\{${index}\\}`, 'g'), param);
|
|
84
91
|
}, input || '')) || input;
|
|
85
92
|
}
|
|
86
|
-
exports.stringFormat = stringFormat;
|
|
87
93
|
function replaceStringAt(origin, index, replacement) {
|
|
88
94
|
if (!(origin === null || origin === void 0 ? void 0 : origin.length) || !(replacement === null || replacement === void 0 ? void 0 : replacement.length))
|
|
89
95
|
return origin;
|
|
90
96
|
return origin.substring(0, index) + replacement + origin.substring(index + replacement.length);
|
|
91
97
|
}
|
|
92
|
-
exports.replaceStringAt = replaceStringAt;
|
|
93
98
|
function capitalizeAllFirstLetters(value) {
|
|
94
99
|
let resultString = value;
|
|
95
100
|
for (let i = 0; i < resultString.length; i++) {
|
|
@@ -98,11 +103,9 @@ function capitalizeAllFirstLetters(value) {
|
|
|
98
103
|
}
|
|
99
104
|
return resultString;
|
|
100
105
|
}
|
|
101
|
-
exports.capitalizeAllFirstLetters = capitalizeAllFirstLetters;
|
|
102
106
|
function capitalizeFirstLetter(value) {
|
|
103
107
|
return value.charAt(0).toUpperCase() + value.substr(1).toLowerCase();
|
|
104
108
|
}
|
|
105
|
-
exports.capitalizeFirstLetter = capitalizeFirstLetter;
|
|
106
109
|
function createLevenshteinDistanceMatrix(str1, str2) {
|
|
107
110
|
const len1 = str1.length;
|
|
108
111
|
const len2 = str2.length;
|
|
@@ -119,7 +122,6 @@ function createLevenshteinDistanceMatrix(str1, str2) {
|
|
|
119
122
|
matrix[i][j] = Math.min((matrix[i - 1][j]) + 1, (matrix[i][j - 1]) + 1, (matrix[i - 1][j - 1]) + (str1[i - 1] === str2[j - 1] ? 0 : 1));
|
|
120
123
|
return matrix;
|
|
121
124
|
}
|
|
122
|
-
exports.createLevenshteinDistanceMatrix = createLevenshteinDistanceMatrix;
|
|
123
125
|
function levenshteinDistance(str1, str2) {
|
|
124
126
|
//Quick exists
|
|
125
127
|
if (str1.length === 0)
|
|
@@ -131,12 +133,9 @@ function levenshteinDistance(str1, str2) {
|
|
|
131
133
|
//Distance between the strings should be at bottom right corner of the matrix
|
|
132
134
|
return matrix[str1.length][str2.length];
|
|
133
135
|
}
|
|
134
|
-
exports.levenshteinDistance = levenshteinDistance;
|
|
135
136
|
function normalizeString(string) {
|
|
136
137
|
return string.replace(/–/g, '-').replace(/\n/g, '').replace(/\s+/g, ' ').replace(/’/g, '\'').trim();
|
|
137
138
|
}
|
|
138
|
-
exports.normalizeString = normalizeString;
|
|
139
139
|
function convertUpperCamelCase(upperCamelCase, delimiter = ' ') {
|
|
140
140
|
return upperCamelCase.replace(/([a-z0-9])([A-Z])/g, `$1${delimiter}$2`);
|
|
141
141
|
}
|
|
142
|
-
exports.convertUpperCamelCase = convertUpperCamelCase;
|
package/utils/tools.js
CHANGED
|
@@ -17,12 +17,17 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.logicalXOR = exports.
|
|
20
|
+
exports.logicalXOR = exports.resolveFunctionOrValue = exports.resolveContent = exports.functionThatReturnsTrue = exports.functionThatReturnsFalse = exports.voidFunction = exports.EmptyArray = exports.EmptyObject = void 0;
|
|
21
|
+
exports.regexpCase = regexpCase;
|
|
22
|
+
exports.createFilterPattern = createFilterPattern;
|
|
23
|
+
exports.calculateJsonSizeMb = calculateJsonSizeMb;
|
|
24
|
+
exports.__stringify = __stringify;
|
|
25
|
+
exports.exists = exists;
|
|
26
|
+
exports.freeze = freeze;
|
|
21
27
|
const object_tools_1 = require("./object-tools");
|
|
22
28
|
function regexpCase(value, reg) {
|
|
23
29
|
return value.match(new RegExp(reg)) || { input: undefined };
|
|
24
30
|
}
|
|
25
|
-
exports.regexpCase = regexpCase;
|
|
26
31
|
function createFilterPattern(rawFilter) {
|
|
27
32
|
let filter = rawFilter || '';
|
|
28
33
|
filter = filter.trim();
|
|
@@ -31,12 +36,10 @@ function createFilterPattern(rawFilter) {
|
|
|
31
36
|
filter.length === 0 ? filter = '.*?' : filter += '.*';
|
|
32
37
|
return filter;
|
|
33
38
|
}
|
|
34
|
-
exports.createFilterPattern = createFilterPattern;
|
|
35
39
|
function calculateJsonSizeMb(data) {
|
|
36
40
|
const number = JSON.stringify(data).length / 1024 / 1024;
|
|
37
41
|
return Math.round(number * 100) / 100;
|
|
38
42
|
}
|
|
39
|
-
exports.calculateJsonSizeMb = calculateJsonSizeMb;
|
|
40
43
|
function __stringify(obj, pretty) {
|
|
41
44
|
if (!obj)
|
|
42
45
|
return '';
|
|
@@ -50,7 +53,6 @@ function __stringify(obj, pretty) {
|
|
|
50
53
|
return JSON.stringify(obj, null, 2);
|
|
51
54
|
return JSON.stringify(obj);
|
|
52
55
|
}
|
|
53
|
-
exports.__stringify = __stringify;
|
|
54
56
|
exports.EmptyObject = Object.freeze({});
|
|
55
57
|
exports.EmptyArray = Object.freeze([]);
|
|
56
58
|
exports.voidFunction = Object.freeze(async () => {
|
|
@@ -65,11 +67,9 @@ exports.resolveFunctionOrValue = exports.resolveContent;
|
|
|
65
67
|
function exists(item) {
|
|
66
68
|
return item !== undefined && item !== null;
|
|
67
69
|
}
|
|
68
|
-
exports.exists = exists;
|
|
69
70
|
function freeze(item) {
|
|
70
71
|
return Object.freeze(item);
|
|
71
72
|
}
|
|
72
|
-
exports.freeze = freeze;
|
|
73
73
|
const logicalXOR = (a, b) => {
|
|
74
74
|
return (a && !b) || (!a && b);
|
|
75
75
|
};
|
package/utils/version-tools.d.ts
CHANGED
|
@@ -8,3 +8,8 @@
|
|
|
8
8
|
* 1 if second is greater
|
|
9
9
|
*/
|
|
10
10
|
export declare function compareVersions(firstVersion: string, secondVersion: string): 0 | 1 | -1;
|
|
11
|
+
/**
|
|
12
|
+
* Expects a version of XXX.YYY.ZZZ and nothing else
|
|
13
|
+
* @param version
|
|
14
|
+
*/
|
|
15
|
+
export declare function validateVersion(version: string): string | undefined;
|
package/utils/version-tools.js
CHANGED
|
@@ -17,8 +17,11 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.compareVersions =
|
|
20
|
+
exports.compareVersions = compareVersions;
|
|
21
|
+
exports.validateVersion = validateVersion;
|
|
21
22
|
const exceptions_1 = require("../core/exceptions/exceptions");
|
|
23
|
+
const validator_core_1 = require("../validator/validator-core");
|
|
24
|
+
const validators_1 = require("../validator/validators");
|
|
22
25
|
/**
|
|
23
26
|
*
|
|
24
27
|
* @param firstVersion a version
|
|
@@ -30,11 +33,11 @@ const exceptions_1 = require("../core/exceptions/exceptions");
|
|
|
30
33
|
*/
|
|
31
34
|
function compareVersions(firstVersion, secondVersion) {
|
|
32
35
|
if (!firstVersion)
|
|
33
|
-
throw new exceptions_1.BadImplementationException(
|
|
36
|
+
throw new exceptions_1.BadImplementationException('First version is undefined');
|
|
34
37
|
if (!secondVersion)
|
|
35
|
-
throw new exceptions_1.BadImplementationException(
|
|
36
|
-
const firstVersionAsArray = firstVersion.split(
|
|
37
|
-
const secondVersionAsArray = secondVersion.split(
|
|
38
|
+
throw new exceptions_1.BadImplementationException('Second version is undefined');
|
|
39
|
+
const firstVersionAsArray = firstVersion.split('\.');
|
|
40
|
+
const secondVersionAsArray = secondVersion.split('\.');
|
|
38
41
|
for (let i = 0; i < firstVersionAsArray.length; i++) {
|
|
39
42
|
const secondVal = +secondVersionAsArray[i];
|
|
40
43
|
const firstVal = +firstVersionAsArray[i];
|
|
@@ -47,4 +50,10 @@ function compareVersions(firstVersion, secondVersion) {
|
|
|
47
50
|
}
|
|
48
51
|
return 0;
|
|
49
52
|
}
|
|
50
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Expects a version of XXX.YYY.ZZZ and nothing else
|
|
55
|
+
* @param version
|
|
56
|
+
*/
|
|
57
|
+
function validateVersion(version) {
|
|
58
|
+
return (0, validator_core_1.tsValidateResult)(version, validators_1.tsValidateVersion);
|
|
59
|
+
}
|