@webdeveric/utils 0.74.0 → 0.74.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.
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.deepFreeze = deepFreeze;
4
4
  function deepFreeze(input, partialOptions = {}) {
5
- const { filterProperties = new Set(['prototype', '__proto__']), doNotFreeze = new WeakSet(typeof globalThis !== 'undefined' ? [globalThis] : []), frozen = new WeakSet(), } = partialOptions;
5
+ const { filterProperties = new Set(['prototype', '__proto__']), doNotFreeze = new WeakSet([globalThis]), frozen = new WeakSet(), } = partialOptions;
6
6
  if (doNotFreeze.has(input)) {
7
7
  return input;
8
8
  }
@@ -12,9 +12,7 @@ function deepFreeze(input, partialOptions = {}) {
12
12
  const freeze = (inputObject) => {
13
13
  if (Array.isArray(inputObject)) {
14
14
  inputObject.forEach((item) => {
15
- if (shouldFreeze(item)) {
16
- freeze(item);
17
- }
15
+ shouldFreeze(item) && freeze(item);
18
16
  });
19
17
  }
20
18
  else {
@@ -26,9 +24,7 @@ function deepFreeze(input, partialOptions = {}) {
26
24
  }
27
25
  }
28
26
  }
29
- if (!frozen.has(inputObject)) {
30
- frozen.add(Object.freeze(inputObject));
31
- }
27
+ !frozen.has(inputObject) && frozen.add(Object.freeze(inputObject));
32
28
  return inputObject;
33
29
  };
34
30
  return freeze(input);
@@ -27,7 +27,7 @@ const describeInput = (input) => {
27
27
  const url = new URL(input);
28
28
  return `${url.protocol.replace(':', '')} URL${url.username || url.password ? ' with credentials' : ''}`;
29
29
  }
30
- catch (error) {
30
+ catch {
31
31
  return 'Invalid URL';
32
32
  }
33
33
  }
@@ -46,12 +46,10 @@ const describeInput = (input) => {
46
46
  if (Number.isInteger(input)) {
47
47
  return 'Integer';
48
48
  }
49
- if (Number.isFinite(input)) {
50
- return 'Finite Number';
51
- }
52
49
  if (Number.isNaN(input)) {
53
50
  return 'NaN';
54
51
  }
52
+ return 'Float';
55
53
  }
56
54
  }
57
55
  return (0, getType_js_1.getType)(input);
@@ -1,5 +1,39 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isTimeoutError = void 0;
4
- const isTimeoutError = (error) => error instanceof DOMException && error.name === 'TimeoutError';
5
- exports.isTimeoutError = isTimeoutError;
4
+ const literal_js_1 = require("./factory/literal.js");
5
+ const optional_js_1 = require("./factory/optional.js");
6
+ const shape_js_1 = require("./factory/shape.js");
7
+ const isNumber_js_1 = require("./isNumber.js");
8
+ const isString_js_1 = require("./isString.js");
9
+ exports.isTimeoutError = (0, shape_js_1.shape)({
10
+ name: (0, literal_js_1.literal)('TimeoutError'),
11
+ message: isString_js_1.isString,
12
+ stack: (0, optional_js_1.optional)(isString_js_1.isString),
13
+ code: isNumber_js_1.isNumber,
14
+ INDEX_SIZE_ERR: (0, literal_js_1.literal)(1),
15
+ DOMSTRING_SIZE_ERR: (0, literal_js_1.literal)(2),
16
+ HIERARCHY_REQUEST_ERR: (0, literal_js_1.literal)(3),
17
+ WRONG_DOCUMENT_ERR: (0, literal_js_1.literal)(4),
18
+ INVALID_CHARACTER_ERR: (0, literal_js_1.literal)(5),
19
+ NO_DATA_ALLOWED_ERR: (0, literal_js_1.literal)(6),
20
+ NO_MODIFICATION_ALLOWED_ERR: (0, literal_js_1.literal)(7),
21
+ NOT_FOUND_ERR: (0, literal_js_1.literal)(8),
22
+ NOT_SUPPORTED_ERR: (0, literal_js_1.literal)(9),
23
+ INUSE_ATTRIBUTE_ERR: (0, literal_js_1.literal)(10),
24
+ INVALID_STATE_ERR: (0, literal_js_1.literal)(11),
25
+ SYNTAX_ERR: (0, literal_js_1.literal)(12),
26
+ INVALID_MODIFICATION_ERR: (0, literal_js_1.literal)(13),
27
+ NAMESPACE_ERR: (0, literal_js_1.literal)(14),
28
+ INVALID_ACCESS_ERR: (0, literal_js_1.literal)(15),
29
+ VALIDATION_ERR: (0, literal_js_1.literal)(16),
30
+ TYPE_MISMATCH_ERR: (0, literal_js_1.literal)(17),
31
+ SECURITY_ERR: (0, literal_js_1.literal)(18),
32
+ NETWORK_ERR: (0, literal_js_1.literal)(19),
33
+ ABORT_ERR: (0, literal_js_1.literal)(20),
34
+ URL_MISMATCH_ERR: (0, literal_js_1.literal)(21),
35
+ QUOTA_EXCEEDED_ERR: (0, literal_js_1.literal)(22),
36
+ TIMEOUT_ERR: (0, literal_js_1.literal)(23),
37
+ INVALID_NODE_TYPE_ERR: (0, literal_js_1.literal)(24),
38
+ DATA_CLONE_ERR: (0, literal_js_1.literal)(25),
39
+ });
@@ -12,7 +12,7 @@ const redactCredentialsInURL = (input, mask = 'REDACTED') => {
12
12
  }
