@open-norantec/utilities 2.1.0 → 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,4 +1,13 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.AttemptUtil = void 0;
4
13
  class AttemptUtil {
@@ -10,14 +19,16 @@ class AttemptUtil {
10
19
  return error;
11
20
  }
12
21
  }
13
- static async execPromise(promise) {
14
- var _a;
15
- try {
16
- return (_a = promise === null || promise === void 0 ? void 0 : promise.catch) === null || _a === void 0 ? void 0 : _a.call(promise, (error) => Promise.resolve(error));
17
- }
18
- catch (error) {
19
- return error;
20
- }
22
+ static execPromise(promise) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ var _a;
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
+ }
31
+ });
21
32
  }
22
33
  }
23
34
  exports.AttemptUtil = AttemptUtil;
@@ -2,5 +2,5 @@ export declare class CryptoUtil {
2
2
  static importRsaPrivatePemKey(pemString: string, algorithm: AlgorithmIdentifier, keyUsages: Iterable<KeyUsage>): Promise<CryptoKey>;
3
3
  static importRsaPublicPemKey(pemString: string, algorithm: AlgorithmIdentifier, keyUsages: Iterable<KeyUsage>): Promise<CryptoKey>;
4
4
  static sha256Hex(input: string): Promise<string>;
5
- static convertHexToUint8Array(hexString: string): Uint8Array;
5
+ static convertHexToUint8Array(hexString: string): Uint8Array<ArrayBuffer>;
6
6
  }
@@ -1,35 +1,50 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.CryptoUtil = void 0;
4
13
  class CryptoUtil {
5
- static async importRsaPrivatePemKey(pemString, algorithm, keyUsages) {
6
- const base64 = pemString.replace(/(-----(BEGIN|END) PRIVATE KEY-----|\n|\r)/g, '').trim();
7
- const binaryString = atob(base64);
8
- const keyArrayBuffer = new ArrayBuffer(binaryString.length);
9
- const keyArrayBufferView = new Uint8Array(keyArrayBuffer);
10
- for (let i = 0; i < binaryString.length; i += 1) {
11
- keyArrayBufferView[i] = binaryString.charCodeAt(i);
12
- }
13
- const importedKey = await crypto.subtle.importKey('pkcs8', keyArrayBuffer, algorithm, true, keyUsages);
14
- return importedKey;
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);
22
+ }
23
+ const importedKey = yield crypto.subtle.importKey('pkcs8', keyArrayBuffer, algorithm, true, keyUsages);
24
+ return importedKey;
25
+ });
15
26
  }
16
- static async importRsaPublicPemKey(pemString, algorithm, keyUsages) {
17
- const base64 = pemString.replace(/(-----(BEGIN|END) PUBLIC KEY-----|\n|\r)/g, '').trim();
18
- const binaryString = atob(base64);
19
- const keyArrayBuffer = new ArrayBuffer(binaryString.length);
20
- const keyArrayBufferView = new Uint8Array(keyArrayBuffer);
21
- for (let i = 0; i < binaryString.length; i += 1) {
22
- keyArrayBufferView[i] = binaryString.charCodeAt(i);
23
- }
24
- const importedKey = await crypto.subtle.importKey('spki', keyArrayBuffer, algorithm, true, keyUsages);
25
- return importedKey;
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;
38
+ });
26
39
  }
27
- static async sha256Hex(input) {
28
- const encoder = new TextEncoder();
29
- const data = encoder.encode(input);
30
- const hashBuffer = await crypto.subtle.digest('SHA-256', data);
31
- const hashArray = Array.from(new Uint8Array(hashBuffer));
32
- return hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
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('');
47
+ });
33
48
  }
