@alextheman/utility 5.6.1 → 5.6.3

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,4 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  //#region \0rolldown/runtime.js
3
3
  var __create = Object.create;
4
4
  var __defProp = Object.defineProperty;
@@ -7,16 +7,12 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
7
7
  var __getProtoOf = Object.getPrototypeOf;
8
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
9
  var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
- key = keys[i];
13
- if (!__hasOwnProp.call(to, key) && key !== except) {
14
- __defProp(to, key, {
15
- get: ((k) => from[k]).bind(null, key),
16
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
- });
18
- }
19
- }
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: ((k) => from[k]).bind(null, key),
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
20
16
  }
21
17
  return to;
22
18
  };
@@ -24,14 +20,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
20
  value: mod,
25
21
  enumerable: true
26
22
  }) : target, mod));
27
-
28
23
  //#endregion
29
24
  let node_path = require("node:path");
30
25
  node_path = __toESM(node_path);
31
26
  let zod = require("zod");
32
27
  zod = __toESM(zod);
33
28
  require("libsodium-wrappers");
34
-
35
29
  //#region src/node/functions/normalizeImportPath.ts
36
30
  /**
37
31
  * Normalizes an import path meant for use in an import statement in JavaScript.
@@ -67,26 +61,15 @@ function normalizeImportPath(importPath) {
67
61
  * @returns The import path normalised.
68
62
  */
69
63
  const normaliseImportPath = normalizeImportPath;
70
-
71
64
  //#endregion
72
65
  //#region src/root/constants/FILE_PATH_REGEX.ts
73
66
  const FILE_PATH_PATTERN = String.raw`(?<directory>.+)[\/\\](?<base>[^\/\\]+)`;
74
67
  const FILE_PATH_REGEX = RegExp(`^${FILE_PATH_PATTERN}$`);
75
-
76
- //#endregion
77
- //#region src/root/constants/ONE_DAY_IN_MILLISECONDS.ts
78
- const ONE_DAY_IN_MILLISECONDS = 1440 * 60 * 1e3;
79
-
80
- //#endregion
81
- //#region src/root/constants/UUID_REGEX.ts
82
- const UUID_PATTERN = "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}";
83
- const UUID_REGEX = new RegExp(`^${UUID_PATTERN}$`);
84
-
68
+ new RegExp(`^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$`);
85
69
  //#endregion
86
70
  //#region src/root/constants/VERSION_NUMBER_REGEX.ts
87
71
  const VERSION_NUMBER_PATTERN = String.raw`^(?:v)?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$`;
88
72
  const VERSION_NUMBER_REGEX = RegExp(`^${VERSION_NUMBER_PATTERN}$`);
89
-
90
73
  //#endregion
91
74
  //#region src/root/functions/arrayHelpers/fillArray.ts
