@open-norantec/utilities 2.1.0 → 2.1.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/dist/array-util.class.js +93 -28
- package/dist/attempt-util.class.js +58 -17
- package/dist/crypto-util.class.d.ts +1 -1
- package/dist/crypto-util.class.js +102 -36
- package/dist/date-util.class.js +12 -12
- package/dist/ecdh-util.class.d.ts +0 -2
- package/dist/ecdh-util.class.js +21 -22
- package/dist/enum-util.class.d.ts +1 -1
- package/dist/enum-util.class.js +66 -24
- package/dist/enums.js +2 -5
- package/dist/error-util.class.js +48 -26
- package/dist/eslint-util.class.d.ts +3 -25
- package/dist/eslint-util.class.js +31 -18
- package/dist/header-util.class.js +31 -14
- package/dist/index.js +15 -31
- package/dist/json-util.class.js +8 -8
- package/dist/log-util.class.js +23 -24
- package/dist/schemas.js +56 -59
- package/dist/string-util.class.js +28 -25
- package/dist/url-util.class.js +91 -24
- package/dist/user-agent-util.class.js +10 -10
- package/dist/uuid-util.class.js +13 -13
- package/dist/vm-util.class.js +20 -14
- package/dist/zod.js +1 -17
- package/package.json +4 -2
|
@@ -1,47 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { UUIDUtil } from './uuid-util.class';
|
|
2
|
+
var StringUtil = (function () {
|
|
3
|
+
function StringUtil() {
|
|
4
|
+
}
|
|
5
|
+
StringUtil.isFalsyString = function (value, connector) {
|
|
6
|
+
if (connector === void 0) { connector = 'AND'; }
|
|
7
|
+
var stringList = Array.isArray(value) ? value : [value];
|
|
8
|
+
var checkResultList = stringList.map(function (stringValue) { return typeof stringValue === 'string' && stringValue.length > 0; });
|
|
9
9
|
if (connector === 'AND') {
|
|
10
|
-
return checkResultList.some((result)
|
|
10
|
+
return checkResultList.some(function (result) { return !result; });
|
|
11
11
|
}
|
|
12
12
|
if (connector === 'OR') {
|
|
13
|
-
return checkResultList.every((result)
|
|
13
|
+
return checkResultList.every(function (result) { return !result; });
|
|
14
14
|
}
|
|
15
15
|
return true;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
};
|
|
17
|
+
StringUtil.generateRandomText = function (length, extraCharacters) {
|
|
18
|
+
if (length === void 0) { length = 32; }
|
|
19
|
+
if (extraCharacters === void 0) { extraCharacters = ''; }
|
|
20
|
+
var seed = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'.concat(extraCharacters);
|
|
21
|
+
var result = '';
|
|
20
22
|
while (result.length < length) {
|
|
21
23
|
result += seed.charAt(Math.floor(Math.random() * seed.length));
|
|
22
24
|
}
|
|
23
25
|
return result;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
};
|
|
27
|
+
StringUtil.generateTempId = function () {
|
|
28
|
+
var tempIds = [];
|
|
27
29
|
while (true) {
|
|
28
|
-
|
|
30
|
+
var currentTempId = UUIDUtil.generateV4();
|
|
29
31
|
if (tempIds.indexOf(currentTempId) === -1) {
|
|
30
32
|
tempIds.push(currentTempId);
|
|
31
|
-
return
|
|
33
|
+
return "temp$:".concat(currentTempId);
|
|
32
34
|
}
|
|
33
35
|
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
+
};
|
|
37
|
+
StringUtil.extractTempId = function (idOrTempId) {
|
|
36
38
|
var _a;
|
|
37
39
|
if (!idOrTempId) {
|
|
38
40
|
return null;
|
|
39
41
|
}
|
|
40
|
-
|
|
42
|
+
var regex = /^temp\$:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
41
43
|
if (!regex.test(idOrTempId)) {
|
|
42
44
|
return;
|
|
43
45
|
}
|
|
44
46
|
return ((_a = /^temp\$:(.*)$/g.exec(idOrTempId)) === null || _a === void 0 ? void 0 : _a[1]) || null;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
};
|
|
48
|
+
return StringUtil;
|
|
49
|
+
}());
|
|
50
|
+
export { StringUtil };
|
package/dist/url-util.class.js
CHANGED
|
@@ -1,31 +1,98 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
12
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
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;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
38
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
39
|
+
if (!m) return o;
|
|
40
|
+
var i = m.call(o), r, ar = [], e;
|
|
41
|
+
try {
|
|
42
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
43
|
+
}
|
|
44
|
+
catch (error) { e = { error: error }; }
|
|
45
|
+
finally {
|
|
46
|
+
try {
|
|
47
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
48
|
+
}
|
|
49
|
+
finally { if (e) throw e.error; }
|
|
50
|
+
}
|
|
51
|
+
return ar;
|
|
52
|
+
};
|
|
53
|
+
import { CryptoUtil } from './crypto-util.class';
|
|
54
|
+
var UrlUtil = (function () {
|
|
55
|
+
function UrlUtil() {
|
|
56
|
+
}
|
|
57
|
+
UrlUtil.normalize = function (urlString) {
|
|
58
|
+
var url = new URL(urlString);
|
|
59
|
+
var searchParams = new URLSearchParams(url.search);
|
|
9
60
|
url.search = '';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
.map((
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
61
|
+
var newSearchParams = new URLSearchParams();
|
|
62
|
+
var searchParamsEntries = Array.from(searchParams.entries());
|
|
63
|
+
var newSearchParamsEntries = searchParamsEntries
|
|
64
|
+
.map(function (_a) {
|
|
65
|
+
var _b = __read(_a, 1), key = _b[0];
|
|
66
|
+
return key;
|
|
67
|
+
})
|
|
68
|
+
.sort(function (a, b) { return a.localeCompare(b); })
|
|
69
|
+
.map(function (key) { return [key, []]; });
|
|
70
|
+
searchParamsEntries.forEach(function (_a) {
|
|
71
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
72
|
+
newSearchParamsEntries.find(function (_a) {
|
|
73
|
+
var _b = __read(_a, 1), k = _b[0];
|
|
74
|
+
return k === key;
|
|
75
|
+
})[1].push(value);
|
|
18
76
|
});
|
|
19
|
-
newSearchParamsEntries.forEach((
|
|
20
|
-
|
|
77
|
+
newSearchParamsEntries.forEach(function (_a) {
|
|
78
|
+
var _b = __read(_a, 2), key = _b[0], values = _b[1];
|
|
79
|
+
values.forEach(function (value) {
|
|
21
80
|
newSearchParams.append(key, value);
|
|
22
81
|
});
|
|
23
82
|
});
|
|
24
83
|
url.search = newSearchParams.toString();
|
|
25
84
|
return url.toString();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
85
|
+
};
|
|
86
|
+
UrlUtil.hash = function (urlString) {
|
|
87
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
88
|
+
return __generator(this, function (_a) {
|
|
89
|
+
switch (_a.label) {
|
|
90
|
+
case 0: return [4, CryptoUtil.sha256Hex(UrlUtil.normalize(urlString))];
|
|
91
|
+
case 1: return [2, _a.sent()];
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
return UrlUtil;
|
|
97
|
+
}());
|
|
98
|
+
export { UrlUtil };
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const userAgents = [
|
|
1
|
+
var UserAgentUtil = (function () {
|
|
2
|
+
function UserAgentUtil() {
|
|
3
|
+
}
|
|
4
|
+
UserAgentUtil.generateRandomUa = function () {
|
|
5
|
+
var userAgents = [
|
|
7
6
|
'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.12) Gecko/20070731 Ubuntu/dapper-security Firefox/1.5.0.12',
|
|
8
7
|
'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Acoo Browser; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506)',
|
|
9
8
|
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11',
|
|
@@ -24,8 +23,9 @@ class UserAgentUtil {
|
|
|
24
23
|
'Opera/9.25 (Windows NT 5.1; U; en), Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/1.2.9',
|
|
25
24
|
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36',
|
|
26
25
|
];
|
|
27
|
-
|
|
26
|
+
var userAgent = userAgents[Math.random() * userAgents.length];
|
|
28
27
|
return userAgent;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
};
|
|
29
|
+
return UserAgentUtil;
|
|
30
|
+
}());
|
|
31
|
+
export { UserAgentUtil };
|
package/dist/uuid-util.class.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
static generateV4() {
|
|
1
|
+
var UUIDUtil = (function () {
|
|
2
|
+
function UUIDUtil() {
|
|
3
|
+
}
|
|
4
|
+
UUIDUtil.generateV4 = function () {
|
|
6
5
|
var _a, _b;
|
|
7
6
|
if (typeof window !== 'undefined' && typeof ((_a = window.crypto) === null || _a === void 0 ? void 0 : _a.randomUUID) === 'function') {
|
|
8
7
|
try {
|
|
@@ -16,17 +15,18 @@ class UUIDUtil {
|
|
|
16
15
|
}
|
|
17
16
|
catch (e) { }
|
|
18
17
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
for (
|
|
18
|
+
var hex = [];
|
|
19
|
+
var bytes = new Uint8Array(16);
|
|
20
|
+
for (var i = 0; i < 16; i++) {
|
|
22
21
|
bytes[i] = Math.floor(Math.random() * 256);
|
|
23
22
|
}
|
|
24
23
|
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
25
24
|
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
26
|
-
for (
|
|
25
|
+
for (var i = 0; i < 16; i++) {
|
|
27
26
|
hex.push(bytes[i].toString(16).padStart(2, '0'));
|
|
28
27
|
}
|
|
29
|
-
return
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
return "".concat(hex[0]).concat(hex[1]).concat(hex[2]).concat(hex[3], "-").concat(hex[4]).concat(hex[5], "-").concat(hex[6]).concat(hex[7], "-").concat(hex[8]).concat(hex[9], "-").concat(hex[10]).concat(hex[11]).concat(hex[12]).concat(hex[13]).concat(hex[14]).concat(hex[15]);
|
|
29
|
+
};
|
|
30
|
+
return UUIDUtil;
|
|
31
|
+
}());
|
|
32
|
+
export { UUIDUtil };
|
package/dist/vm-util.class.js
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import * as vm from 'node:vm';
|
|
13
|
+
var VMUtil = (function () {
|
|
14
|
+
function VMUtil() {
|
|
13
15
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
VMUtil.runScriptCode = function (code, overrideContext) {
|
|
17
|
+
new vm.Script(code).runInContext(vm.createContext(__assign(__assign(__assign({}, global), { __dirname: __dirname, __filename: __filename, process: process, module: module, exports: exports, require: require }), overrideContext)));
|
|
18
|
+
};
|
|
19
|
+
return VMUtil;
|
|
20
|
+
}());
|
|
21
|
+
export { VMUtil };
|
package/dist/zod.js
CHANGED
|
@@ -1,17 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("zod"), exports);
|
|
1
|
+
export * from 'zod';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-norantec/utilities",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "NoranTec Utilities",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -31,13 +31,14 @@
|
|
|
31
31
|
"homepage": "https://github.com/norantec/utilities#readme",
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/colors": "^1.1.3",
|
|
34
|
+
"@types/lodash": "^4.17.25",
|
|
34
35
|
"@types/node": "18.11.18",
|
|
35
36
|
"cross-env": "^7.0.3",
|
|
36
37
|
"eslint": "^10.3.0",
|
|
37
38
|
"rimraf": "^6.0.1",
|
|
38
39
|
"ts-node": "^10.0.0",
|
|
39
40
|
"type-fest": "^4.37.0",
|
|
40
|
-
"typescript": "
|
|
41
|
+
"typescript": "^6.0.3"
|
|
41
42
|
},
|
|
42
43
|
"dependencies": {
|
|
43
44
|
"@stylistic/eslint-plugin": "5.10.0",
|
|
@@ -46,6 +47,7 @@
|
|
|
46
47
|
"colors": "^1.4.0",
|
|
47
48
|
"eslint-config-prettier": "^10.0.0",
|
|
48
49
|
"eslint-plugin-prettier": "^5.0.0",
|
|
50
|
+
"lodash": "^4.18.1",
|
|
49
51
|
"prettier": "^3.0.0",
|
|
50
52
|
"uuid": "^11.1.0",
|
|
51
53
|
"zod": "^4.4.3"
|