34
49
  static convertHexToUint8Array(hexString) {
35
50
  return new Uint8Array(new Array(hexString.length / 2).fill(0).map((value, index) => {
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import * as crypto from 'node:crypto';
4
2
  export declare class ECDHUtil {
5
3
  private readonly curveName;
@@ -1,7 +1,40 @@
1
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
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  exports.ECDHUtil = void 0;
4
- const crypto = require("node:crypto");
37
+ const crypto = __importStar(require("node:crypto"));
5
38
  class ECDHUtil {
6
39
  constructor(curveName = 'prime256v1') {
7
40
  this.curveName = curveName;
@@ -6,5 +6,5 @@ export declare class EnumUtil {
6
6
  static getEntries(inputEnum: IEnum): Array<[string, any]>;
7
7
  static isValidValue(inputEnum: IEnum, inputValue: any): boolean;
8
8
  static isEqual(enum1: IEnum, enum2: IEnum): boolean;
9
- static createEnumSchema<const T extends Record<string, string>>(object: T, params?: Parameters<typeof z.enum>[1]): z.ZodEnum<{ [k_1 in T[keyof T]]: k_1; } extends infer T_1 ? { [k in keyof T_1]: { [k_1 in T[keyof T]]: k_1; }[k]; } : never>;
9
+ static createEnumSchema<const T extends Record<string, string>>(object: T, params?: Parameters<typeof z.enum>[1]): z.ZodEnum<{ [k_1 in T[keyof T]]: k_1; } extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never>;
10
10
  }
@@ -1,29 +1,7 @@
1
- import * as tsParser from '@typescript-eslint/parser';
2
- import * as stylistic from '@stylistic/eslint-plugin';
3
1
  export declare class ESLintUtil {
4
- static create({ ignores, project }: {
2
+ static create({ ignores, project, rules, }: {
5
3
  ignores?: string[];
6
4
  project?: string;
7
- }): {
8
- files: string[];
9
- languageOptions: {
10
- parser: typeof tsParser;
11
- parserOptions: {
12
- project: string;
13
- tsconfigRootDir: string;
14
- sourceType: string;
15
- };
16
- };
17
- ignores: string[];
18
- plugins: {
19
- '@typescript-eslint': {
20
- configs: Record<string, ClassicConfig.Config>;
21
- meta: FlatConfig.PluginMeta;
22
- rules: import("@typescript-eslint/eslint-plugin/rules").TypeScriptESLintRules;
23
- };
24
- '@stylistic': typeof stylistic;
25
- prettier: import("@eslint/core").Plugin;
26
- };
27
- rules: any;
28
- }[];
5
+ rules?: Record<string, any>;
6
+ }): Record<string, any>[];
29
7
  }
@@ -1,12 +1,46 @@
1
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
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  exports.ESLintUtil = void 0;
4
- const tsParser = require("@typescript-eslint/parser");
5
- const tsPlugin = require("@typescript-eslint/eslint-plugin");
6
- const stylistic = require("@stylistic/eslint-plugin");
7
- const prettier = require("eslint-plugin-prettier");
37
+ const tsParser = __importStar(require("@typescript-eslint/parser"));
38
+ const tsPlugin = __importStar(require("@typescript-eslint/eslint-plugin"));
39
+ const stylistic = __importStar(require("@stylistic/eslint-plugin"));
40
+ const prettier = __importStar(require("eslint-plugin-prettier"));
41
+ const _ = __importStar(require("lodash"));
8
42
  class ESLintUtil {
9
- static create({ ignores = [], project = './tsconfig.json' }) {
43
+ static create({ ignores = [], project = './tsconfig.json', rules, }) {
10
44
  var _a, _b, _c, _d;
11
45
  return [
12
46
  {
@@ -25,7 +59,7 @@ class ESLintUtil {
25
59
  '@stylistic': stylistic,
26
60
  prettier,
27
61
  },
28
- rules: Object.assign(Object.assign(Object.assign({}, (_b = (_a = tsPlugin === null || tsPlugin === void 0 ? void 0 : tsPlugin.configs) === null || _a === void 0 ? void 0 : _a.recommended) === null || _b === void 0 ? void 0 : _b.rules), (_d = (_c = prettier === null || prettier === void 0 ? void 0 : prettier.configs) === null || _c === void 0 ? void 0 : _c.recommended) === null || _d === void 0 ? void 0 : _d.rules), { 'prettier/prettier': [
62
+ rules: _.merge(Object.assign(Object.assign(Object.assign({}, (_b = (_a = tsPlugin === null || tsPlugin === void 0 ? void 0 : tsPlugin.configs) === null || _a === void 0 ? void 0 : _a.recommended) === null || _b === void 0 ? void 0 : _b.rules), (_d = (_c = prettier === null || prettier === void 0 ? void 0 : prettier.configs) === null || _c === void 0 ? void 0 : _c.recommended) === null || _d === void 0 ? void 0 : _d.rules), { 'prettier/prettier': [
29
63
  'error',
30
64
  {
31
65
  singleQuote: true,
@@ -48,7 +82,7 @@ class ESLintUtil {
48
82
  requireLast: false,
49
83
  },
50
84
  },
51
- ], 'object-curly-newline': ['error', { multiline: true, consistent: true }] }),
85
+ ], 'object-curly-newline': ['error', { multiline: true, consistent: true }], 'multiline-ternary': 'off' }), rules || {}),
52
86
  },
53
87
  ];
54
88
  }
@@ -1,4 +1,13 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.UrlUtil = void 0;
4
13
  const crypto_util_class_1 = require("./crypto-util.class");
@@ -24,8 +33,10 @@ class UrlUtil {
24
33
  url.search = newSearchParams.toString();
25
34
  return url.toString();
26
35
  }
27
- static async hash(urlString) {
28
- return await crypto_util_class_1.CryptoUtil.sha256Hex(UrlUtil.normalize(urlString));
36
+ static hash(urlString) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ return yield crypto_util_class_1.CryptoUtil.sha256Hex(UrlUtil.normalize(urlString));
39
+ });
29
40
  }
30
41
  }
31
42
  exports.UrlUtil = UrlUtil;
@@ -1,7 +1,40 @@
1
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
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  exports.VMUtil = void 0;
4
- const vm = require("node:vm");
37
+ const vm = __importStar(require("node:vm"));
5
38
  class VMUtil {
6
39
  static runScriptCode(code, overrideContext) {
7
40
  new vm.Script(code).runInContext(vm.createContext(Object.assign(Object.assign(Object.assign({}, global), { __dirname,
package/package.json CHANGED
@@ -1,53 +1,55 @@
1
1
  {
2
- "name": "@open-norantec/utilities",
3
- "version": "2.1.0",
4
- "description": "NoranTec Utilities",
5
- "main": "dist/index.js",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1",
8
- "build:cjs": "rimraf dist && tsc -b",
9
- "build": "npm run build:cjs",
10
- "setup:exec": "node bin/nttc.js setup",
11
- "setup": "npm run build && node bin/nttc.js setup"
12
- },
13
- "repository": {
14
- "type": "git",
15
- "url": "git+ssh://git@github.com/norantec/utilities.git"
16
- },
17
- "author": "lenconda <i@lenconda.top>",
18
- "bugs": {
19
- "url": "https://github.com/norantec/utilities/issues"
20
- },
21
- "files": [
22
- "bin",
23
- "dist",
24
- "LICENSE",
25
- "README.md"
26
- ],
27
- "publishConfig": {
28
- "access": "public",
29
- "registry": "https://registry.npmjs.org"
30
- },
31
- "homepage": "https://github.com/norantec/utilities#readme",
32
- "devDependencies": {
33
- "@types/colors": "^1.1.3",
34
- "@types/node": "18.11.18",
35
- "cross-env": "^7.0.3",
36
- "eslint": "^10.3.0",
37
- "rimraf": "^6.0.1",
38
- "ts-node": "^10.0.0",
39
- "type-fest": "^4.37.0",
40
- "typescript": "~5.1.3"
41
- },
42
- "dependencies": {
43
- "@stylistic/eslint-plugin": "5.10.0",
44
- "@typescript-eslint/eslint-plugin": "^8.0.0",
45
- "@typescript-eslint/parser": "^8.0.0",
46
- "colors": "^1.4.0",
47
- "eslint-config-prettier": "^10.0.0",
48
- "eslint-plugin-prettier": "^5.0.0",
49
- "prettier": "^3.0.0",
50
- "uuid": "^11.1.0",
51
- "zod": "^4.4.3"
52
- }
2
+ "name": "@open-norantec/utilities",
3
+ "version": "2.1.2",
4
+ "description": "NoranTec Utilities",
5
+ "main": "dist/index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1",
8
+ "build:cjs": "rimraf dist && tsc -b",
9
+ "build": "npm run build:cjs",
10
+ "setup:exec": "node bin/nttc.js setup",
11
+ "setup": "npm run build && node bin/nttc.js setup"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+ssh://git@github.com/norantec/utilities.git"
16
+ },
17
+ "author": "lenconda <i@lenconda.top>",
18
+ "bugs": {
19
+ "url": "https://github.com/norantec/utilities/issues"
20
+ },
21
+ "files": [
22
+ "bin",
23
+ "dist",
24
+ "LICENSE",
25
+ "README.md"
26
+ ],
27
+ "publishConfig": {
28
+ "access": "public",
29
+ "registry": "https://registry.npmjs.org"
30
+ },
31
+ "homepage": "https://github.com/norantec/utilities#readme",
32
+ "devDependencies": {
33
+ "@types/colors": "^1.1.3",
34
+ "@types/lodash": "^4.17.25",
35
+ "@types/node": "18.11.18",
36
+ "cross-env": "^7.0.3",
37
+ "eslint": "^10.3.0",
38
+ "rimraf": "^6.0.1",
39
+ "ts-node": "^10.0.0",
40
+ "type-fest": "^4.37.0",
41
+ "typescript": "^6.0.3"
42
+ },
43
+ "dependencies": {
44
+ "@stylistic/eslint-plugin": "5.10.0",
45
+ "@typescript-eslint/eslint-plugin": "^8.0.0",
46
+ "@typescript-eslint/parser": "^8.0.0",
47
+ "colors": "^1.4.0",
48
+ "eslint-config-prettier": "^10.0.0",
49
+ "eslint-plugin-prettier": "^5.0.0",
50
+ "lodash": "^4.18.1",
51
+ "prettier": "^3.0.0",
52
+ "uuid": "^11.1.0",
53
+ "zod": "^4.4.3"
54
+ }
53
55
  }