92
75
  /**
@@ -113,7 +96,6 @@ function fillArray(callback, length = 1) {
113
96
  })) return Promise.all(outputArray);
114
97
  return outputArray;
115
98
  }
116
-
117
99
  //#endregion
118
100
  //#region src/root/functions/arrayHelpers/paralleliseArrays.ts
119
101
  /**
@@ -137,7 +119,6 @@ function paralleliseArrays(firstArray, secondArray) {
137
119
  for (let i = 0; i < firstArray.length; i++) outputArray.push([firstArray[i], secondArray[i]]);
138
120
  return outputArray;
139
121
  }
140
-
141
122
  //#endregion
142
123
  //#region src/root/functions/parsers/parseIntStrict.ts
143
124
  /**
@@ -159,7 +140,7 @@ function parseIntStrict(string, radix) {
159
140
  string,
160
141
  radix
161
142
  } : { string }, "INTEGER_PARSING_ERROR", `Only numeric values${radix && radix > 10 && radix <= 36 ? ` or character${radix !== 11 ? "s" : ""} A${radix !== 11 ? `-${maxAllowedAlphabeticalCharacter?.toUpperCase()} ` : " "}` : " "}are allowed.`);
162
- if (radix && radix < 10 && [...trimmedString].some((character) => {
143
+ if (radix && radix < 10 && [...trimmedString.replace(/^[+-]/, "")].some((character) => {
163
144
  return parseInt(character) >= radix;
164
145
  })) throw new DataError({
165
146
  string,
@@ -169,7 +150,6 @@ function parseIntStrict(string, radix) {
169
150
  if (isNaN(parseIntResult)) throw new DataError({ string }, "INTEGER_PARSING_ERROR", "Value is not a valid integer.");
170
151
  return parseIntResult;
171
152
  }
172
-
173
153
  //#endregion
174
154
  //#region src/root/functions/taggedTemplate/interpolate.ts
175
155
  /**
@@ -197,7 +177,6 @@ function interpolate(strings, ...interpolations) {
197
177
  for (const [string, interpolation = ""] of paralleliseArrays(strings, interpolations)) result += string + interpolation;
198
178
  return result;
199
179
  }
200
-
201
180
  //#endregion
202
181
  //#region src/root/functions/taggedTemplate/normaliseIndents.ts
203
182
  function calculateTabSize(line, whitespaceLength) {
@@ -261,7 +240,6 @@ function normaliseIndents(first, ...args) {
261
240
  const options = typeof args[args.length - 1] === "object" && !Array.isArray(args[args.length - 1]) ? args.pop() : {};
262
241
  return reduceLines(interpolate(strings, ...[...args]).split("\n"), options);
263
242
  }
264
-
265
243
  //#endregion
266
244
  //#region src/root/functions/miscellaneous/sayHello.ts
267
245
  /**
@@ -375,7 +353,6 @@ function sayHello() {
375
353
  I'll commit to you!
376
354
  `;
377
355
  }
378
-
379
356
  //#endregion
380
357
  //#region src/root/functions/parsers/parseVersionType.ts
381
358
  /**
@@ -388,7 +365,6 @@ const VersionType = {
388
365
  MINOR: "minor",
389
366
  PATCH: "patch"
390
367
  };
391
-
392
368
  //#endregion
393
369
  //#region src/root/types/DataError.ts
394
370
  /**
@@ -478,7 +454,6 @@ var DataError = class DataError extends Error {
478
454
  throw new Error("Expected a DataError to be thrown but none was thrown");
479
455
  }
480
456
  };
481
-
482
457
  //#endregion
483
458
  //#region src/root/types/VersionNumber.ts
484
459
  /**
@@ -503,7 +478,7 @@ var VersionNumber = class VersionNumber {
503
478
  this.minor = input.minor;
504
479
  this.patch = input.patch;
505
480
  } else if (typeof input === "string") {
506
- if (!RegExp(VERSION_NUMBER_REGEX).test(input)) throw new DataError({ input }, "INVALID_VERSION", `"${input}" is not a valid version number. Version numbers must be of the format "X.Y.Z" or "vX.Y.Z", where X, Y, and Z are non-negative integers.`);
481
+ if (!VERSION_NUMBER_REGEX.test(input)) throw new DataError({ input }, "INVALID_VERSION", `"${input}" is not a valid version number. Version numbers must be of the format "X.Y.Z" or "vX.Y.Z", where X, Y, and Z are non-negative integers.`);
507
482
  const [major, minor, patch] = VersionNumber.formatString(input, { omitPrefix: true }).split(".").map((number) => {
508
483
  return parseIntStrict(number);
509
484
  });
@@ -520,7 +495,10 @@ var VersionNumber = class VersionNumber {
520
495
  this.major = major;
521
496
  this.minor = minor;
522
497
  this.patch = patch;
523
- }
498
+ } else throw new DataError({ input }, "INVALID_INPUT", normaliseIndents`
499
+ The provided input can not be parsed into a valid version number.
500
+ Expected either a string of format X.Y.Z or vX.Y.Z, a tuple of three numbers, or another \`VersionNumber\` instance.
501
+ `);
524
502
  }
525
503
  /**
526
504
  * Gets the current version type of the current instance of `VersionNumber`.
@@ -632,7 +610,7 @@ var VersionNumber = class VersionNumber {
632
610
  return VersionNumber.formatString(rawString, { omitPrefix: false });
633
611
  }
634
612
  };
635
- const zodVersionNumber = zod.default.union([
613
+ zod.default.union([
636
614
  zod.default.string(),
637
615
  zod.default.tuple([
638
616
  zod.default.number(),
@@ -643,7 +621,6 @@ const zodVersionNumber = zod.default.union([
643
621
  ]).transform((rawVersionNumber) => {
644
622
  return new VersionNumber(rawVersionNumber);
645
623
  });
646
-
647
624
  //#endregion
648
625
  //#region src/node/functions/parseFilePath.ts
649
626
  /**
@@ -674,13 +651,11 @@ function parseFilePath(filePath) {
674
651
  fullPath: node_path.default.join(caughtGroups.groups.directory.replaceAll("\\", "/"), caughtGroups.groups.base)
675
652
  };
676
653
  }
677
-
678
654
  //#endregion
679
655
  //#region src/node/functions/sayHello.ts
680
656
  var sayHello_default = sayHello;
681
-
682
657
  //#endregion
683
658
  exports.normaliseImportPath = normaliseImportPath;
684
659
  exports.normalizeImportPath = normalizeImportPath;
685
660
  exports.parseFilePath = parseFilePath;
686
- exports.sayHello = sayHello_default;
661
+ exports.sayHello = sayHello_default;
@@ -1,7 +1,6 @@
1
1
  import path from "node:path";
2
2
  import z from "zod";
3
3
  import "libsodium-wrappers";
4
-
5
4
  //#region src/node/functions/normalizeImportPath.ts
6
5
  /**
7
6
  * Normalizes an import path meant for use in an import statement in JavaScript.
@@ -37,26 +36,15 @@ function normalizeImportPath(importPath) {
37
36
  * @returns The import path normalised.
38
37
  */
