@open-norantec/utilities 2.1.1 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,121 +1,56 @@
1
- var __values = (this && this.__values) || function(o) {
2
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
3
- if (m) return m.call(o);
4
- if (o && typeof o.length === "number") return {
5
- next: function () {
6
- if (o && i >= o.length) o = void 0;
7
- return { value: o && o[i++], done: !o };
8
- }
9
- };
10
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
11
- };
12
- var __read = (this && this.__read) || function (o, n) {
13
- var m = typeof Symbol === "function" && o[Symbol.iterator];
14
- if (!m) return o;
15
- var i = m.call(o), r, ar = [], e;
16
- try {
17
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
18
- }
19
- catch (error) { e = { error: error }; }
20
- finally {
21
- try {
22
- if (r && !r.done && (m = i["return"])) m.call(i);
23
- }
24
- finally { if (e) throw e.error; }
25
- }
26
- return ar;
27
- };
28
- var ArrayUtil = (function () {
29
- function ArrayUtil() {
30
- }
31
- ArrayUtil.checkUnique = function (data, validator) {
32
- var e_1, _a;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ArrayUtil = void 0;
4
+ class ArrayUtil {
5
+ static checkUnique(data, validator) {
33
6
  if (!data || !Array.isArray(data)) {
34
7
  return;
35
8
  }
36
- var values = [];
37
- var _loop_1 = function (item) {
38
- var currentValue = validator(item);
9
+ const values = [];
10
+ for (const item of data) {
11
+ const currentValue = validator(item);
39
12
  if (!Array.isArray(currentValue)) {
40
- return "continue";
13
+ continue;
41
14
  }
42
- var exist = values.some(function (checkValue) {
43
- var e_2, _a;
44
- try {
45
- for (var _b = (e_2 = void 0, __values(checkValue.entries())), _c = _b.next(); !_c.done; _c = _b.next()) {
46
- var _d = __read(_c.value, 2), index = _d[0], value = _d[1];
47
- if (currentValue[index] !== value) {
48
- return false;
49
- }
50
- }
51
- }
52
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
53
- finally {
54
- try {
55
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
15
+ const exist = values.some((checkValue) => {
16
+ for (const [index, value] of checkValue.entries()) {
17
+ if (currentValue[index] !== value) {
18
+ return false;
56
19
  }
57
- finally { if (e_2) throw e_2.error; }
58
20
  }
59
21
  return true;
60
22
  });
61
23
  if (exist) {
62
- return { value: false };
24
+ return false;
63
25
  }
64
26
  values.push(currentValue);
65
- };
66
- try {
67
- for (var data_1 = __values(data), data_1_1 = data_1.next(); !data_1_1.done; data_1_1 = data_1.next()) {
68
- var item = data_1_1.value;
69
- var state_1 = _loop_1(item);
70
- if (typeof state_1 === "object")
71
- return state_1.value;
72
- }
73
- }
74
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
75
- finally {
76
- try {
77
- if (data_1_1 && !data_1_1.done && (_a = data_1.return)) _a.call(data_1);
78
- }
79
- finally { if (e_1) throw e_1.error; }
80
27
  }
81
28
  return true;
82
- };
83
- ArrayUtil.getPositiveIndexValue = function (length, index) {
29
+ }
30
+ static getPositiveIndexValue(length, index) {
84
31
  if (!length || !index) {
85
32
  return index;
86
33
  }
87
- var result = index;
34
+ let result = index;
88
35
  while (result < 0) {
89
36
  result = length + result;
90
37
  }
91
38
  return result;
92
- };
93
- ArrayUtil.traverse = function (array, transformer) {
94
- var e_3, _a;
39
+ }
40
+ static traverse(array, transformer) {
95
41
  if (!Array.isArray(array)) {
96
42
  return [];
97
43
  }
98
- var result = [];
99
- try {
100
- for (var array_1 = __values(array), array_1_1 = array_1.next(); !array_1_1.done; array_1_1 = array_1.next()) {
101
- var item = array_1_1.value;
102
- if (Array.isArray(item)) {
103
- result.push(ArrayUtil.traverse(item, transformer));
104
- }
105
- else {
106
- result.push(typeof transformer === 'function' ? transformer(item) : item);
107
- }
44
+ const result = [];
45
+ for (const item of array) {
46
+ if (Array.isArray(item)) {
47
+ result.push(ArrayUtil.traverse(item, transformer));
108
48
  }
109
- }
110
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
111
- finally {
112
- try {
113
- if (array_1_1 && !array_1_1.done && (_a = array_1.return)) _a.call(array_1);
49
+ else {
50
+ result.push(typeof transformer === 'function' ? transformer(item) : item);
114
51
  }
115
- finally { if (e_3) throw e_3.error; }
116
52
  }
117
53
  return result;
118
- };
119
- return ArrayUtil;
120
- }());
121
- export { ArrayUtil };
54
+ }
55
+ }
56
+ exports.ArrayUtil = ArrayUtil;
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -7,58 +8,27 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
9
  });
9
10
  };
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 AttemptUtil = (function () {
38
- function AttemptUtil() {
39
- }
40
- AttemptUtil.exec = function (callbackFn) {
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.AttemptUtil = void 0;
13
+ class AttemptUtil {
14
+ static exec(callbackFn) {
41
15
  try {
42
16
  return callbackFn === null || callbackFn === void 0 ? void 0 : callbackFn();
43
17
  }
44
18
  catch (error) {
45
19
  return error;
46
20
  }
47
- };
48
- AttemptUtil.execPromise = function (promise) {
49
- return __awaiter(this, void 0, void 0, function () {
21
+ }
22
+ static execPromise(promise) {
23
+ return __awaiter(this, void 0, void 0, function* () {
50
24
  var _a;
51
- return __generator(this, function (_b) {
52
- try {
53
- return [2, (_a = promise === null || promise === void 0 ? void 0 : promise.catch) === null || _a === void 0 ? void 0 : _a.call(promise, function (error) { return Promise.resolve(error); })];
54
- }
55
- catch (error) {
56
- return [2, error];
57
- }
58
- return [2];
59
- });
25
+ try {
26
+ return (_a = promise === null || promise === void 0 ? void 0 : promise.catch) === null || _a === void 0 ? void 0 : _a.call(promise, (error) => Promise.resolve(error));
27
+ }
28
+ catch (error) {
29
+ return error;
30
+ }
60
31
  });
61
- };
62
- return AttemptUtil;
63
- }());
64
- export { AttemptUtil };
32
+ }
33
+ }
34
+ exports.AttemptUtil = AttemptUtil;
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -7,100 +8,48 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
9
  });
9
10
  };
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;
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.CryptoUtil = void 0;
13
+ class CryptoUtil {
14
+ static importRsaPrivatePemKey(pemString, algorithm, keyUsages) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const base64 = pemString.replace(/(-----(BEGIN|END) PRIVATE KEY-----|\n|\r)/g, '').trim();
17
+ const binaryString = atob(base64);
18
+ const keyArrayBuffer = new ArrayBuffer(binaryString.length);
19
+ const keyArrayBufferView = new Uint8Array(keyArrayBuffer);
20
+ for (let i = 0; i < binaryString.length; i += 1) {
21
+ keyArrayBufferView[i] = binaryString.charCodeAt(i);
31
22
  }
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 CryptoUtil = (function () {
38
- function CryptoUtil() {
39
- }
40
- CryptoUtil.importRsaPrivatePemKey = function (pemString, algorithm, keyUsages) {
41
- return __awaiter(this, void 0, void 0, function () {
42
- var base64, binaryString, keyArrayBuffer, keyArrayBufferView, i, importedKey;
43
- return __generator(this, function (_a) {
44
- switch (_a.label) {
45
- case 0:
46
- base64 = pemString.replace(/(-----(BEGIN|END) PRIVATE KEY-----|\n|\r)/g, '').trim();
47
- binaryString = atob(base64);
48
- keyArrayBuffer = new ArrayBuffer(binaryString.length);
49
- keyArrayBufferView = new Uint8Array(keyArrayBuffer);
50
- for (i = 0; i < binaryString.length; i += 1) {
51
- keyArrayBufferView[i] = binaryString.charCodeAt(i);
52
- }
53
- return [4, crypto.subtle.importKey('pkcs8', keyArrayBuffer, algorithm, true, keyUsages)];
54
- case 1:
55
- importedKey = _a.sent();
56
- return [2, importedKey];
57
- }
58
- });
23
+ const importedKey = yield crypto.subtle.importKey('pkcs8', keyArrayBuffer, algorithm, true, keyUsages);
24
+ return importedKey;
59
25
  });
60
- };
61
- CryptoUtil.importRsaPublicPemKey = function (pemString, algorithm, keyUsages) {
62
- return __awaiter(this, void 0, void 0, function () {
63
- var base64, binaryString, keyArrayBuffer, keyArrayBufferView, i, importedKey;
64
- return __generator(this, function (_a) {
65
- switch (_a.label) {
66
- case 0:
67
- base64 = pemString.replace(/(-----(BEGIN|END) PUBLIC KEY-----|\n|\r)/g, '').trim();
68
- binaryString = atob(base64);
69
- keyArrayBuffer = new ArrayBuffer(binaryString.length);
70
- keyArrayBufferView = new Uint8Array(keyArrayBuffer);
71
- for (i = 0; i < binaryString.length; i += 1) {
72
- keyArrayBufferView[i] = binaryString.charCodeAt(i);
73
- }
74
- return [4, crypto.subtle.importKey('spki', keyArrayBuffer, algorithm, true, keyUsages)];
75
- case 1:
76
- importedKey = _a.sent();
77
- return [2, importedKey];
78
- }
79
- });
26
+ }
27
+ static importRsaPublicPemKey(pemString, algorithm, keyUsages) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ const base64 = pemString.replace(/(-----(BEGIN|END) PUBLIC KEY-----|\n|\r)/g, '').trim();
30
+ const binaryString = atob(base64);
31
+ const keyArrayBuffer = new ArrayBuffer(binaryString.length);
32
+ const keyArrayBufferView = new Uint8Array(keyArrayBuffer);
33
+ for (let i = 0; i < binaryString.length; i += 1) {
34
+ keyArrayBufferView[i] = binaryString.charCodeAt(i);
35
+ }
36
+ const importedKey = yield crypto.subtle.importKey('spki', keyArrayBuffer, algorithm, true, keyUsages);
37
+ return importedKey;
80
38
  });
81
- };
82
- CryptoUtil.sha256Hex = function (input) {
83
- return __awaiter(this, void 0, void 0, function () {
84
- var encoder, data, hashBuffer, hashArray;
85
- return __generator(this, function (_a) {
86
- switch (_a.label) {
87
- case 0:
88
- encoder = new TextEncoder();
89
- data = encoder.encode(input);
90
- return [4, crypto.subtle.digest('SHA-256', data)];
91
- case 1:
92
- hashBuffer = _a.sent();
93
- hashArray = Array.from(new Uint8Array(hashBuffer));
94
- return [2, hashArray.map(function (b) { return b.toString(16).padStart(2, '0'); }).join('')];
95
- }
96
- });
39
+ }
40
+ static sha256Hex(input) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ const encoder = new TextEncoder();
43
+ const data = encoder.encode(input);
44
+ const hashBuffer = yield crypto.subtle.digest('SHA-256', data);
45
+ const hashArray = Array.from(new Uint8Array(hashBuffer));
46
+ return hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
97
47
  });
98
- };
99
- CryptoUtil.convertHexToUint8Array = function (hexString) {
100
- return new Uint8Array(new Array(hexString.length / 2).fill(0).map(function (value, index) {
48
+ }
49
+ static convertHexToUint8Array(hexString) {
50
+ return new Uint8Array(new Array(hexString.length / 2).fill(0).map((value, index) => {
101
51
  return parseInt(hexString.slice(index * 2, index * 2 + 2), 16);
102
52
  }));
103
- };
104
- return CryptoUtil;
105
- }());
106
- export { CryptoUtil };
53
+ }
54
+ }
55
+ exports.CryptoUtil = CryptoUtil;
@@ -1,15 +1,15 @@
1
- import { StringUtil } from './string-util.class';
2
- var DateUtil = (function () {
3
- function DateUtil() {
4
- }
5
- DateUtil.isValidDate = function (date) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DateUtil = void 0;
4
+ const string_util_class_1 = require("./string-util.class");
5
+ class DateUtil {
6
+ static isValidDate(date) {
6
7
  return date instanceof Date && !Number.isNaN(Date.prototype.getTime.call(date));
7
- };
8
- DateUtil.isValidDateString = function (value) {
9
- if (StringUtil.isFalsyString(value))
8
+ }
9
+ static isValidDateString(value) {
10
+ if (string_util_class_1.StringUtil.isFalsyString(value))
10
11
  return false;
11
12
  return DateUtil.isValidDate(new Date(value));
12
- };
13
- return DateUtil;
14
- }());
15
- export { DateUtil };
13
+ }
14
+ }
15
+ exports.DateUtil = DateUtil;
@@ -1,31 +1,65 @@
1
- import * as crypto from 'node:crypto';
2
- var ECDHUtil = (function () {
3
- function ECDHUtil(curveName) {
4
- if (curveName === void 0) { curveName = 'prime256v1'; }
1
+ "use strict";
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.ECDHUtil = void 0;
37
+ const crypto = __importStar(require("node:crypto"));
38
+ class ECDHUtil {
39
+ constructor(curveName = 'prime256v1') {
5
40
  this.curveName = curveName;
6
41
  this.ecdh = crypto.createECDH(this.curveName);
7
42
  this.ALGORITHM = 'aes-256-gcm';
8
43
  }
9
- ECDHUtil.prototype.encrypt = function (data, otherPublicKey) {
10
- var sharedKey = this.ecdh.computeSecret(new Uint8Array(otherPublicKey));
11
- var iv = crypto.randomBytes(16);
12
- var cipher = crypto.createCipheriv(this.ALGORITHM, new Uint8Array(sharedKey), new Uint8Array(iv));
13
- var encrypted = Buffer.concat([new Uint8Array(cipher.update(data, 'utf-8')), new Uint8Array(cipher.final())]);
44
+ encrypt(data, otherPublicKey) {
45
+ const sharedKey = this.ecdh.computeSecret(new Uint8Array(otherPublicKey));
46
+ const iv = crypto.randomBytes(16);
47
+ const cipher = crypto.createCipheriv(this.ALGORITHM, new Uint8Array(sharedKey), new Uint8Array(iv));
48
+ const encrypted = Buffer.concat([new Uint8Array(cipher.update(data, 'utf-8')), new Uint8Array(cipher.final())]);
14
49
  return Buffer.concat([new Uint8Array(iv), new Uint8Array(encrypted), new Uint8Array(cipher.getAuthTag())]).toString('base64');
15
- };
16
- ECDHUtil.prototype.decrypt = function (encryptedData, otherPublicKey) {
17
- var sharedKey = this.ecdh.computeSecret(new Uint8Array(otherPublicKey));
18
- var data = Buffer.from(encryptedData, 'base64');
19
- var iv = data.subarray(0, 16);
20
- var authTag = data.subarray(data.length - 16);
21
- var encrypted = data.subarray(16, data.length - 16);
22
- var decipher = crypto.createDecipheriv(this.ALGORITHM, new Uint8Array(sharedKey), new Uint8Array(iv));
50
+ }
51
+ decrypt(encryptedData, otherPublicKey) {
52
+ const sharedKey = this.ecdh.computeSecret(new Uint8Array(otherPublicKey));
53
+ const data = Buffer.from(encryptedData, 'base64');
54
+ const iv = data.subarray(0, 16);
55
+ const authTag = data.subarray(data.length - 16);
56
+ const encrypted = data.subarray(16, data.length - 16);
57
+ const decipher = crypto.createDecipheriv(this.ALGORITHM, new Uint8Array(sharedKey), new Uint8Array(iv));
23
58
  decipher.setAuthTag(new Uint8Array(authTag));
24
59
  return Buffer.concat([
25
60
  new Uint8Array(decipher.update(new Uint8Array(encrypted))),
26
61
  new Uint8Array(decipher.final()),
27
62
  ]).toString('utf-8');
28
- };
29
- return ECDHUtil;
30
- }());
31
- export { ECDHUtil };
63
+ }
64
+ }
65
+ exports.ECDHUtil = ECDHUtil;
@@ -1,84 +1,42 @@
1
- var __read = (this && this.__read) || function (o, n) {
2
- var m = typeof Symbol === "function" && o[Symbol.iterator];
3
- if (!m) return o;
4
- var i = m.call(o), r, ar = [], e;
5
- try {
6
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
7
- }
8
- catch (error) { e = { error: error }; }
9
- finally {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EnumUtil = void 0;
4
+ const zod_1 = require("./zod");
5
+ class EnumUtil {
6
+ static getEntries(inputEnum) {
10
7
  try {
11
- if (r && !r.done && (m = i["return"])) m.call(i);
12
- }
13
- finally { if (e) throw e.error; }
14
- }
15
- return ar;
16
- };
17
- var __values = (this && this.__values) || function(o) {
18
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
19
- if (m) return m.call(o);
20
- if (o && typeof o.length === "number") return {
21
- next: function () {
22
- if (o && i >= o.length) o = void 0;
23
- return { value: o && o[i++], done: !o };
24
- }
25
- };
26
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
27
- };
28
- import { z } from './zod';
29
- var EnumUtil = (function () {
30
- function EnumUtil() {
31
- }
32
- EnumUtil.getEntries = function (inputEnum) {
33
- try {
34
- return Object.entries(inputEnum).filter(function (_a) {
35
- var _b = __read(_a, 1), key = _b[0];
8
+ return Object.entries(inputEnum).filter(([key]) => {
36
9
  return (key.length > 1 && key.startsWith('0')) || Number.isNaN(Number(key));
37
10
  });
38
11
  }
39
12
  catch (e) {
40
13
  return [];
41
14
  }
42
- };
43
- EnumUtil.isValidValue = function (inputEnum, inputValue) {
44
- var entries = EnumUtil.getEntries(inputEnum);
15
+ }
16
+ static isValidValue(inputEnum, inputValue) {
17
+ const entries = EnumUtil.getEntries(inputEnum);
45
18
  if (entries.length === 0)
46
19
  return false;
47
- return entries.some(function (_a) {
48
- var _b = __read(_a, 2), value = _b[1];
49
- return value === inputValue;
50
- });
51
- };
52
- EnumUtil.isEqual = function (enum1, enum2) {
53
- var e_1, _a;
54
- var entries1 = this.getEntries(enum1);
55
- var entries2 = this.getEntries(enum2);
20
+ return entries.some(([, value]) => value === inputValue);
21
+ }
22
+ static isEqual(enum1, enum2) {
23
+ const entries1 = this.getEntries(enum1);
24
+ const entries2 = this.getEntries(enum2);
56
25
  if (entries1.length !== entries2.length) {
57
26
  return false;
58
27
  }
59
28
  if (entries1.length === 0) {
60
29
  return true;
61
30
  }
62
- try {
63
- for (var entries1_1 = __values(entries1), entries1_1_1 = entries1_1.next(); !entries1_1_1.done; entries1_1_1 = entries1_1.next()) {
64
- var _b = __read(entries1_1_1.value, 2), key = _b[0], value = _b[1];
65
- if (entries2[key] !== value) {
66
- return false;
67
- }
68
- }
69
- }
70
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
71
- finally {
72
- try {
73
- if (entries1_1_1 && !entries1_1_1.done && (_a = entries1_1.return)) _a.call(entries1_1);
31
+ for (const [key, value] of entries1) {
32
+ if (entries2[key] !== value) {
33
+ return false;
74
34
  }
75
- finally { if (e_1) throw e_1.error; }
76
35
  }
77
36
  return true;
78
- };
79
- EnumUtil.createEnumSchema = function (object, params) {
80
- return z.enum(Object.values(object), params);
81
- };
82
- return EnumUtil;
83
- }());
84
- export { EnumUtil };
37
+ }
38
+ static createEnumSchema(object, params) {
39
+ return zod_1.z.enum(Object.values(object), params);
40
+ }
41
+ }
42
+ exports.EnumUtil = EnumUtil;
package/dist/enums.js CHANGED
@@ -1,4 +1,7 @@
1
- export var Enums;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Enums = void 0;
4
+ var Enums;
2
5
  (function (Enums) {
3
6
  Enums.OrderOrientation = {
4
7
  ASC: 'ASC',
@@ -49,4 +52,4 @@ export var Enums;
49
52
  VERBOSE: 'verbose',
50
53
  DEBUG: 'debug',
51
54
  };
52
- })(Enums || (Enums = {}));
55
+ })(Enums || (exports.Enums = Enums = {}));