@webdeveric/utils 0.46.0 → 0.48.0

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.
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertIsInt32 = assertIsInt32;
4
+ const isInt32_js_1 = require("../predicate/isInt32.js");
5
+ const getError_js_1 = require("./getError.js");
6
+ function assertIsInt32(input, error = 'input is not an Int32') {
7
+ if (!(0, isInt32_js_1.isInt32)(input)) {
8
+ throw (0, getError_js_1.getError)(error);
9
+ }
10
+ }
@@ -23,6 +23,7 @@ __exportStar(require("./assertIsBooleanArray.js"), exports);
23
23
  __exportStar(require("./assertIsDigitsString.js"), exports);
24
24
  __exportStar(require("./assertIsFiniteNumber.js"), exports);
25
25
  __exportStar(require("./assertIsFunction.js"), exports);
26
+ __exportStar(require("./assertIsInt32.js"), exports);
26
27
  __exportStar(require("./assertIsInteger.js"), exports);
27
28
  __exportStar(require("./assertIsIntString.js"), exports);
28
29
  __exportStar(require("./assertIsIterable.js"), exports);
package/dist/cjs/index.js CHANGED
@@ -49,6 +49,7 @@ __exportStar(require("./inRange.js"), exports);
49
49
  __exportStar(require("./isEmpty.js"), exports);
50
50
  __exportStar(require("./iterateForever.js"), exports);
51
51
  __exportStar(require("./joinStrings.js"), exports);
52
+ __exportStar(require("./jsonParse.js"), exports);
52
53
  __exportStar(require("./looksLikeURL.js"), exports);
53
54
  __exportStar(require("./normalize.js"), exports);
54
55
  __exportStar(require("./parseNumber.js"), exports);
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.jsonParse = jsonParse;
4
+ function jsonParse(input, reviver, assertionFn) {
5
+ const data = JSON.parse(input, reviver);
6
+ assertionFn?.(data);
7
+ return data;
8
+ }
@@ -25,6 +25,7 @@ __exportStar(require("./isBooleanArray.js"), exports);
25
25
  __exportStar(require("./isDigitsString.js"), exports);
26
26
  __exportStar(require("./isFiniteNumber.js"), exports);
27
27
  __exportStar(require("./isFunction.js"), exports);
28
+ __exportStar(require("./isInt32.js"), exports);
28
29
  __exportStar(require("./isInteger.js"), exports);
29
30
  __exportStar(require("./isIntString.js"), exports);
30
31
  __exportStar(require("./isISODateString.js"), exports);
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isInt32 = isInt32;
4
+ function isInt32(input) {
5
+ const int32Min = -2_147_483_648;
6
+ const int32Max = 2_147_483_647;
7
+ return typeof input === 'number' && Number.isInteger(input) && input >= int32Min && input <= int32Max;
8
+ }
@@ -19,6 +19,7 @@ __exportStar(require("./branded.js"), exports);
19
19
  __exportStar(require("./common.js"), exports);
20
20
  __exportStar(require("./date-time.js"), exports);
21
21
  __exportStar(require("./functions.js"), exports);
22
+ __exportStar(require("./numbers.js"), exports);
22
23
  __exportStar(require("./objects.js"), exports);
23
24
  __exportStar(require("./records.js"), exports);
