ts-data-forge 3.2.0 → 3.3.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.
package/README.md CHANGED
@@ -132,7 +132,7 @@ Here are some examples of how to use utilities from `ts-data-forge`:
132
132
 
133
133
  The `expectType` utility allows you to make assertions about types at compile time. This is useful for ensuring type correctness in complex type manipulations or when refactoring.
134
134
 
135
- ```typescript
135
+ ```tsx
136
136
  import { expectType } from 'ts-data-forge';
137
137
 
138
138
  type User = { id: number; name: string };
@@ -158,7 +158,7 @@ expectType<User, any>('!='); // Error: Comparisons with `any` are also strictly
158
158
 
159
159
  Handle nullable values and error-prone operations safely.
160
160
 
161
- ```typescript
161
+ ```tsx
162
162
  import { match, Optional, pipe, Result } from 'ts-data-forge';
163
163
 
164
164
  // Optional for nullable values
@@ -212,7 +212,7 @@ assert(processResult(Result.err('Failed')) === 'Error: Failed');
212
212
 
213
213
  The `Num` object provides safe and convenient functions for numerical operations.
214
214
 
215
- ```typescript
215
+ ```tsx
216
216
  import { Num } from 'ts-data-forge';
217
217
 
218
218
  // Basic conversions
@@ -252,7 +252,7 @@ if (Num.isNonZero(value)) {
252
252
 
253
253
  `ts-data-forge` provides branded number types that enforce specific constraints at the type level.
254
254
 
255
- ```typescript
255
+ ```tsx
256
256
  import {
257
257
  asFiniteNumber,
258
258
  asInt,
@@ -314,7 +314,7 @@ assert(randomInt16 <= 32767);
314
314
 
315
315
  The `Arr` object provides a rich set of functions for array manipulation.
316
316
 
317
- ```typescript
317
+ ```tsx
318
318
  import { Arr, expectType, Optional } from 'ts-data-forge';
319
319
 
320
320
  const numbers: readonly number[] = [1, 2, 3, 4, 5, 2, 3];
@@ -369,7 +369,7 @@ if (Optional.isSome(oldestPerson)) {
369
369
 
370
370
  Type-safe, immutable data structures.
371
371
 
372
- ```typescript
372
+ ```tsx
373
373
  import { Arr, IMap, ISet, Optional } from 'ts-data-forge';
374
374
 
375
375
  // IMap usage - immutable operations
@@ -415,7 +415,7 @@ assert(setWithItems.size === 2);
415
415
 
416
416
  Safe type narrowing with comprehensive type guards.
417
417
 
418
- ```typescript
418
+ ```tsx
419
419
  import { hasKey, isNonNullObject, isRecord } from 'ts-data-forge';
420
420
 
421
421
  const processData = (data: unknown): string | undefined => {
@@ -448,7 +448,7 @@ assert(processData('not an object') === undefined);
448
448
 
449
449
  Generate ranges for iteration and array creation.
450
450
 
451
- ```typescript
451
+ ```tsx
452
452
  import { range } from 'ts-data-forge';
453
453
 
454
454
  // Traditional for loop using range
@@ -0,0 +1,2 @@
1
+ export * from './index.mjs';
2
+ //# sourceMappingURL=entry-point.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entry-point.d.mts","sourceRoot":"","sources":["../src/entry-point.mts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
@@ -0,0 +1,61 @@
1
+ export { Arr } from './array/array-utils.mjs';
2
+ export { IMapMapped } from './collections/imap-mapped.mjs';
3
+ export { IMap } from './collections/imap.mjs';
4
+ export { ISetMapped } from './collections/iset-mapped.mjs';
5
+ export { ISet } from './collections/iset.mjs';
6
+ export { createQueue } from './collections/queue.mjs';
7
+ export { createStack } from './collections/stack.mjs';
8
+ export { expectType } from './expect-type.mjs';
9
+ export { match } from './functional/match.mjs';
10
+ export { Optional } from './functional/optional.mjs';
11
+ export { pipe } from './functional/pipe.mjs';
12
+ export { Result } from './functional/result.mjs';
13
+ export { hasKey } from './guard/has-key.mjs';
14
+ export { isNonEmptyString } from './guard/is-non-empty-string.mjs';
15
+ export { isNonNullObject } from './guard/is-non-null-object.mjs';
16
+ export { isPrimitive } from './guard/is-primitive.mjs';
17
+ export { isRecord } from './guard/is-record.mjs';
18
+ export { isBigint, isBoolean, isNonNullish, isNotBigint, isNotBoolean, isNotNull, isNotNumber, isNotString, isNotSymbol, isNotUndefined, isNull, isNullish, isNumber, isString, isSymbol, isUndefined } from './guard/is-type.mjs';
19
+ export { keyIsIn } from './guard/key-is-in.mjs';
20
+ export { range } from './iterator/range.mjs';
21
+ export { Json } from './json/json.mjs';
22
+ export { FiniteNumber, asFiniteNumber, isFiniteNumber } from './number/branded-types/finite-number.mjs';
23
+ export { Int, asInt, isInt } from './number/branded-types/int.mjs';
24
+ export { Int16, asInt16, isInt16 } from './number/branded-types/int16.mjs';
25
+ export { Int32, asInt32, isInt32 } from './number/branded-types/int32.mjs';
26
+ export { NonNegativeFiniteNumber, asNonNegativeFiniteNumber, isNonNegativeFiniteNumber } from './number/branded-types/non-negative-finite-number.mjs';
27
+ export { NonNegativeInt16, asNonNegativeInt16, isNonNegativeInt16 } from './number/branded-types/non-negative-int16.mjs';
28
+ export { NonNegativeInt32, asNonNegativeInt32, isNonNegativeInt32 } from './number/branded-types/non-negative-int32.mjs';
29
+ export { NonZeroFiniteNumber, asNonZeroFiniteNumber, isNonZeroFiniteNumber } from './number/branded-types/non-zero-finite-number.mjs';
30
+ export { NonZeroInt, asNonZeroInt, isNonZeroInt } from './number/branded-types/non-zero-int.mjs';
31
+ export { NonZeroInt16, asNonZeroInt16, isNonZeroInt16 } from './number/branded-types/non-zero-int16.mjs';
32
+ export { NonZeroInt32, asNonZeroInt32, isNonZeroInt32 } from './number/branded-types/non-zero-int32.mjs';
33
+ export { NonZeroSafeInt, asNonZeroSafeInt, isNonZeroSafeInt } from './number/branded-types/non-zero-safe-int.mjs';
34
+ export { NonZeroUint16, asNonZeroUint16, isNonZeroUint16 } from './number/branded-types/non-zero-uint16.mjs';
35
+ export { NonZeroUint32, asNonZeroUint32, isNonZeroUint32 } from './number/branded-types/non-zero-uint32.mjs';
36
+ export { PositiveFiniteNumber, asPositiveFiniteNumber, isPositiveFiniteNumber } from './number/branded-types/positive-finite-number.mjs';
37
+ export { PositiveInt, asPositiveInt, isPositiveInt } from './number/branded-types/positive-int.mjs';
38
+ export { PositiveInt16, asPositiveInt16, isPositiveInt16 } from './number/branded-types/positive-int16.mjs';
39
+ export { PositiveInt32, asPositiveInt32, isPositiveInt32 } from './number/branded-types/positive-int32.mjs';
40
+ export { PositiveSafeInt, asPositiveSafeInt, isPositiveSafeInt } from './number/branded-types/positive-safe-int.mjs';
41
+ export { PositiveUint16, asPositiveUint16, isPositiveUint16 } from './number/branded-types/positive-uint16.mjs';
42
+ export { PositiveUint32, asPositiveUint32, isPositiveUint32 } from './number/branded-types/positive-uint32.mjs';
43
+ export { SafeInt, asSafeInt, isSafeInt } from './number/branded-types/safe-int.mjs';
44
+ export { SafeUint, asSafeUint, isSafeUint } from './number/branded-types/safe-uint.mjs';
45
+ export { Uint, asUint, isUint } from './number/branded-types/uint.mjs';
46
+ export { Uint16, asUint16, isUint16 } from './number/branded-types/uint16.mjs';
47
+ export { Uint32, asUint32, isUint32 } from './number/branded-types/uint32.mjs';
48
+ export { Int8, asInt8, isInt8 } from './number/enum/int8.mjs';
49
+ export { Uint8, asUint8, isUint8 } from './number/enum/uint8.mjs';
50
+ export { Num } from './number/num.mjs';
51
+ export { TsDataForgeInternals } from './number/refined-number-utils.mjs';
52
+ export { Obj } from './object/object.mjs';
53
+ export { castDeepMutable, castMutable } from './others/cast-mutable.mjs';
54
+ export { castDeepReadonly, castReadonly } from './others/cast-readonly.mjs';
55
+ export { ifThen } from './others/if-then.mjs';
56
+ export { mapNullable } from './others/map-nullable.mjs';
57
+ export { memoizeFunction } from './others/memoize-function.mjs';
58
+ export { tp } from './others/tuple.mjs';
59
+ export { unknownToString } from './others/unknown-to-string.mjs';
60
+ export { createPromise } from './promise/promise.mjs';
61
+ //# sourceMappingURL=entry-point.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entry-point.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"unknown-to-string.d.mts","sourceRoot":"","sources":["../../src/others/unknown-to-string.mts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8IG;AACH,eAAO,MAAM,eAAe,GAC1B,OAAO,OAAO,EACd,UAAU,OAAO,CAAC,QAAQ,CAAC;IAAE,iBAAiB,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC,KAC1D,MA+BF,CAAC"}
1
+ {"version":3,"file":"unknown-to-string.d.mts","sourceRoot":"","sources":["../../src/others/unknown-to-string.mts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8IG;AACH,eAAO,MAAM,eAAe,GAC1B,OAAO,OAAO,EACd,UAAU,OAAO,CAAC,QAAQ,CAAC;IAAE,iBAAiB,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC,KAC1D,MAiCF,CAAC"}
@@ -147,8 +147,9 @@ const unknownToString = (value, options) => {
147
147
  switch (typeof value) {
148
148
  case 'string':
149
149
  return value;
150
- case 'number':
151
150
  case 'bigint':
151
+ return `${value.toString()}n`;
152
+ case 'number':
152
153
  case 'boolean':
153
154
  case 'symbol':
154
155
  case 'function':
@@ -1 +1 @@
1
- {"version":3,"file":"unknown-to-string.mjs","sources":["../../src/others/unknown-to-string.mts"],"sourcesContent":[null],"names":[],"mappings":";;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8IG;MACU,eAAe,GAAG,CAC7B,KAAc,EACd,OAA2D,KACjD;I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AA,KAAK,QAAQ;AACb,QAAA,KAAK,UAAU;AACb,YAAA,OAAO,KAAK,CAAC,QAAQ,EAAE;AAEzB,QAAA,KAAK,QAAQ;AACX,YAAA,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE;AACxB,gBAAA,OAAO,MAAM;YACf;AACA,YAAA,IAAI;AACF,gBAAA,MAAM,WAAW,GACf,OAAO,EAAE,iBAAiB,KAAK;sBAC3B,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,SAAS,EAAE,CAAC;AACpC,sBAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;AAC3B,gBAAA,OAAO,WAAW;YACpB;YAAE,OAAO,KAAK,EAAE;gBACd,OAAO,KAAK,YAAY;sBACpB,KAAK,CAAC;sBACN,gCAAgC;YACtC;AAEF,QAAA,KAAK,WAAW;AACd,YAAA,OAAO,WAAW;;AAExB;;;;"}
package/dist/types.d.mts CHANGED
@@ -1,2 +1,2 @@
1
1
  import './globals.d.mts';
2
- export * from './index.mjs';
2
+ export * from './entry-point.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-data-forge",
3
- "version": "3.2.0",
3
+ "version": "3.3.0",
4
4
  "private": false,
5
5
  "keywords": [
6
6
  "typescript",
@@ -22,11 +22,11 @@
22
22
  ".": {
23
23
  "import": {
24
24
  "types": "./dist/types.d.mts",
25
- "default": "./dist/index.mjs"
25
+ "default": "./dist/entry-point.mjs"
26
26
  }
27
27
  }
28
28
  },
29
- "module": "./dist/index.mjs",
29
+ "module": "./dist/entry-point.mjs",
30
30
  "types": "./dist/types.d.mts",
31
31
  "files": [
32
32
  "src",
@@ -35,30 +35,26 @@
35
35
  "LICENSE"
36
36
  ],
37
37
  "scripts": {
38
- "build": "tsx ./scripts/cmd/build.mjs",
39
- "check-all": "tsx ./scripts/cmd/check-all.mjs",
40
- "check:ext": "tsx ./scripts/cmd/check-ext.mjs",
38
+ "build": "tsx ./scripts/cmd/build.mts",
39
+ "check-all": "tsx ./scripts/cmd/check-all.mts",
40
+ "check:ext": "tsx ./scripts/cmd/check-ext.mts",
41
41
  "cspell": "cspell \"**\" --gitignore --gitignore-root ./ --no-progress",
42
- "doc": "tsx ./scripts/cmd/gen-docs.mjs",
42
+ "doc": "tsx ./scripts/cmd/gen-docs.mts",
43
+ "doc:embed": "tsx ./scripts/cmd/embed-samples.mts",
43
44
  "fmt": "format-diff-from origin/main",
44
45
  "fmt:full": "prettier --write .",
45
- "gi": "gen-index-ts ./src --index-ext .mts --export-ext .mjs --target-ext .mts --target-ext .tsx --fmt 'npm run fmt'",
46
+ "gi": "gen-index-ts ./src --index-ext .mts --export-ext .mjs --target-ext .mts --target-ext .tsx --exclude entry-point.mts --fmt 'npm run fmt'",
46
47
  "lint": "eslint .",
47
48
  "lint:fix": "eslint . --fix",
48
- "lint:samples": "eslint ./samples",
49
49
  "md": "markdownlint-cli2",
50
50
  "test": "npm run z:vitest -- run",
51
51
  "test:cov": "npm run z:vitest -- run --coverage",
52
52
  "test:cov:ui": "vite preview --outDir ./coverage",
53
- "test:samples": "vitest --config ./samples/vitest.config.ts",
54
53
  "test:ui": "npm run z:vitest -- --ui",
55
54
  "testw": "npm run z:vitest -- watch",
56
- "testw:samples": "npm run test:samples -- watch",
57
55
  "tsc": "tsc --noEmit",
58
56
  "tscw": "tsc --noEmit --watch -p ./tsconfig.json",
59
- "tscw:samples": "tsc --noEmit --watch -p ./samples/tsconfig.json",
60
57
  "type-check": "tsc --noEmit",
61
- "type-check:samples": "tsc --noEmit -p ./samples/tsconfig.json",
62
58
  "update-packages": "npx npm-check-updates -u --install always",
63
59
  "z:vitest": "vitest --config ./configs/vitest.config.ts"
64
60
  },
@@ -68,7 +64,7 @@
68
64
  "devDependencies": {
69
65
  "@emotion/react": "^11.14.0",
70
66
  "@emotion/styled": "^11.14.1",
71
- "@eslint/js": "^9.34.0",
67
+ "@eslint/js": "^9.35.0",
72
68
  "@mui/material": "^7.3.1",
73
69
  "@rollup/plugin-replace": "^6.0.2",
74
70
  "@rollup/plugin-strip": "^3.0.4",
@@ -77,15 +73,15 @@
77
73
  "@semantic-release/commit-analyzer": "^13.0.1",
78
74
  "@semantic-release/exec": "^7.1.0",
79
75
  "@semantic-release/git": "^10.0.1",
80
- "@semantic-release/github": "^11.0.4",
76
+ "@semantic-release/github": "^11.0.6",
81
77
  "@semantic-release/npm": "^12.0.2",
82
78
  "@semantic-release/release-notes-generator": "^14.0.3",
83
- "@types/node": "^24.3.0",
79
+ "@types/node": "^24.3.1",
84
80
  "@vitest/coverage-v8": "^3.2.4",
85
81
  "@vitest/ui": "^3.2.4",
86
82
  "conventional-changelog-conventionalcommits": "^9.1.0",
87
- "cspell": "^9.2.0",
88
- "eslint": "^9.34.0",
83
+ "cspell": "^9.2.1",
84
+ "eslint": "^9.35.0",
89
85
  "eslint-import-resolver-typescript": "4.4.4",
90
86
  "eslint-plugin-array-func": "5.0.2",
91
87
  "eslint-plugin-functional": "9.0.2",
@@ -93,7 +89,7 @@
93
89
  "eslint-plugin-prefer-arrow-functions": "3.6.2",
94
90
  "eslint-plugin-promise": "7.2.1",
95
91
  "eslint-plugin-security": "3.0.1",
96
- "eslint-plugin-unicorn": "60.0.0",
92
+ "eslint-plugin-unicorn": "61.0.2",
97
93
  "eslint-plugin-vitest": "0.5.4",
98
94
  "fast-glob": "^3.3.3",
99
95
  "immer": "^10.1.1",
@@ -101,15 +97,15 @@
101
97
  "prettier": "^3.6.2",
102
98
  "prettier-plugin-organize-imports": "^4.2.0",
103
99
  "prettier-plugin-packagejson": "^2.5.19",
104
- "rollup": "^4.48.0",
100
+ "rollup": "^4.50.1",
105
101
  "semantic-release": "^24.2.7",
106
- "ts-repo-utils": "^6.0.3",
102
+ "ts-repo-utils": "^7.5.0",
107
103
  "tslib": "^2.8.1",
108
- "tsx": "^4.20.4",
104
+ "tsx": "^4.20.5",
109
105
  "typedoc": "^0.28.10",
110
106
  "typedoc-plugin-markdown": "^4.8.1",
111
107
  "typescript": "^5.9.2",
112
- "typescript-eslint": "^8.40.0",
108
+ "typescript-eslint": "^8.43.0",
113
109
  "vitest": "^3.2.4"
114
110
  },
115
111
  "peerDependencies": {
@@ -0,0 +1 @@
1
+ export * from './index.mjs';
@@ -22,7 +22,6 @@ describe('isRecord', () => {
22
22
  const unk: unknown = obj;
23
23
  const res = isRecord(unk);
24
24
 
25
- // eslint-disable-next-line @typescript-eslint/no-empty-object-type
26
25
  expectType<typeof obj, {}>('=');
27
26
  expectType<typeof res, boolean>('=');
28
27
 
@@ -151,8 +151,10 @@ export const unknownToString = (
151
151
  case 'string':
152
152
  return value;
153
153
 
154
- case 'number':
155
154
  case 'bigint':
155
+ return `${value.toString()}n`;
156
+
157
+ case 'number':
156
158
  case 'boolean':
157
159
  case 'symbol':
158
160
  case 'function':
@@ -77,6 +77,6 @@ describe('unknownToString', () => {
77
77
 
78
78
  test('BigInt value', () => {
79
79
  const result = unknownToString(BigInt(123));
80
- expect(result).toBe('123');
80
+ expect(result).toBe('123n');
81
81
  });
82
82
  });