13
13
  return url.toString();
14
14
  }
15
- catch (error) {
15
+ catch {
16
16
  return String(input);
17
17
  }
18
18
  };
@@ -2,16 +2,19 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.toPascalCase = toPascalCase;
4
4
  const capitalize_js_1 = require("./capitalize.js");
5
- const getType_js_1 = require("./getType.js");
6
5
  function toPascalCase(text, customWords) {
7
- const words = String(text).match(/[A-Z][a-z']+|\d+|[a-z']+/g);
8
- let fixedWords = words?.map((word) => (0, capitalize_js_1.capitalize)(word.replace(/'/g, '')));
9
- if (fixedWords && customWords && (0, getType_js_1.getType)(customWords) === 'Object') {
6
+ let words = String(text)
7
+ .replaceAll(/['.]/g, '')
8
+ .replaceAll(/[^a-z0-9]/gi, ' ')
9
+ .split(/(\s+)|(?<=\d)(?=[a-z])|(?<=[a-z])(?=\d)/i)
10
+ .filter((word) => word?.trim().length)
11
+ .map(capitalize_js_1.capitalize);
12
+ if (words && customWords && typeof customWords === 'object') {
10
13
  const replacements = new Map(Object.entries(customWords).map(([key, value]) => [key.toLowerCase(), value]));
11
14
  if (replacements.size) {
12
15
  const replaceCustomWords = (word) => replacements.get(word.toLowerCase()) ?? word;
13
- fixedWords = fixedWords.map(replaceCustomWords);
16
+ words = words.map(replaceCustomWords);
14
17
  }
15
18
  }
16
- return (fixedWords ? fixedWords.join('') : '');
19
+ return words.join('');
17
20
  }
@@ -1,5 +1,5 @@
1
1
  export function deepFreeze(input, partialOptions = {}) {
2
- const { filterProperties = new Set(['prototype', '__proto__']), doNotFreeze = new WeakSet(typeof globalThis !== 'undefined' ? [globalThis] : []), frozen = new WeakSet(), } = partialOptions;
2
+ const { filterProperties = new Set(['prototype', '__proto__']), doNotFreeze = new WeakSet([globalThis]), frozen = new WeakSet(), } = partialOptions;
3
3
  if (doNotFreeze.has(input)) {
4
4
  return input;
5
5
  }
@@ -9,9 +9,7 @@ export function deepFreeze(input, partialOptions = {}) {
9
9
  const freeze = (inputObject) => {
10
10
  if (Array.isArray(inputObject)) {
11
11
  inputObject.forEach((item) => {
12
- if (shouldFreeze(item)) {
13
- freeze(item);
14
- }
12
+ shouldFreeze(item) && freeze(item);
15
13
  });
16
14
  }
17
15
  else {
@@ -23,9 +21,7 @@ export function deepFreeze(input, partialOptions = {}) {
23
21
  }
24
22
  }
25
23
  }
26
- if (!frozen.has(inputObject)) {
27
- frozen.add(Object.freeze(inputObject));
28
- }
24
+ !frozen.has(inputObject) && frozen.add(Object.freeze(inputObject));
29
25
  return inputObject;
30
26
  };
31
27
  return freeze(input);
@@ -24,7 +24,7 @@ export const describeInput = (input) => {
24
24
  const url = new URL(input);
25
25
  return `${url.protocol.replace(':', '')} URL${url.username || url.password ? ' with credentials' : ''}`;
26
26
  }
27
- catch (error) {
27
+ catch {
28
28
  return 'Invalid URL';
29
29
  }
30
30
  }
@@ -43,12 +43,10 @@ export const describeInput = (input) => {
43
43
  if (Number.isInteger(input)) {
44
44
  return 'Integer';
45
45
  }
46
- if (Number.isFinite(input)) {
47
- return 'Finite Number';
48
- }
49
46
  if (Number.isNaN(input)) {
50
47
  return 'NaN';
51
48
  }
49
+ return 'Float';
52
50
  }
53
51
  }
54
52
  return getType(input);
@@ -1 +1,36 @@
1
- export const isTimeoutError = (error) => error instanceof DOMException && error.name === 'TimeoutError';
1
+ import { literal } from './factory/literal.js';
2
+ import { optional } from './factory/optional.js';
3
+ import { shape } from './factory/shape.js';
4
+ import { isNumber } from './isNumber.js';
5
+ import { isString } from './isString.js';
6
+ export const isTimeoutError = shape({
7
+ name: literal('TimeoutError'),
8
+ message: isString,
9
+ stack: optional(isString),
10
+ code: isNumber,
11
+ INDEX_SIZE_ERR: literal(1),
12
+ DOMSTRING_SIZE_ERR: literal(2),
13
+ HIERARCHY_REQUEST_ERR: literal(3),
14
+ WRONG_DOCUMENT_ERR: literal(4),
15
+ INVALID_CHARACTER_ERR: literal(5),
16
+ NO_DATA_ALLOWED_ERR: literal(6),
17
+ NO_MODIFICATION_ALLOWED_ERR: literal(7),
18
+ NOT_FOUND_ERR: literal(8),
19
+ NOT_SUPPORTED_ERR: literal(9),
20
+ INUSE_ATTRIBUTE_ERR: literal(10),
21
+ INVALID_STATE_ERR: literal(11),
22
+ SYNTAX_ERR: literal(12),
23
+ INVALID_MODIFICATION_ERR: literal(13),
24
+ NAMESPACE_ERR: literal(14),
25
+ INVALID_ACCESS_ERR: literal(15),
26
+ VALIDATION_ERR: literal(16),
27
+ TYPE_MISMATCH_ERR: literal(17),
28
+ SECURITY_ERR: literal(18),
29
+ NETWORK_ERR: literal(19),
30
+ ABORT_ERR: literal(20),
31
+ URL_MISMATCH_ERR: literal(21),
32
+ QUOTA_EXCEEDED_ERR: literal(22),
33
+ TIMEOUT_ERR: literal(23),
34
+ INVALID_NODE_TYPE_ERR: literal(24),
35
+ DATA_CLONE_ERR: literal(25),
36
+ });
@@ -9,7 +9,7 @@ export const redactCredentialsInURL = (input, mask = 'REDACTED') => {
9
9
  }
10
10
  return url.toString();
11
11
  }
12
- catch (error) {
12
+ catch {
13
13
  return String(input);
14
14
  }
15
15
  };
@@ -1,14 +1,17 @@
1
1
  import { capitalize } from './capitalize.js';
2
- import { getType } from './getType.js';
3
2
  export function toPascalCase(text, customWords) {
4
- const words = String(text).match(/[A-Z][a-z']+|\d+|[a-z']+/g);
5
- let fixedWords = words?.map((word) => capitalize(word.replace(/'/g, '')));
6
- if (fixedWords && customWords && getType(customWords) === 'Object') {
3
+ let words = String(text)
4
+ .replaceAll(/['.]/g, '')
5
+ .replaceAll(/[^a-z0-9]/gi, ' ')
6
+ .split(/(\s+)|(?<=\d)(?=[a-z])|(?<=[a-z])(?=\d)/i)
7
+ .filter((word) => word?.trim().length)
8
+ .map(capitalize);
9
+ if (words && customWords && typeof customWords === 'object') {
7
10
  const replacements = new Map(Object.entries(customWords).map(([key, value]) => [key.toLowerCase(), value]));
8
11
  if (replacements.size) {
9
12
  const replaceCustomWords = (word) => replacements.get(word.toLowerCase()) ?? word;
10
- fixedWords = fixedWords.map(replaceCustomWords);
13
+ words = words.map(replaceCustomWords);
11
14
  }
12
15
  }
13
- return (fixedWords ? fixedWords.join('') : '');
16
+ return words.join('');
14
17
  }
@@ -1 +1 @@
1
- export declare const isBinaryNumberString: import("../index.js").TypePredicateFn<`0b${number}` | `0B${number}`>;
1
+ export declare const isBinaryNumberString: import("../index.js").TypePredicateFn<`0B${number}` | `0b${number}`>;
@@ -1 +1 @@
1
- export declare const isHexNumberString: import("../index.js").TypePredicateFn<`0x${string}` | `0X${string}`>;
1
+ export declare const isHexNumberString: import("../index.js").TypePredicateFn<`0X${string}` | `0x${string}`>;
@@ -1 +1 @@
1
- export declare const isOctalNumberString: import("../index.js").TypePredicateFn<`0o${number}` | `0O${number}`>;
1
+ export declare const isOctalNumberString: import("../index.js").TypePredicateFn<`0O${number}` | `0o${number}`>;
@@ -1,2 +1,32 @@
1
- import type { TimeoutError } from '../types/errors.js';
2
- export declare const isTimeoutError: (error: unknown) => error is TimeoutError;
1
+ export declare const isTimeoutError: import("../index.js").TypePredicateFn<{
2
+ stack?: string | undefined;
3
+ readonly code: number;
4
+ readonly message: string;
5
+ name: "TimeoutError";
6
+ readonly INDEX_SIZE_ERR: 1;
7
+ readonly DOMSTRING_SIZE_ERR: 2;
8
+ readonly HIERARCHY_REQUEST_ERR: 3;
9
+ readonly WRONG_DOCUMENT_ERR: 4;
10
+ readonly INVALID_CHARACTER_ERR: 5;
11
+ readonly NO_DATA_ALLOWED_ERR: 6;
12
+ readonly NO_MODIFICATION_ALLOWED_ERR: 7;
13
+ readonly NOT_FOUND_ERR: 8;
14
+ readonly NOT_SUPPORTED_ERR: 9;
15
+ readonly INUSE_ATTRIBUTE_ERR: 10;
16
+ readonly INVALID_STATE_ERR: 11;
17
+ readonly SYNTAX_ERR: 12;
18
+ readonly INVALID_MODIFICATION_ERR: 13;
19
+ readonly NAMESPACE_ERR: 14;
20
+ readonly INVALID_ACCESS_ERR: 15;
21
+ readonly VALIDATION_ERR: 16;
22
+ readonly TYPE_MISMATCH_ERR: 17;
23
+ readonly SECURITY_ERR: 18;
24
+ readonly NETWORK_ERR: 19;
25
+ readonly ABORT_ERR: 20;
26
+ readonly URL_MISMATCH_ERR: 21;
27
+ readonly QUOTA_EXCEEDED_ERR: 22;
28
+ readonly TIMEOUT_ERR: 23;
29
+ readonly INVALID_NODE_TYPE_ERR: 24;
30
+ readonly DATA_CLONE_ERR: 25;
31
+ cause?: unknown;
32
+ }>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@webdeveric/utils",
3
3
  "description": "Just another collection of utilities.",
4
- "version": "0.74.0",
4
+ "version": "0.74.2",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -66,18 +66,18 @@
66
66
  "url": "https://github.com/webdeveric/utils/issues"
67
67
  },
68
68
  "homepage": "https://github.com/webdeveric/utils/#readme",
69
- "packageManager": "pnpm@10.18.0+sha512.e804f889f1cecc40d572db084eec3e4881739f8dec69c0ff10d2d1beff9a4e309383ba27b5b750059d7f4c149535b6cd0d2cb1ed3aeb739239a4284a68f40cfa",
69
+ "packageManager": "pnpm@10.30.3+sha512.c961d1e0a2d8e354ecaa5166b822516668b7f44cb5bd95122d590dd81922f606f5473b6d23ec4a5be05e7fcd18e8488d47d978bbe981872f1145d06e9a740017",
70
70
  "scripts": {
71
71
  "clean": "rimraf ./dist/",
72
72
  "prebuild": "pnpm clean",
73
73
  "build": "tsc --build tsconfig.cjs.json tsconfig.mjs.json --force",
74
74
  "postbuild": "echo '{\"type\":\"commonjs\"}' > ./dist/cjs/package.json && echo '{\"type\":\"module\"}' > ./dist/mjs/package.json && pnpm validate",
75
- "typecheck": "tsc --build tsconfig.mjs.json tsconfig.test.json --verbose --noEmit",
75
+ "typecheck": "tsc --build --verbose --noEmit",
76
76
  "lint": "eslint ./*.{js,cjs,mjs,ts,cts,mts} ./src/ ./bench/ ./test/ --ext .ts,.mjs,.cjs",
77
77
  "bench": "vitest bench",
78
78
  "test": "vitest --typecheck",
79
79
  "coverage": "vitest run --coverage --typecheck",
80
- "validate": "validate-package-exports --check --verify",
80
+ "validate": "validate-package-exports --check",
81
81
  "spellcheck": "cspell './{.github,src,bench,test}/**/*.{ts,json}' './*.{md,mjs,mts}' './package.json' --no-progress",
82
82
  "prepublishOnly": "pnpm typecheck && pnpm spellcheck && pnpm lint && pnpm coverage && pnpm build",
83
83
  "format": "prettier --write ./*.{js,json,md} ./src/ ./bench/ ./test/",
@@ -85,29 +85,29 @@
85
85
  },
86
86
  "prettier": "@webdeveric/prettier-config",
87
87
  "devDependencies": {
88
- "@commitlint/config-conventional": "^20.0.0",
89
- "@commitlint/types": "^20.0.0",
90
- "@types/node": "^22.18.7",
91
- "@vitest/coverage-v8": "^3.2.4",
92
- "@webdeveric/eslint-config-ts": "^0.11.0",
88
+ "@commitlint/config-conventional": "^20.4.3",
89
+ "@commitlint/types": "^20.4.3",
90
+ "@types/node": "^22.19.13",
91
+ "@vitest/coverage-v8": "^4.0.18",
92
+ "@webdeveric/eslint-config-ts": "^0.12.0",
93
93
  "@webdeveric/prettier-config": "^0.3.0",
94
- "commitlint": "^20.1.0",
95
- "commitlint-plugin-cspell": "^0.3.0",
96
- "conventional-changelog-conventionalcommits": "^9.1.0",
97
- "cspell": "^9.2.1",
94
+ "commitlint": "^20.4.3",
95
+ "commitlint-plugin-cspell": "^0.6.0",
96
+ "conventional-changelog-conventionalcommits": "^9.3.0",
97
+ "cspell": "^9.7.0",
98
98
  "eslint": "^8.57.1",
99
99
  "eslint-config-prettier": "^10.1.8",
100
100
  "eslint-import-resolver-typescript": "^4.4.4",
101
101
  "eslint-plugin-import": "^2.32.0",
102
102
  "husky": "^9.1.7",
103
- "jsdom": "^27.0.0",
104
- "lint-staged": "^16.2.3",
105
- "prettier": "^3.6.2",
106
- "rimraf": "^6.0.1",
103
+ "jsdom": "^28.1.0",
104
+ "lint-staged": "^16.3.2",
105
+ "prettier": "^3.8.1",
106
+ "rimraf": "^6.1.3",
107
107
  "semantic-release": "^24.2.9",
108
- "typescript": "^5.9.2",
109
- "validate-package-exports": "^0.14.0",
110
- "vitest": "^3.2.4"
108
+ "typescript": "6.0.0-dev.20260304",
109
+ "validate-package-exports": "^0.19.1",
110
+ "vitest": "^4.0.18"
111
111
  },
112
112
  "pnpm": {
113
113
  "onlyBuiltDependencies": [