@nu-art/ts-common 0.105.0 → 0.105.1
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/consts/consts.d.ts +1 -0
- package/consts/consts.js +22 -0
- package/consts/consts.js.map +1 -0
- package/core/application.d.ts +5 -0
- package/core/application.js +55 -0
- package/core/application.js.map +1 -0
- package/core/debug-flags.d.ts +25 -0
- package/core/debug-flags.js +87 -0
- package/core/debug-flags.js.map +1 -0
- package/core/dispatcher.d.ts +18 -0
- package/core/dispatcher.js +132 -0
- package/core/dispatcher.js.map +1 -0
- package/core/error-handling.d.ts +14 -0
- package/core/error-handling.js +38 -0
- package/core/error-handling.js.map +1 -0
- package/core/exceptions.d.ts +118 -0
- package/core/exceptions.js +214 -0
- package/core/exceptions.js.map +1 -0
- package/core/logger/BeLogged.d.ts +14 -0
- package/core/logger/BeLogged.js +61 -0
- package/core/logger/BeLogged.js.map +1 -0
- package/core/logger/LogClient.d.ts +14 -0
- package/core/logger/LogClient.js +67 -0
- package/core/logger/LogClient.js.map +1 -0
- package/core/logger/LogClient_BaseRotate.d.ts +19 -0
- package/core/logger/LogClient_BaseRotate.js +80 -0
- package/core/logger/LogClient_BaseRotate.js.map +1 -0
- package/core/logger/LogClient_Browser.d.ts +9 -0
- package/core/logger/LogClient_Browser.js +101 -0
- package/core/logger/LogClient_Browser.js.map +1 -0
- package/core/logger/LogClient_Function.d.ts +8 -0
- package/core/logger/LogClient_Function.js +75 -0
- package/core/logger/LogClient_Function.js.map +1 -0
- package/core/logger/LogClient_MemBuffer.d.ts +9 -0
- package/core/logger/LogClient_MemBuffer.js +61 -0
- package/core/logger/LogClient_MemBuffer.js.map +1 -0
- package/core/logger/LogClient_Terminal.d.ts +9 -0
- package/core/logger/LogClient_Terminal.js +75 -0
- package/core/logger/LogClient_Terminal.js.map +1 -0
- package/core/logger/Logger.d.ts +38 -0
- package/core/logger/Logger.js +216 -0
- package/core/logger/Logger.js.map +1 -0
- package/core/logger/types.d.ts +10 -0
- package/core/logger/types.js +36 -0
- package/core/logger/types.js.map +1 -0
- package/core/logger/utils.d.ts +5 -0
- package/core/logger/utils.js +80 -0
- package/core/logger/utils.js.map +1 -0
- package/core/module-manager.d.ts +18 -0
- package/core/module-manager.js +112 -0
- package/core/module-manager.js.map +1 -0
- package/core/module.d.ts +32 -0
- package/core/module.js +126 -0
- package/core/module.js.map +1 -0
- package/csv.d.ts +1 -0
- package/csv.js +35 -0
- package/csv.js.map +1 -0
- package/index.d.ts +43 -0
- package/index.js +77 -0
- package/index.js.map +1 -0
- package/modules/CSVModule.d.ts +32 -0
- package/modules/CSVModule.js +165 -0
- package/modules/CSVModule.js.map +1 -0
- package/modules/CliParamsModule.d.ts +27 -0
- package/modules/CliParamsModule.js +94 -0
- package/modules/CliParamsModule.js.map +1 -0
- package/modules/csv-serializer.d.ts +11 -0
- package/modules/csv-serializer.js +50 -0
- package/modules/csv-serializer.js.map +1 -0
- package/package.json +3 -6
- package/permissions/permission-group.d.ts +8 -0
- package/permissions/permission-group.js +37 -0
- package/permissions/permission-group.js.map +1 -0
- package/test-index.d.ts +2 -0
- package/test-index.js +19 -0
- package/test-index.js.map +1 -0
- package/testing/consts.d.ts +5 -0
- package/testing/consts.js +74 -0
- package/testing/consts.js.map +1 -0
- package/testing/types.d.ts +16 -0
- package/testing/types.js +20 -0
- package/testing/types.js.map +1 -0
- package/tools/Replacer.d.ts +24 -0
- package/tools/Replacer.js +172 -0
- package/tools/Replacer.js.map +1 -0
- package/tools/get-log-style.d.ts +14 -0
- package/tools/get-log-style.js +43 -0
- package/tools/get-log-style.js.map +1 -0
- package/utils/array-tools.d.ts +85 -0
- package/utils/array-tools.js +302 -0
- package/utils/array-tools.js.map +1 -0
- package/utils/crypto-tools.d.ts +4 -0
- package/utils/crypto-tools.js +36 -0
- package/utils/crypto-tools.js.map +1 -0
- package/utils/date-time-tools.d.ts +28 -0
- package/utils/date-time-tools.js +180 -0
- package/utils/date-time-tools.js.map +1 -0
- package/utils/db-object-tools.d.ts +3 -0
- package/utils/db-object-tools.js +9 -0
- package/utils/db-object-tools.js.map +1 -0
- package/utils/filter-tools.d.ts +137 -0
- package/utils/filter-tools.js +217 -0
- package/utils/filter-tools.js.map +1 -0
- package/utils/hash-tools.d.ts +8 -0
- package/utils/hash-tools.js +60 -0
- package/utils/hash-tools.js.map +1 -0
- package/utils/merge-tools.d.ts +3 -0
- package/utils/merge-tools.js +71 -0
- package/utils/merge-tools.js.map +1 -0
- package/utils/mimetype-tools.d.ts +8 -0
- package/utils/mimetype-tools.js +29 -0
- package/utils/mimetype-tools.js.map +1 -0
- package/utils/number-tools.d.ts +1 -0
- package/utils/number-tools.js +26 -0
- package/utils/number-tools.js.map +1 -0
- package/utils/object-tools.d.ts +13 -0
- package/utils/object-tools.js +129 -0
- package/utils/object-tools.js.map +1 -0
- package/utils/query-params.d.ts +5 -0
- package/utils/query-params.js +24 -0
- package/utils/query-params.js.map +1 -0
- package/utils/queue.d.ts +16 -0
- package/utils/queue.js +166 -0
- package/utils/queue.js.map +1 -0
- package/utils/random-tools.d.ts +2 -0
- package/utils/random-tools.js +35 -0
- package/utils/random-tools.js.map +1 -0
- package/utils/storage-capacity-tools.d.ts +6 -0
- package/utils/storage-capacity-tools.js +27 -0
- package/utils/storage-capacity-tools.js.map +1 -0
- package/utils/string-tools.d.ts +10 -0
- package/utils/string-tools.js +100 -0
- package/utils/string-tools.js.map +1 -0
- package/utils/tools.d.ts +13 -0
- package/utils/tools.js +103 -0
- package/utils/tools.js.map +1 -0
- package/utils/types.d.ts +92 -0
- package/utils/types.js +23 -0
- package/utils/types.js.map +1 -0
- package/utils/version-tools.d.ts +10 -0
- package/utils/version-tools.js +51 -0
- package/utils/version-tools.js.map +1 -0
- package/validator/type-validators.d.ts +29 -0
- package/validator/type-validators.js +211 -0
- package/validator/type-validators.js.map +1 -0
- package/validator/validator-core.d.ts +36 -0
- package/validator/validator-core.js +144 -0
- package/validator/validator-core.js.map +1 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* ts-common is the basic building blocks of our typescript projects
|
|
4
|
+
*
|
|
5
|
+
* Copyright (C) 2020 Adam van der Kruk aka TacB0sS
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.hashPasswordWithSalt = exports.randomObject = exports.randomNumber = void 0;
|
|
21
|
+
var crypto_1 = require("crypto");
|
|
22
|
+
function randomNumber(range) {
|
|
23
|
+
return Math.floor(Math.random() * (range));
|
|
24
|
+
}
|
|
25
|
+
exports.randomNumber = randomNumber;
|
|
26
|
+
function randomObject(items) {
|
|
27
|
+
return items[randomNumber(items.length)];
|
|
28
|
+
}
|
|
29
|
+
exports.randomObject = randomObject;
|
|
30
|
+
function hashPasswordWithSalt(salt, password) {
|
|
31
|
+
return (0, crypto_1.createHmac)('sha512', salt)
|
|
32
|
+
.update(password)
|
|
33
|
+
.digest('hex');
|
|
34
|
+
}
|
|
35
|
+
exports.hashPasswordWithSalt = hashPasswordWithSalt;
|
|
36
|
+
//# sourceMappingURL=crypto-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto-tools.js","sourceRoot":"","sources":["../../src/main/utils/crypto-tools.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;AAEH,iCAAkC;AAElC,SAAgB,YAAY,CAAC,KAAa;IACzC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAA;AAC3C,CAAC;AAFD,oCAEC;AAED,SAAgB,YAAY,CAAI,KAAU;IACzC,OAAO,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;AAC1C,CAAC;AAFD,oCAEC;AAED,SAAgB,oBAAoB,CAAC,IAAqB,EAAE,QAAyB;IACpF,OAAO,IAAA,mBAAU,EAAC,QAAQ,EAAE,IAAI,CAAC;SAC/B,MAAM,CAAC,QAAQ,CAAC;SAChB,MAAM,CAAC,KAAK,CAAC,CAAC;AACjB,CAAC;AAJD,oDAIC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AuditBy, Timestamp } from './types';
|
|
2
|
+
export declare const Second = 1000;
|
|
3
|
+
export declare const Minute: number;
|
|
4
|
+
export declare const Hour: number;
|
|
5
|
+
export declare const Day: number;
|
|
6
|
+
export declare const Week: number;
|
|
7
|
+
export declare const Format_HHmmss_DDMMYYYY = "HH:mm:ss_DD-MM-YYYY";
|
|
8
|
+
export declare const Format_YYYYMMDD_HHmmss = "YYYY-MM-DD_HH:mm:ss";
|
|
9
|
+
export type Weekday = 'Sunday' | 'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday';
|
|
10
|
+
export declare const Weekdays: Weekday[];
|
|
11
|
+
export type TimerHandler = (...args: any[]) => void;
|
|
12
|
+
export declare function timeout(sleepMs: number): Promise<unknown>;
|
|
13
|
+
export declare function _setTimeout(handler: TimerHandler, sleepMs?: number, ...args: any[]): number;
|
|
14
|
+
export declare function _clearTimeout(handlerId?: number): void;
|
|
15
|
+
export declare function _setInterval(handler: TimerHandler, sleepMs?: number, ...args: any[]): number;
|
|
16
|
+
export declare function _clearInterval(handlerId?: number): void;
|
|
17
|
+
export declare function auditBy(user: string, comment?: string, timestamp?: number): AuditBy;
|
|
18
|
+
export declare function currentTimeMillis(): number;
|
|
19
|
+
export declare function specificTimeTodayMillis(hours: number, minutes: number): number;
|
|
20
|
+
export declare function currentLocalTimeMillis(): number;
|
|
21
|
+
export declare function currentTimeMillisWithTimeZone(): number;
|
|
22
|
+
export declare function createReadableTimestampObject(pattern?: string, timestamp?: number, timezone?: string): Timestamp;
|
|
23
|
+
/**
|
|
24
|
+
* For detailed list of formats visit https://momentjs.com/docs/#/displaying/format/
|
|
25
|
+
*/
|
|
26
|
+
export declare function formatTimestamp(pattern?: string, timestamp?: number, timezone?: string): string;
|
|
27
|
+
export declare function parseTimeString(timestamp: string, pattern?: string): number;
|
|
28
|
+
export declare function normalizeTimestamp(timestamp: number, pattern: string): number;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* ts-common is the basic building blocks of our typescript projects
|
|
4
|
+
*
|
|
5
|
+
* Copyright (C) 2020 Adam van der Kruk aka TacB0sS
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
20
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
21
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
22
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
23
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
24
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
25
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
29
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
30
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
31
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
32
|
+
function step(op) {
|
|
33
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
34
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
35
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
36
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
37
|
+
switch (op[0]) {
|
|
38
|
+
case 0: case 1: t = op; break;
|
|
39
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
40
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
41
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
42
|
+
default:
|
|
43
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
44
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
45
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
46
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
47
|
+
if (t[2]) _.ops.pop();
|
|
48
|
+
_.trys.pop(); continue;
|
|
49
|
+
}
|
|
50
|
+
op = body.call(thisArg, _);
|
|
51
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
52
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
56
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
57
|
+
if (ar || !(i in from)) {
|
|
58
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
59
|
+
ar[i] = from[i];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
63
|
+
};
|
|
64
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
+
exports.normalizeTimestamp = exports.parseTimeString = exports.formatTimestamp = exports.createReadableTimestampObject = exports.currentTimeMillisWithTimeZone = exports.currentLocalTimeMillis = exports.specificTimeTodayMillis = exports.currentTimeMillis = exports.auditBy = exports._clearInterval = exports._setInterval = exports._clearTimeout = exports._setTimeout = exports.timeout = exports.Weekdays = exports.Format_YYYYMMDD_HHmmss = exports.Format_HHmmss_DDMMYYYY = exports.Week = exports.Day = exports.Hour = exports.Minute = exports.Second = void 0;
|
|
66
|
+
var moment = require("moment");
|
|
67
|
+
exports.Second = 1000;
|
|
68
|
+
exports.Minute = exports.Second * 60;
|
|
69
|
+
exports.Hour = exports.Minute * 60;
|
|
70
|
+
exports.Day = exports.Hour * 24;
|
|
71
|
+
exports.Week = exports.Day * 7;
|
|
72
|
+
exports.Format_HHmmss_DDMMYYYY = 'HH:mm:ss_DD-MM-YYYY';
|
|
73
|
+
exports.Format_YYYYMMDD_HHmmss = 'YYYY-MM-DD_HH:mm:ss';
|
|
74
|
+
exports.Weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
|
75
|
+
function timeout(sleepMs) {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
77
|
+
return __generator(this, function (_a) {
|
|
78
|
+
return [2 /*return*/, new Promise(function (resolve) { return setTimeout(resolve, sleepMs, undefined); })];
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
exports.timeout = timeout;
|
|
83
|
+
function _setTimeout(handler, sleepMs) {
|
|
84
|
+
if (sleepMs === void 0) { sleepMs = 0; }
|
|
85
|
+
var args = [];
|
|
86
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
87
|
+
args[_i - 2] = arguments[_i];
|
|
88
|
+
}
|
|
89
|
+
return setTimeout.apply(void 0, __spreadArray([handler, sleepMs], args, false));
|
|
90
|
+
}
|
|
91
|
+
exports._setTimeout = _setTimeout;
|
|
92
|
+
function _clearTimeout(handlerId) {
|
|
93
|
+
if (!handlerId)
|
|
94
|
+
return;
|
|
95
|
+
return clearTimeout(handlerId);
|
|
96
|
+
}
|
|
97
|
+
exports._clearTimeout = _clearTimeout;
|
|
98
|
+
function _setInterval(handler, sleepMs) {
|
|
99
|
+
if (sleepMs === void 0) { sleepMs = 0; }
|
|
100
|
+
var args = [];
|
|
101
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
102
|
+
args[_i - 2] = arguments[_i];
|
|
103
|
+
}
|
|
104
|
+
return setInterval.apply(void 0, __spreadArray([handler, sleepMs], args, false));
|
|
105
|
+
}
|
|
106
|
+
exports._setInterval = _setInterval;
|
|
107
|
+
function _clearInterval(handlerId) {
|
|
108
|
+
if (!handlerId)
|
|
109
|
+
return;
|
|
110
|
+
return clearInterval(handlerId);
|
|
111
|
+
}
|
|
112
|
+
exports._clearInterval = _clearInterval;
|
|
113
|
+
function auditBy(user, comment, timestamp) {
|
|
114
|
+
if (timestamp === void 0) { timestamp = currentTimeMillis(); }
|
|
115
|
+
var _auditBy = {
|
|
116
|
+
auditBy: user,
|
|
117
|
+
auditAt: createReadableTimestampObject(exports.Format_HHmmss_DDMMYYYY, timestamp)
|
|
118
|
+
};
|
|
119
|
+
if (comment)
|
|
120
|
+
_auditBy.comment = comment;
|
|
121
|
+
return _auditBy;
|
|
122
|
+
}
|
|
123
|
+
exports.auditBy = auditBy;
|
|
124
|
+
function currentTimeMillis() {
|
|
125
|
+
var date = new Date();
|
|
126
|
+
return date.getTime();
|
|
127
|
+
}
|
|
128
|
+
exports.currentTimeMillis = currentTimeMillis;
|
|
129
|
+
function specificTimeTodayMillis(hours, minutes) {
|
|
130
|
+
var date = new Date();
|
|
131
|
+
date.setHours(hours);
|
|
132
|
+
date.setMinutes(minutes);
|
|
133
|
+
return date.getTime();
|
|
134
|
+
}
|
|
135
|
+
exports.specificTimeTodayMillis = specificTimeTodayMillis;
|
|
136
|
+
function currentLocalTimeMillis() {
|
|
137
|
+
var date = new Date();
|
|
138
|
+
return date.getTime();
|
|
139
|
+
}
|
|
140
|
+
exports.currentLocalTimeMillis = currentLocalTimeMillis;
|
|
141
|
+
function currentTimeMillisWithTimeZone() {
|
|
142
|
+
var date = new Date();
|
|
143
|
+
return date.getTime() + date.getTimezoneOffset();
|
|
144
|
+
}
|
|
145
|
+
exports.currentTimeMillisWithTimeZone = currentTimeMillisWithTimeZone;
|
|
146
|
+
function createReadableTimestampObject(pattern, timestamp, timezone) {
|
|
147
|
+
if (pattern === void 0) { pattern = exports.Format_HHmmss_DDMMYYYY; }
|
|
148
|
+
if (timestamp === void 0) { timestamp = currentTimeMillis(); }
|
|
149
|
+
var timeObj = {
|
|
150
|
+
timestamp: timestamp,
|
|
151
|
+
pretty: formatTimestamp(pattern, timestamp)
|
|
152
|
+
};
|
|
153
|
+
if (timezone)
|
|
154
|
+
timeObj.timezone = timezone;
|
|
155
|
+
return timeObj;
|
|
156
|
+
}
|
|
157
|
+
exports.createReadableTimestampObject = createReadableTimestampObject;
|
|
158
|
+
/**
|
|
159
|
+
* For detailed list of formats visit https://momentjs.com/docs/#/displaying/format/
|
|
160
|
+
*/
|
|
161
|
+
function formatTimestamp(pattern, timestamp, timezone) {
|
|
162
|
+
if (pattern === void 0) { pattern = exports.Format_HHmmss_DDMMYYYY; }
|
|
163
|
+
if (timestamp === void 0) { timestamp = currentTimeMillis(); }
|
|
164
|
+
if (timezone === void 0) { timezone = Intl.DateTimeFormat()
|
|
165
|
+
.resolvedOptions().timeZone; }
|
|
166
|
+
var m = moment.utc(timestamp);
|
|
167
|
+
m.utcOffset(-new Date().getTimezoneOffset());
|
|
168
|
+
return m.format(pattern);
|
|
169
|
+
}
|
|
170
|
+
exports.formatTimestamp = formatTimestamp;
|
|
171
|
+
function parseTimeString(timestamp, pattern) {
|
|
172
|
+
if (pattern === void 0) { pattern = exports.Format_HHmmss_DDMMYYYY; }
|
|
173
|
+
return moment.utc(timestamp, pattern).valueOf();
|
|
174
|
+
}
|
|
175
|
+
exports.parseTimeString = parseTimeString;
|
|
176
|
+
function normalizeTimestamp(timestamp, pattern) {
|
|
177
|
+
return parseTimeString(formatTimestamp(pattern, timestamp), pattern);
|
|
178
|
+
}
|
|
179
|
+
exports.normalizeTimestamp = normalizeTimestamp;
|
|
180
|
+
//# sourceMappingURL=date-time-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-time-tools.js","sourceRoot":"","sources":["../../src/main/utils/date-time-tools.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,+BAAiC;AAIpB,QAAA,MAAM,GAAG,IAAI,CAAC;AACd,QAAA,MAAM,GAAG,cAAM,GAAG,EAAE,CAAC;AACrB,QAAA,IAAI,GAAG,cAAM,GAAG,EAAE,CAAC;AACnB,QAAA,GAAG,GAAG,YAAI,GAAG,EAAE,CAAC;AAChB,QAAA,IAAI,GAAG,WAAG,GAAG,CAAC,CA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AAC;IAE7B,OAAO,OAAO,CAAC;AAChB,CAAC;AAXD,sEAWC;AAED;;GAEG;AACH,SAAgB,eAAe,CAAC,OAAwC,EAAE,SAAuC,EAAE,QACvF;IADI,wBAAA,EAAA,UAAkB,8BAAsB;IAAE,0BAAA,EAAA,YAAoB,iBAAiB,EAAE;IAAE,yBAAA,EAAA,WAAmB,IAAI,CAAC,cAAc,EAAE;SACzJ,eAAe,EAAE,CAAC,QAAQ;IAC3B,IAAM,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAChC,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,iBAAiB,EAAE,CAAC,CAAC;IAC7C,OAAO,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AAC1B,CAAC;AALD,0CAKC;AAED,SAAgB,eAAe,CAAC,SAAiB,EAAE,OAAwC;IAAxC,wBAAA,EAAA,UAAkB,8BAAsB;IAC1F,OAAO,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC;AACjD,CAAC;AAFD,0CAEC;AAED,SAAgB,kBAAkB,CAAC,SAAiB,EAAE,OAAe;IACpE,OAAO,eAAe,CAAC,eAAe,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,OAAO,CAAC,CAAC;AACtE,CAAC;AAFD,gDAEC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dbObjectToId = exports.KeysOfDB_Object = void 0;
|
|
4
|
+
exports.KeysOfDB_Object = ['_id', '_v', '__created', '__updated'];
|
|
5
|
+
function dbObjectToId(i) {
|
|
6
|
+
return i._id;
|
|
7
|
+
}
|
|
8
|
+
exports.dbObjectToId = dbObjectToId;
|
|
9
|
+
//# sourceMappingURL=db-object-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db-object-tools.js","sourceRoot":"","sources":["../../src/main/utils/db-object-tools.ts"],"names":[],"mappings":";;;AAGa,QAAA,eAAe,GAAwB,CAAC,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;AAE5F,SAAgB,YAAY,CAAC,CAAY;IACxC,OAAO,CAAC,CAAC,GAAG,CAAC;AACd,CAAC;AAFD,oCAEC"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* # Filter
|
|
3
|
+
*
|
|
4
|
+
* ## <ins>Intro:</ins>
|
|
5
|
+
*
|
|
6
|
+
* A filter tool for filtering a collection or testing items by comparing string values</br>
|
|
7
|
+
* This tool aims to simplify filtering arrays of strings or objects containing string fields
|
|
8
|
+
* by defining which fields are tested (via a mapper function) testing those fields against a string
|
|
9
|
+
*
|
|
10
|
+
* ## <ins>Example data:</ins>
|
|
11
|
+
*
|
|
12
|
+
* type T in the following examples will be:
|
|
13
|
+
*
|
|
14
|
+
* ```js
|
|
15
|
+
* type T = {
|
|
16
|
+
* name: string;
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* items:
|
|
21
|
+
* ```js
|
|
22
|
+
* const item1: T = {name: 'Matan'};
|
|
23
|
+
* const item2: T = {name: 'Adam'};
|
|
24
|
+
* const item3: T = {name: 'Itay'};
|
|
25
|
+
* const items: T[] = [item1, item2, item3];
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare class Filter<T> {
|
|
29
|
+
private regexp;
|
|
30
|
+
private readonly mapper;
|
|
31
|
+
private originFilterText?;
|
|
32
|
+
private _filter;
|
|
33
|
+
static translateStringToRegexFilter: (filter: string, regexp: boolean) => RegExp;
|
|
34
|
+
/**
|
|
35
|
+
* Returns an instance of a filter, where the tested fields are the one provided by the mapper.
|
|
36
|
+
*
|
|
37
|
+
* @param mapper a function that returns a string array
|
|
38
|
+
*
|
|
39
|
+
* @return
|
|
40
|
+
*
|
|
41
|
+
* #### <ins>Usage:</ins>
|
|
42
|
+
* ```js
|
|
43
|
+
* //Prepares a filter instance where tests are run on the item.name
|
|
44
|
+
* const filter = new Filter<T>((item)=>[item.name]);
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
constructor(mapper: (item: T) => string[]);
|
|
48
|
+
/**
|
|
49
|
+
* A function to set the Filter.regexp boolean flag
|
|
50
|
+
*
|
|
51
|
+
* @param regexp
|
|
52
|
+
* </br>
|
|
53
|
+
* @returns - the Filter instance
|
|
54
|
+
* </br></br>
|
|
55
|
+
*
|
|
56
|
+
* #### <ins>Usage:</ins>
|
|
57
|
+
* ```js
|
|
58
|
+
* const filter = new Filter().setRegexp(false);
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
*/
|
|
62
|
+
setRegexp(regexp: boolean): this;
|
|
63
|
+
/**
|
|
64
|
+
* A function returning a boolean value for if the item passes the filter</br>
|
|
65
|
+
* The function checks the item fields (based on the mapper given when the Filter instance was created) against the filterText argument
|
|
66
|
+
*
|
|
67
|
+
* @param item The item to check
|
|
68
|
+
* @param filterText A string to filter by
|
|
69
|
+
*
|
|
70
|
+
* @return
|
|
71
|
+
*
|
|
72
|
+
* </br>
|
|
73
|
+
*
|
|
74
|
+
* #### <ins>Usage:</ins>
|
|
75
|
+
* ```js
|
|
76
|
+
* const item: T = {name: 'Matan'}
|
|
77
|
+
*
|
|
78
|
+
* //Will print 'true'
|
|
79
|
+
* console.log(filter.filterItem(item, 'Matan'))
|
|
80
|
+
*
|
|
81
|
+
* //Will print 'false'
|
|
82
|
+
* console.log(filter.filterItem(item, 'Adam'))
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
filterItem(item: T, filterText: string): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* A function returning an array of items that pass the filter</br>
|
|
88
|
+
* The function checks each item's fields (based on the mapper given when the Filter instance was created) against the filterText argument.
|
|
89
|
+
*
|
|
90
|
+
* @param items An array of items to check
|
|
91
|
+
* @param filterText - A string to filter by
|
|
92
|
+
*
|
|
93
|
+
* @return
|
|
94
|
+
*
|
|
95
|
+
* </br>
|
|
96
|
+
*
|
|
97
|
+
* #### <ins>Usage:</ins>
|
|
98
|
+
* ```js
|
|
99
|
+
* //Will return [item2]
|
|
100
|
+
* const filteredItems = filter.filter(items,'Adam');
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
filter(items: T[], filterText: string): T[];
|
|
104
|
+
filterSort(items: T[], filterText: string): T[];
|
|
105
|
+
/**
|
|
106
|
+
* A function return a boolean value as to if any of the item fields passes the Filter._filter</br>
|
|
107
|
+
* Regular expression set by the "setRegexp" function.</br>
|
|
108
|
+
* This function serves as a "default mapper" to pass to a prototype.filter function instead of using this Filter functionality.
|
|
109
|
+
*
|
|
110
|
+
* @param item The item to check
|
|
111
|
+
*
|
|
112
|
+
* @return
|
|
113
|
+
*
|
|
114
|
+
* #### <ins>Usage:</ins>
|
|
115
|
+
* ```js
|
|
116
|
+
* const filter = new Filter();
|
|
117
|
+
*
|
|
118
|
+
* filter.prepareFilter('REGEX');
|
|
119
|
+
*
|
|
120
|
+
* const filteredItems = [item1,item2,item3].filter(filter.filterImpl);
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
filterImpl: (item: T) => boolean;
|
|
124
|
+
/**
|
|
125
|
+
* A function that sets the Filter instance's filter text and regex.
|
|
126
|
+
*
|
|
127
|
+
* @param filter a filter string
|
|
128
|
+
*
|
|
129
|
+
* @returns - the Filter instance
|
|
130
|
+
*
|
|
131
|
+
* #### <ins>Usage:</ins>
|
|
132
|
+
* ```js
|
|
133
|
+
* const filter = new Filter().prepareFilter('REGEX');
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
prepareFilter(filter?: string): this;
|
|
137
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* ts-common is the basic building blocks of our typescript projects
|
|
4
|
+
*
|
|
5
|
+
* Copyright (C) 2020 Adam van der Kruk aka TacB0sS
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.Filter = void 0;
|
|
21
|
+
var array_tools_1 = require("./array-tools");
|
|
22
|
+
var specialChars = ['(', ')', '?', '[', ']', '*', '\\', '/'];
|
|
23
|
+
/**
|
|
24
|
+
* # Filter
|
|
25
|
+
*
|
|
26
|
+
* ## <ins>Intro:</ins>
|
|
27
|
+
*
|
|
28
|
+
* A filter tool for filtering a collection or testing items by comparing string values</br>
|
|
29
|
+
* This tool aims to simplify filtering arrays of strings or objects containing string fields
|
|
30
|
+
* by defining which fields are tested (via a mapper function) testing those fields against a string
|
|
31
|
+
*
|
|
32
|
+
* ## <ins>Example data:</ins>
|
|
33
|
+
*
|
|
34
|
+
* type T in the following examples will be:
|
|
35
|
+
*
|
|
36
|
+
* ```js
|
|
37
|
+
* type T = {
|
|
38
|
+
* name: string;
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* items:
|
|
43
|
+
* ```js
|
|
44
|
+
* const item1: T = {name: 'Matan'};
|
|
45
|
+
* const item2: T = {name: 'Adam'};
|
|
46
|
+
* const item3: T = {name: 'Itay'};
|
|
47
|
+
* const items: T[] = [item1, item2, item3];
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
var Filter = /** @class */ (function () {
|
|
51
|
+
/**
|
|
52
|
+
* Returns an instance of a filter, where the tested fields are the one provided by the mapper.
|
|
53
|
+
*
|
|
54
|
+
* @param mapper a function that returns a string array
|
|
55
|
+
*
|
|
56
|
+
* @return
|
|
57
|
+
*
|
|
58
|
+
* #### <ins>Usage:</ins>
|
|
59
|
+
* ```js
|
|
60
|
+
* //Prepares a filter instance where tests are run on the item.name
|
|
61
|
+
* const filter = new Filter<T>((item)=>[item.name]);
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
function Filter(mapper) {
|
|
65
|
+
var _this = this;
|
|
66
|
+
this.regexp = true;
|
|
67
|
+
/**
|
|
68
|
+
* A function return a boolean value as to if any of the item fields passes the Filter._filter</br>
|
|
69
|
+
* Regular expression set by the "setRegexp" function.</br>
|
|
70
|
+
* This function serves as a "default mapper" to pass to a prototype.filter function instead of using this Filter functionality.
|
|
71
|
+
*
|
|
72
|
+
* @param item The item to check
|
|
73
|
+
*
|
|
74
|
+
* @return
|
|
75
|
+
*
|
|
76
|
+
* #### <ins>Usage:</ins>
|
|
77
|
+
* ```js
|
|
78
|
+
* const filter = new Filter();
|
|
79
|
+
*
|
|
80
|
+
* filter.prepareFilter('REGEX');
|
|
81
|
+
*
|
|
82
|
+
* const filteredItems = [item1,item2,item3].filter(filter.filterImpl);
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
this.filterImpl = function (item) {
|
|
86
|
+
var keysToFilter = _this.mapper(item);
|
|
87
|
+
for (var _i = 0, keysToFilter_1 = keysToFilter; _i < keysToFilter_1.length; _i++) {
|
|
88
|
+
var key = keysToFilter_1[_i];
|
|
89
|
+
if (key.toLowerCase().match(_this._filter))
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
};
|
|
94
|
+
this.mapper = mapper;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* A function to set the Filter.regexp boolean flag
|
|
98
|
+
*
|
|
99
|
+
* @param regexp
|
|
100
|
+
* </br>
|
|
101
|
+
* @returns - the Filter instance
|
|
102
|
+
* </br></br>
|
|
103
|
+
*
|
|
104
|
+
* #### <ins>Usage:</ins>
|
|
105
|
+
* ```js
|
|
106
|
+
* const filter = new Filter().setRegexp(false);
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
*/
|
|
110
|
+
Filter.prototype.setRegexp = function (regexp) {
|
|
111
|
+
this.regexp = regexp;
|
|
112
|
+
delete this.originFilterText;
|
|
113
|
+
return this;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* A function returning a boolean value for if the item passes the filter</br>
|
|
117
|
+
* The function checks the item fields (based on the mapper given when the Filter instance was created) against the filterText argument
|
|
118
|
+
*
|
|
119
|
+
* @param item The item to check
|
|
120
|
+
* @param filterText A string to filter by
|
|
121
|
+
*
|
|
122
|
+
* @return
|
|
123
|
+
*
|
|
124
|
+
* </br>
|
|
125
|
+
*
|
|
126
|
+
* #### <ins>Usage:</ins>
|
|
127
|
+
* ```js
|
|
128
|
+
* const item: T = {name: 'Matan'}
|
|
129
|
+
*
|
|
130
|
+
* //Will print 'true'
|
|
131
|
+
* console.log(filter.filterItem(item, 'Matan'))
|
|
132
|
+
*
|
|
133
|
+
* //Will print 'false'
|
|
134
|
+
* console.log(filter.filterItem(item, 'Adam'))
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
Filter.prototype.filterItem = function (item, filterText) {
|
|
138
|
+
this.prepareFilter(filterText);
|
|
139
|
+
return this.filterImpl(item);
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* A function returning an array of items that pass the filter</br>
|
|
143
|
+
* The function checks each item's fields (based on the mapper given when the Filter instance was created) against the filterText argument.
|
|
144
|
+
*
|
|
145
|
+
* @param items An array of items to check
|
|
146
|
+
* @param filterText - A string to filter by
|
|
147
|
+
*
|
|
148
|
+
* @return
|
|
149
|
+
*
|
|
150
|
+
* </br>
|
|
151
|
+
*
|
|
152
|
+
* #### <ins>Usage:</ins>
|
|
153
|
+
* ```js
|
|
154
|
+
* //Will return [item2]
|
|
155
|
+
* const filteredItems = filter.filter(items,'Adam');
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
Filter.prototype.filter = function (items, filterText) {
|
|
159
|
+
this.prepareFilter(filterText);
|
|
160
|
+
return items.filter(this.filterImpl);
|
|
161
|
+
};
|
|
162
|
+
Filter.prototype.filterSort = function (items, filterText) {
|
|
163
|
+
var _this = this;
|
|
164
|
+
this.prepareFilter(filterText);
|
|
165
|
+
var text = filterText.toLowerCase();
|
|
166
|
+
var filteredItems = items.filter(this.filterImpl);
|
|
167
|
+
return (0, array_tools_1.sortArray)(filteredItems, function (item) {
|
|
168
|
+
var values = _this.mapper(item).map(function (value) { return value.toLowerCase(); });
|
|
169
|
+
//Exact Match
|
|
170
|
+
if (values.includes(text)) {
|
|
171
|
+
return 0;
|
|
172
|
+
}
|
|
173
|
+
for (var _i = 0, values_1 = values; _i < values_1.length; _i++) {
|
|
174
|
+
var value = values_1[_i];
|
|
175
|
+
if (value.includes(text)) {
|
|
176
|
+
return 1;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return 2;
|
|
180
|
+
});
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* A function that sets the Filter instance's filter text and regex.
|
|
184
|
+
*
|
|
185
|
+
* @param filter a filter string
|
|
186
|
+
*
|
|
187
|
+
* @returns - the Filter instance
|
|
188
|
+
*
|
|
189
|
+
* #### <ins>Usage:</ins>
|
|
190
|
+
* ```js
|
|
191
|
+
* const filter = new Filter().prepareFilter('REGEX');
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
Filter.prototype.prepareFilter = function (filter) {
|
|
195
|
+
if (this.originFilterText === filter)
|
|
196
|
+
return this;
|
|
197
|
+
this._filter = Filter.translateStringToRegexFilter(filter || '', this.regexp);
|
|
198
|
+
this.originFilterText = filter;
|
|
199
|
+
return this;
|
|
200
|
+
};
|
|
201
|
+
Filter.translateStringToRegexFilter = function (filter, regexp) {
|
|
202
|
+
filter = (filter || '').trim();
|
|
203
|
+
filter = filter.toLowerCase();
|
|
204
|
+
filter = filter.replace(/\s+/, ' ');
|
|
205
|
+
if (regexp) {
|
|
206
|
+
filter = Array.from(filter).map(function (char) { return specialChars.includes(char) ? ".*?\\".concat(char) : ".*?".concat(char); }).join('');
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
filter = ".*?".concat(filter);
|
|
210
|
+
}
|
|
211
|
+
filter.length === 0 ? filter = '.*?' : filter += '.*';
|
|
212
|
+
return new RegExp(filter);
|
|
213
|
+
};
|
|
214
|
+
return Filter;
|
|
215
|
+
}());
|
|
216
|
+
exports.Filter = Filter;
|
|
217
|
+
//# sourceMappingURL=filter-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter-tools.js","sourceRoot":"","sources":["../../src/main/utils/filter-tools.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;AAGH,6CAAwC;AAExC,IAAM,YAAY,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH;IAsBC;;;;;;;;;;;;OAYG;IACH,gBAAY,MAA6B;QAAzC,iBAEC;QApCO,WAAM,GAAG,IAAI,CAAC;QAkItB;;;;;;;;;;;;;;;;;WAiBG;QACH,eAAU,GAAG,UAAC,IAAO;YACpB,IAAM,YAAY,GAAG,KAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YACvC,KAAkB,UAAY,EAAZ,6BAAY,EAAZ,0BAAY,EAAZ,IAAY,EAAE;gBAA3B,IAAM,GAAG,qBAAA;gBACb,IAAI,GAAG,CAAC,WAAW,EAAE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AC,CAAC,CAAC,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,MAAM,IAAI,IAAI,CAAC;QACtD,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC;IAC3B,CAAC,CAAC;IA+JH,aAAC;CAAA,AAnLD,IAmLC;AAnLY,wBAAM"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export declare function md5(toBeConverted: any): string;
|
|
3
|
+
export declare function sha1(toBeConverted: any): string;
|
|
4
|
+
export declare function sha256(toBeConverted: any): string;
|
|
5
|
+
export declare function sha384(toBeConverted: any): string;
|
|
6
|
+
export declare function sha512(toBeConverted: any): string;
|
|
7
|
+
export declare function encode(data: string | number | Buffer, encoding?: BufferEncoding): string;
|
|
8
|
+
export declare function decode(encoded: string, from?: BufferEncoding, to?: BufferEncoding): string;
|