@open-norantec/utilities 2.0.5 → 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.
@@ -1,47 +1,50 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StringUtil = void 0;
4
- const uuid_util_class_1 = require("./uuid-util.class");
5
- class StringUtil {
6
- static isFalsyString(value, connector = 'AND') {
7
- const stringList = Array.isArray(value) ? value : [value];
8
- const checkResultList = stringList.map((stringValue) => typeof stringValue === 'string' && stringValue.length > 0);
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) => !result);
10
+ return checkResultList.some(function (result) { return !result; });
11
11
  }
12
12
  if (connector === 'OR') {
13
- return checkResultList.every((result) => !result);
13
+ return checkResultList.every(function (result) { return !result; });
14
14
  }
15
15
  return true;
16
- }
17
- static generateRandomText(length = 32, extraCharacters = '') {
18
- const seed = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'.concat(extraCharacters);
19
- let result = '';
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
- static generateTempId() {
26
- const tempIds = [];
26
+ };
27
+ StringUtil.generateTempId = function () {
28
+ var tempIds = [];
27
29
  while (true) {
28
- const currentTempId = uuid_util_class_1.UUIDUtil.generateV4();
30
+ var currentTempId = UUIDUtil.generateV4();
29
31
  if (tempIds.indexOf(currentTempId) === -1) {
30
32
  tempIds.push(currentTempId);
31
- return `temp$:${currentTempId}`;
33
+ return "temp$:".concat(currentTempId);
32
34
  }
33
35
  }
34
- }
35
- static extractTempId(idOrTempId) {
36
+ };
37
+ StringUtil.extractTempId = function (idOrTempId) {
36
38
  var _a;
37
39
  if (!idOrTempId) {
38
40
  return null;
39
41
  }
40
- const 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;
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
- exports.StringUtil = StringUtil;
47
+ };
48
+ return StringUtil;
49
+ }());
50
+ export { StringUtil };
@@ -1,31 +1,98 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UrlUtil = void 0;
4
- const crypto_util_class_1 = require("./crypto-util.class");
5
- class UrlUtil {
6
- static normalize(urlString) {
7
- const url = new URL(urlString);
8
- const searchParams = new URLSearchParams(url.search);
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
- const newSearchParams = new URLSearchParams();
11
- const searchParamsEntries = Array.from(searchParams.entries());
12
- const newSearchParamsEntries = searchParamsEntries
13
- .map(([key]) => key)
14
- .sort((a, b) => a.localeCompare(b))
15
- .map((key) => [key, []]);
16
- searchParamsEntries.forEach(([key, value]) => {
17
- newSearchParamsEntries.find(([k]) => k === key)[1].push(value);
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(([key, values]) => {
20
- values.forEach((value) => {
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
- static async hash(urlString) {
28
- return await crypto_util_class_1.CryptoUtil.sha256Hex(UrlUtil.normalize(urlString));
29
- }
30
- }
31
- exports.UrlUtil = UrlUtil;
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UserAgentUtil = void 0;
4
- class UserAgentUtil {
5
- static generateRandomUa() {
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
- const userAgent = userAgents[Math.random() * userAgents.length];
26
+ var userAgent = userAgents[Math.random() * userAgents.length];
28
27
  return userAgent;
29
- }
30
- }
31
- exports.UserAgentUtil = UserAgentUtil;
28
+ };
29
+ return UserAgentUtil;
30
+ }());
31
+ export { UserAgentUtil };
@@ -1,8 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UUIDUtil = void 0;
4
- class UUIDUtil {
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
- const hex = [];
20
- const bytes = new Uint8Array(16);
21
- for (let i = 0; i < 16; i++) {
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 (let i = 0; i < 16; i++) {
25
+ for (var i = 0; i < 16; i++) {
27
26
  hex.push(bytes[i].toString(16).padStart(2, '0'));
28
27
  }
29
- return `${hex[0]}${hex[1]}${hex[2]}${hex[3]}-${hex[4]}${hex[5]}-${hex[6]}${hex[7]}-${hex[8]}${hex[9]}-${hex[10]}${hex[11]}${hex[12]}${hex[13]}${hex[14]}${hex[15]}`;
30
- }
31
- }
32
- exports.UUIDUtil = UUIDUtil;
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 };
@@ -1,15 +1,21 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VMUtil = void 0;
4
- const vm = require("node:vm");
5
- class VMUtil {
6
- static runScriptCode(code, overrideContext) {
7
- new vm.Script(code).runInContext(vm.createContext(Object.assign(Object.assign(Object.assign({}, global), { __dirname,
8
- __filename,
9
- process,
10
- module,
11
- exports,
12
- require }), overrideContext)));
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
- exports.VMUtil = VMUtil;
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
- "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 __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.0.5",
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": "~5.1.3"
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"