39
38
  const normaliseImportPath = normalizeImportPath;
40
-
41
39
  //#endregion
42
40
  //#region src/root/constants/FILE_PATH_REGEX.ts
43
41
  const FILE_PATH_PATTERN = String.raw`(?<directory>.+)[\/\\](?<base>[^\/\\]+)`;
44
42
  const FILE_PATH_REGEX = RegExp(`^${FILE_PATH_PATTERN}$`);
45
-
46
- //#endregion
47
- //#region src/root/constants/ONE_DAY_IN_MILLISECONDS.ts
48
- const ONE_DAY_IN_MILLISECONDS = 1440 * 60 * 1e3;
49
-
50
- //#endregion
51
- //#region src/root/constants/UUID_REGEX.ts
52
- const UUID_PATTERN = "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}";
53
- const UUID_REGEX = new RegExp(`^${UUID_PATTERN}$`);
54
-
43
+ new RegExp(`^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$`);
55
44
  //#endregion
56
45
  //#region src/root/constants/VERSION_NUMBER_REGEX.ts
57
46
  const VERSION_NUMBER_PATTERN = String.raw`^(?:v)?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$`;
58
47
  const VERSION_NUMBER_REGEX = RegExp(`^${VERSION_NUMBER_PATTERN}$`);
59
-
60
48
  //#endregion
61
49
  //#region src/root/functions/arrayHelpers/fillArray.ts