24
25
  __exportStar(require("./strings.js"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ import { isInt32 } from '../predicate/isInt32.js';
2
+ import { getError } from './getError.js';
3
+ export function assertIsInt32(input, error = 'input is not an Int32') {
4
+ if (!isInt32(input)) {
5
+ throw getError(error);
6
+ }
7
+ }
@@ -7,6 +7,7 @@ export * from './assertIsBooleanArray.js';
7
7
  export * from './assertIsDigitsString.js';
8
8
  export * from './assertIsFiniteNumber.js';
9
9
  export * from './assertIsFunction.js';
10
+ export * from './assertIsInt32.js';
10
11
  export * from './assertIsInteger.js';
11
12
  export * from './assertIsIntString.js';
12
13
  export * from './assertIsIterable.js';
package/dist/mjs/index.js CHANGED
@@ -33,6 +33,7 @@ export * from './inRange.js';
33
33
  export * from './isEmpty.js';
34
34
  export * from './iterateForever.js';
35
35
  export * from './joinStrings.js';
36
+ export * from './jsonParse.js';
36
37
  export * from './looksLikeURL.js';
37
38
  export * from './normalize.js';
38
39
  export * from './parseNumber.js';
@@ -0,0 +1,5 @@
1
+ export function jsonParse(input, reviver, assertionFn) {
2
+ const data = JSON.parse(input, reviver);
3
+ assertionFn?.(data);
4
+ return data;
5
+ }
@@ -9,6 +9,7 @@ export * from './isBooleanArray.js';
9
9
  export * from './isDigitsString.js';
10
10
  export * from './isFiniteNumber.js';
11
11
  export * from './isFunction.js';
12
+ export * from './isInt32.js';
12
13
  export * from './isInteger.js';
13
14
  export * from './isIntString.js';
14
15
  export * from './isISODateString.js';
@@ -0,0 +1,5 @@
1
+ export function isInt32(input) {
2
+ const int32Min = -2_147_483_648;
3
+ const int32Max = 2_147_483_647;
4
+ return typeof input === 'number' && Number.isInteger(input) && input >= int32Min && input <= int32Max;
5
+ }
@@ -3,6 +3,7 @@ export * from './branded.js';
3
3
  export * from './common.js';
4
4
  export * from './date-time.js';
5
5
  export * from './functions.js';
6
+ export * from './numbers.js';
6
7
  export * from './objects.js';
7
8
  export * from './records.js';
8
9
  export * from './strings.js';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { Int32 } from '../types/numbers.js';
2
+ export declare function assertIsInt32(input: unknown, error?: string | Error): asserts input is Int32;
@@ -7,6 +7,7 @@ export * from './assertIsBooleanArray.js';
7
7
  export * from './assertIsDigitsString.js';
8
8
  export * from './assertIsFiniteNumber.js';
9
9
  export * from './assertIsFunction.js';
10
+ export * from './assertIsInt32.js';
10
11
  export * from './assertIsInteger.js';
11
12
  export * from './assertIsIntString.js';
12
13
  export * from './assertIsIterable.js';
@@ -33,6 +33,7 @@ export * from './inRange.js';
33
33
  export * from './isEmpty.js';
34
34
  export * from './iterateForever.js';
35
35
  export * from './joinStrings.js';
36
+ export * from './jsonParse.js';
36
37
  export * from './looksLikeURL.js';
37
38
  export * from './normalize.js';
38
39
  export * from './parseNumber.js';
@@ -0,0 +1,4 @@
1
+ import type { TypeAssertionFn } from './types/functions.js';
2
+ export type JsonReviver = Parameters<JSON['parse']>[1];
3
+ export declare function jsonParse(input: string, reviver?: JsonReviver): unknown;
4
+ export declare function jsonParse<T>(input: string, reviver: JsonReviver | undefined, assertionFn: TypeAssertionFn<T>): T;
@@ -9,6 +9,7 @@ export * from './isBooleanArray.js';
9
9
  export * from './isDigitsString.js';
10
10
  export * from './isFiniteNumber.js';
11
11
  export * from './isFunction.js';
12
+ export * from './isInt32.js';
12
13
  export * from './isInteger.js';
13
14
  export * from './isIntString.js';
14
15
  export * from './isISODateString.js';
@@ -0,0 +1,2 @@
1
+ import type { Int32 } from '../types/numbers.js';
2
+ export declare function isInt32(input: unknown): input is Int32;
@@ -1,2 +1,2 @@
1
1
  import type { TypePredicateFn } from '../types/functions.js';
2
- export declare const createStringLengthRangePredicate: (min: number, max?: number) => TypePredicateFn<string>;
2
+ export declare const createStringLengthRangePredicate: <Type extends string = string>(min: number, max?: number) => TypePredicateFn<Type>;
@@ -1,6 +1,11 @@
1
+ import type { Primitive } from './common.js';
1
2
  declare const brand: unique symbol;
2
- type Brand<Id> = {
3
+ export type Brand<Id> = {
3
4
  [brand]: Id;
4
5
  };
5
6
  export type Branded<Type, Id> = Type & Brand<Id>;
7
+ export type Unbranded<Type> = Type extends Branded<infer Inner, unknown> ? Omit<Inner, typeof brand> : Type;
8
+ export type RemoveBranding<Type> = Type extends Primitive ? Unbranded<Type> : {
9
+ [Property in keyof Type]: Type extends Primitive ? Unbranded<Type[Property]> : RemoveBranding<Type[Property]>;
10
+ };
6
11
  export {};
@@ -3,6 +3,7 @@ export * from './branded.js';
3
3
  export * from './common.js';
4
4
  export * from './date-time.js';
5
5
  export * from './functions.js';
6
+ export * from './numbers.js';
6
7
  export * from './objects.js';
7
8
  export * from './records.js';
8
9
  export * from './strings.js';
@@ -0,0 +1,2 @@
1
+ import type { Branded } from './branded.js';
2
+ export type Int32 = Branded<number, 'Int32'>;
@@ -12,3 +12,4 @@ export type FirstChar<Type extends string> = Type extends `${infer First}${infer
12
12
  export type AddSpaceAroundNumbers<Type extends string> = Type extends `${infer First}${infer Rest}` ? Rest extends EmptyString ? First : First extends AlphaCharacter | Capitalize<AlphaCharacter> ? FirstChar<Rest> extends NumericCharacter ? `${First}${Space}${AddSpaceAroundNumbers<Rest>}` : `${First}${AddSpaceAroundNumbers<Rest>}` : First extends NumericCharacter ? FirstChar<Rest> extends AlphaCharacter | Capitalize<AlphaCharacter> ? `${First}${Space}${AddSpaceAroundNumbers<Rest>}` : `${First}${AddSpaceAroundNumbers<Rest>}` : `${First}${AddSpaceAroundNumbers<Rest>}` : never;
13
13
  export type CamelCase<Type extends string, Delimiter extends string = Space> = Type extends `${infer Left}${Delimiter}${infer Right}` ? `${Left}${CamelCase<Capitalize<Right>, Delimiter>}` : Type;
14
14
  export type PascalCase<Type extends string, Delimiter extends string = Space> = Capitalize<CamelCase<AlphanumericOnly<AddSpaceAroundNumbers<Strip<Type, "'">>>, Delimiter>>;
15
+ export type StringLength<Type extends string, Accumulator extends never[] = []> = string extends Type ? never : Type extends `${infer _}${infer Rest}` ? StringLength<Rest, [never, ...Accumulator]> : Accumulator['length'];
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.46.0",
4
+ "version": "0.48.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -66,7 +66,7 @@
66
66
  "url": "https://github.com/webdeveric/utils/issues"
67
67
  },
68
68
  "homepage": "https://github.com/webdeveric/utils/#readme",
69
- "packageManager": "pnpm@9.15.4+sha512.b2dc20e2fc72b3e18848459b37359a32064663e5627a51e4c74b2c29dd8e8e0491483c3abb40789cfd578bf362fb6ba8261b05f0387d76792ed6e23ea3b1b6a0",
69
+ "packageManager": "pnpm@10.4.1+sha512.c753b6c3ad7afa13af388fa6d808035a008e30ea9993f58c6663e2bc5ff21679aa834db094987129aa4d488b86df57f7b634981b2f827cdcacc698cc0cfb88af",
70
70
  "scripts": {
71
71
  "clean": "rimraf ./dist/",
72
72
  "prebuild": "pnpm clean",
@@ -85,28 +85,28 @@
85
85
  },
86
86
  "prettier": "@webdeveric/prettier-config",
87
87
  "devDependencies": {
88
- "@commitlint/config-conventional": "^19.6.0",
88
+ "@commitlint/config-conventional": "^19.7.1",
89
89
  "@commitlint/types": "^19.5.0",
90
- "@types/node": "^22.12.0",
91
- "@vitest/coverage-v8": "^3.0.4",
90
+ "@types/node": "^22.13.4",
91
+ "@vitest/coverage-v8": "^3.0.6",
92
92
  "@webdeveric/eslint-config-ts": "^0.11.0",
93
93
  "@webdeveric/prettier-config": "^0.3.0",
94
- "commitlint": "^19.6.1",
94
+ "commitlint": "^19.7.1",
95
95
  "commitlint-plugin-cspell": "^0.1.1",
96
96
  "conventional-changelog-conventionalcommits": "^8.0.0",
97
- "cspell": "^8.17.3",
97
+ "cspell": "^8.17.4",
98
98
  "eslint": "^8.57.1",
99
99
  "eslint-config-prettier": "^10.0.1",
100
- "eslint-import-resolver-typescript": "^3.7.0",
100
+ "eslint-import-resolver-typescript": "^3.8.2",
101
101
  "eslint-plugin-import": "^2.31.0",
102
102
  "husky": "^9.1.7",
103
103
  "jsdom": "^26.0.0",
104
104
  "lint-staged": "^15.4.3",
105
- "prettier": "^3.4.2",
105
+ "prettier": "^3.5.1",
106
106
  "rimraf": "^6.0.1",
107
- "semantic-release": "^24.2.1",
107
+ "semantic-release": "^24.2.3",
108
108
  "typescript": "^5.7.3",
109
109
  "validate-package-exports": "^0.8.0",
110
- "vitest": "^3.0.4"
110
+ "vitest": "^3.0.6"
111
111
  }
112
112
  }