62
50
  /**
@@ -83,7 +71,6 @@ function fillArray(callback, length = 1) {
83
71
  })) return Promise.all(outputArray);
84
72
  return outputArray;
85
73
  }
86
-
87
74
  //#endregion
88
75
  //#region src/root/functions/arrayHelpers/paralleliseArrays.ts
89
76
  /**
@@ -107,7 +94,6 @@ function paralleliseArrays(firstArray, secondArray) {
107
94
  for (let i = 0; i < firstArray.length; i++) outputArray.push([firstArray[i], secondArray[i]]);
108
95
  return outputArray;
109
96
  }
110
-
111
97
  //#endregion
112
98
  //#region src/root/functions/parsers/parseIntStrict.ts
113
99
  /**
@@ -129,7 +115,7 @@ function parseIntStrict(string, radix) {
129
115
  string,
130
116
  radix
131
117
  } : { string }, "INTEGER_PARSING_ERROR", `Only numeric values${radix && radix > 10 && radix <= 36 ? ` or character${radix !== 11 ? "s" : ""} A${radix !== 11 ? `-${maxAllowedAlphabeticalCharacter?.toUpperCase()} ` : " "}` : " "}are allowed.`);
132
- if (radix && radix < 10 && [...trimmedString].some((character) => {
118
+ if (radix && radix < 10 && [...trimmedString.replace(/^[+-]/, "")].some((character) => {
133
119
  return parseInt(character) >= radix;
134
120
  })) throw new DataError({
135
121
  string,
@@ -139,7 +125,6 @@ function parseIntStrict(string, radix) {
139
125
  if (isNaN(parseIntResult)) throw new DataError({ string }, "INTEGER_PARSING_ERROR", "Value is not a valid integer.");
140
126
  return parseIntResult;
141
127
  }
142
-
143
128
  //#endregion
144
129
  //#region src/root/functions/taggedTemplate/interpolate.ts
145
130
  /**
@@ -167,7 +152,6 @@ function interpolate(strings, ...interpolations) {
167
152
  for (const [string, interpolation = ""] of paralleliseArrays(strings, interpolations)) result += string + interpolation;
168
153
  return result;
169
154
  }
170
-
171
155
  //#endregion
172
156
  //#region src/root/functions/taggedTemplate/normaliseIndents.ts
173
157
  function calculateTabSize(line, whitespaceLength) {
@@ -231,7 +215,6 @@ function normaliseIndents(first, ...args) {
231
215
  const options = typeof args[args.length - 1] === "object" && !Array.isArray(args[args.length - 1]) ? args.pop() : {};
232
216
  return reduceLines(interpolate(strings, ...[...args]).split("\n"), options);
233
217
  }
234
-
235
218
  //#endregion
236
219
  //#region src/root/functions/miscellaneous/sayHello.ts
237
220
  /**
@@ -345,7 +328,6 @@ function sayHello() {
345
328
  I'll commit to you!
346
329
  `;
347
330
  }
348
-
349
331
  //#endregion
350
332
  //#region src/root/functions/parsers/parseVersionType.ts
351
333
  /**
@@ -358,7 +340,6 @@ const VersionType = {
358
340
  MINOR: "minor",
359
341
  PATCH: "patch"
360
342
  };
361
-
362
343
  //#endregion
363
344
  //#region src/root/types/DataError.ts
364
345
  /**
@@ -448,7 +429,6 @@ var DataError = class DataError extends Error {
448
429
  throw new Error("Expected a DataError to be thrown but none was thrown");
449
430
  }
450
431
  };
451
-
452
432
  //#endregion
453
433
  //#region src/root/types/VersionNumber.ts
454
434
  /**
@@ -473,7 +453,7 @@ var VersionNumber = class VersionNumber {
473
453
  this.minor = input.minor;
474
454
  this.patch = input.patch;
475
455
  } else if (typeof input === "string") {
476
- if (!RegExp(VERSION_NUMBER_REGEX).test(input)) throw new DataError({ input }, "INVALID_VERSION", `"${input}" is not a valid version number. Version numbers must be of the format "X.Y.Z" or "vX.Y.Z", where X, Y, and Z are non-negative integers.`);
456
+ if (!VERSION_NUMBER_REGEX.test(input)) throw new DataError({ input }, "INVALID_VERSION", `"${input}" is not a valid version number. Version numbers must be of the format "X.Y.Z" or "vX.Y.Z", where X, Y, and Z are non-negative integers.`);
477
457
  const [major, minor, patch] = VersionNumber.formatString(input, { omitPrefix: true }).split(".").map((number) => {
478
458
  return parseIntStrict(number);
479
459
  });
@@ -490,7 +470,10 @@ var VersionNumber = class VersionNumber {
490
470
  this.major = major;
491
471
  this.minor = minor;
492
472
  this.patch = patch;
493
- }
473
+ } else throw new DataError({ input }, "INVALID_INPUT", normaliseIndents`
474
+ The provided input can not be parsed into a valid version number.
475
+ Expected either a string of format X.Y.Z or vX.Y.Z, a tuple of three numbers, or another \`VersionNumber\` instance.
476
+ `);
494
477
  }
495
478
  /**
496
479
  * Gets the current version type of the current instance of `VersionNumber`.
@@ -602,7 +585,7 @@ var VersionNumber = class VersionNumber {
602
585
  return VersionNumber.formatString(rawString, { omitPrefix: false });
603
586
  }
604
587
  };
605
- const zodVersionNumber = z.union([
588
+ z.union([
606
589
  z.string(),
607
590
  z.tuple([
608
591
  z.number(),
@@ -613,7 +596,6 @@ const zodVersionNumber = z.union([
613
596
  ]).transform((rawVersionNumber) => {
614
597
  return new VersionNumber(rawVersionNumber);
615
598
  });
616
-
617
599
  //#endregion
618
600
  //#region src/node/functions/parseFilePath.ts
619
601
  /**
@@ -644,10 +626,8 @@ function parseFilePath(filePath) {
644
626
  fullPath: path.join(caughtGroups.groups.directory.replaceAll("\\", "/"), caughtGroups.groups.base)
645
627
  };
646
628
  }
647
-
648
629
  //#endregion
649
630
  //#region src/node/functions/sayHello.ts
650
631
  var sayHello_default = sayHello;
651
-
652
632
  //#endregion
653
- export { normaliseImportPath, normalizeImportPath, parseFilePath, sayHello_default as sayHello };
633
+ export { normaliseImportPath, normalizeImportPath, parseFilePath, sayHello_default as sayHello };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alextheman/utility",
3
- "version": "5.6.1",
3
+ "version": "5.6.3",
4
4
  "description": "Helpful utility functions.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -36,23 +36,23 @@
36
36
  "zod": "^4.3.6"
37
37
  },
38
38
  "devDependencies": {
39
- "@alextheman/eslint-plugin": "^5.9.1",
40
- "@types/node": "^25.3.3",
41
- "alex-c-line": "^2.0.0",
39
+ "@alextheman/eslint-plugin": "^5.10.1",
40
+ "@types/node": "^25.5.0",
41
+ "alex-c-line": "^2.2.3",
42
42
  "cross-env": "^10.1.0",
43
43
  "dotenv-cli": "^11.0.0",
44
- "eslint": "^10.0.2",
45
- "globals": "^17.3.0",
44
+ "eslint": "^10.0.3",
45
+ "globals": "^17.4.0",
46
46
  "husky": "^9.1.7",
47
47
  "jsdom": "^28.1.0",
48
48
  "prettier": "^3.8.1",
49
49
  "tempy": "^3.2.0",
50
- "tsdown": "^0.20.3",
50
+ "tsdown": "^0.21.2",
51
51
  "tsx": "^4.21.0",
52
52
  "typedoc": "^0.28.17",
53
53
  "typescript": "^5.9.3",
54
54
  "vite-tsconfig-paths": "^6.1.1",
55
- "vitest": "^4.0.18"
55
+ "vitest": "^4.1.0"
56
56
  },
57
57
  "engines": {
58
58
  "node": ">=22.3.0"
@@ -63,13 +63,13 @@
63
63
  "create-local-package": "pnpm run build && rm -f alextheman-utility-*.tgz && pnpm pack",
64
64
  "create-release-note": "bash -c 'git pull origin main && alex-c-line template release-note create $@' --",
65
65
  "format": "pnpm run format-prettier && pnpm run format-eslint",
66
- "format-eslint": "eslint --fix --suppress-all \"package.json\" \"src/**/*.ts\" \"tests/**/*.ts\" && rm -f eslint-suppressions.json",
66
+ "format-eslint": "eslint --fix --suppress-all \"package.json\" \"src/**/*.ts\" \"tests/**/*.ts\" \"configs/**/*.ts\" && rm -f eslint-suppressions.json",
67
67
  "format-prettier": "pnpm run format-prettier-typescript && pnpm run format-prettier-javascript && pnpm run format-prettier-yml",
68
68
  "format-prettier-javascript": "prettier --write \"./**/*.js\"",
69
69
  "format-prettier-typescript": "prettier --write --parser typescript \"./**/*.ts\"",
70
70
  "format-prettier-yml": "prettier --write \"./**/*.{yml,yaml}\"",
71
71
  "lint": "pnpm run lint-tsc && pnpm run lint-eslint && pnpm run lint-prettier && pnpm run lint-pre-release",
72
- "lint-eslint": "eslint \"package.json\" \"src/**/*.ts\" \"tests/**/*.ts\"",
72
+ "lint-eslint": "eslint \"package.json\" \"src/**/*.ts\" \"tests/**/*.ts\" \"configs/**/*.ts\"",
73
73
  "lint-pre-release": "alex-c-line package-json check --rules no-pre-release-dependencies",
74
74
  "lint-prettier": "pnpm run lint-prettier-typescript && pnpm run lint-prettier-javascript && pnpm run lint-prettier-yml",
75
75
  "lint-prettier-javascript": "prettier --check \"./**/*.js\"",