ts-data-forge 9.0.1 → 10.0.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.
Files changed (50) hide show
  1. package/README.md +1 -1
  2. package/dist/array/impl/array-utils-creation.d.mts +4 -4
  3. package/dist/array/impl/array-utils-creation.d.mts.map +1 -1
  4. package/dist/array/impl/array-utils-creation.mjs.map +1 -1
  5. package/dist/array/impl/array-utils-modification.d.mts +7 -7
  6. package/dist/array/impl/array-utils-modification.d.mts.map +1 -1
  7. package/dist/array/impl/array-utils-modification.mjs.map +1 -1
  8. package/dist/array/impl/array-utils-transformation.d.mts +4 -4
  9. package/dist/array/impl/array-utils-transformation.d.mts.map +1 -1
  10. package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
  11. package/dist/array/impl/array-utils-validation.d.mts +17 -17
  12. package/dist/array/impl/array-utils-validation.d.mts.map +1 -1
  13. package/dist/array/impl/array-utils-validation.mjs +5 -5
  14. package/dist/array/impl/array-utils-validation.mjs.map +1 -1
  15. package/dist/array/impl/index.mjs +1 -1
  16. package/dist/entry-point.mjs +2 -0
  17. package/dist/entry-point.mjs.map +1 -1
  18. package/dist/guard/as-length-bounded-array.d.mts +117 -0
  19. package/dist/guard/as-length-bounded-array.d.mts.map +1 -0
  20. package/dist/guard/as-length-bounded-array.mjs +37 -0
  21. package/dist/guard/as-length-bounded-array.mjs.map +1 -0
  22. package/dist/guard/index.d.mts +2 -0
  23. package/dist/guard/index.d.mts.map +1 -1
  24. package/dist/guard/index.mjs +2 -0
  25. package/dist/guard/index.mjs.map +1 -1
  26. package/dist/guard/is-length-bounded-array.d.mts +159 -0
  27. package/dist/guard/is-length-bounded-array.d.mts.map +1 -0
  28. package/dist/guard/is-length-bounded-array.mjs +7 -0
  29. package/dist/guard/is-length-bounded-array.mjs.map +1 -0
  30. package/dist/guard/is-length-bounded-string.d.mts +5 -6
  31. package/dist/guard/is-length-bounded-string.d.mts.map +1 -1
  32. package/dist/guard/is-length-bounded-string.mjs.map +1 -1
  33. package/dist/index.mjs +2 -0
  34. package/dist/index.mjs.map +1 -1
  35. package/package.json +7 -7
  36. package/src/array/impl/array-utils-creation.mts +3 -3
  37. package/src/array/impl/array-utils-modification.mts +7 -7
  38. package/src/array/impl/array-utils-modification.test.mts +4 -4
  39. package/src/array/impl/array-utils-transformation.mts +4 -4
  40. package/src/array/impl/array-utils-transformation.test.mts +7 -7
  41. package/src/array/impl/array-utils-validation.mts +24 -24
  42. package/src/array/impl/array-utils-validation.test.mts +94 -92
  43. package/src/collections/queue.test.mts +1 -1
  44. package/src/guard/as-length-bounded-array.mts +190 -0
  45. package/src/guard/as-length-bounded-array.test.mts +118 -0
  46. package/src/guard/index.mts +2 -0
  47. package/src/guard/is-length-bounded-array.mts +195 -0
  48. package/src/guard/is-length-bounded-array.test.mts +169 -0
  49. package/src/guard/is-length-bounded-string.mts +6 -6
  50. package/src/object/object.test.mts +3 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-data-forge",
3
- "version": "9.0.1",
3
+ "version": "10.0.0",
4
4
  "private": false,
5
5
  "keywords": [
6
6
  "typescript",
@@ -86,12 +86,12 @@
86
86
  },
87
87
  "dependencies": {
88
88
  "@sindresorhus/is": "^8.1.0",
89
- "ts-type-forge": "^5.0.0"
89
+ "ts-type-forge": "^6.0.0"
90
90
  },
91
91
  "devDependencies": {
92
92
  "@emotion/react": "11.14.0",
93
93
  "@emotion/styled": "11.14.1",
94
- "@mui/material": "9.1.2",
94
+ "@mui/material": "9.2.0",
95
95
  "@rollup/plugin-replace": "6.0.3",
96
96
  "@rollup/plugin-strip": "3.0.4",
97
97
  "@semantic-release/changelog": "6.0.3",
@@ -104,7 +104,7 @@
104
104
  "@types/node": "26.1.0",
105
105
  "@types/react": "19.2.17",
106
106
  "@vitest/browser-playwright": "4.1.9",
107
- "@vitest/coverage-v8": "4.1.9",
107
+ "@vitest/coverage-v8": "4.1.10",
108
108
  "@vitest/ui": "4.1.9",
109
109
  "conventional-changelog-conventionalcommits": "10.2.0",
110
110
  "cspell": "10.0.1",
@@ -113,7 +113,7 @@
113
113
  "eslint": "9.39.4",
114
114
  "eslint-config-typed": "5.3.0",
115
115
  "github-settings-as-code": "1.2.9",
116
- "immer": "11.1.9",
116
+ "immer": "11.1.11",
117
117
  "jiti": "2.7.0",
118
118
  "markdownlint": "0.41.0",
119
119
  "markdownlint-cli2": "0.23.0",
@@ -134,12 +134,12 @@
134
134
  "typescript": "6.0.3",
135
135
  "typescript-native": "npm:typescript@7.0.1-rc",
136
136
  "vite": "8.1.3",
137
- "vitest": "4.1.9"
137
+ "vitest": "4.1.10"
138
138
  },
139
139
  "peerDependencies": {
140
140
  "typescript": ">=4.8"
141
141
  },
142
- "packageManager": "pnpm@11.10.0",
142
+ "packageManager": "pnpm@11.10.0+sha512.0b7f8b98060031904c017e3a41eb187a16d40eeb829b95c4f8cb03681761fc4ab53dd219115b9b447f4dce1a05a214764461e7d3703392a9f32f9511ce8c86c8",
143
143
  "engines": {
144
144
  "node": ">=22.22.2",
145
145
  "pnpm": ">=9.0.0"
@@ -1,6 +1,6 @@
1
1
  import {
2
- type ArrayOfLength,
3
2
  type BoolOr,
3
+ type FixedLengthTuple,
4
4
  type Index,
5
5
  type IsUnion,
6
6
  type List,
@@ -38,7 +38,7 @@ import { type SizeType } from '../../types.mjs';
38
38
  export const zeros = <N extends SizeType.ArgArr>(
39
39
  len: N,
40
40
  ): N extends SmallUint
41
- ? ArrayOfLength<N, 0>
41
+ ? FixedLengthTuple<N, 0>
42
42
  : N extends SizeType.ArgArrPositive
43
43
  ? NonEmptyArray<0>
44
44
  : readonly 0[] =>
@@ -89,7 +89,7 @@ export const create = <N extends SizeType.ArgArr, const V>(
89
89
  len: N,
90
90
  init: V,
91
91
  ): N extends SmallUint
92
- ? ArrayOfLength<N, V>
92
+ ? FixedLengthTuple<N, V>
93
93
  : N extends SizeType.ArgArrPositive
94
94
  ? NonEmptyArray<V>
95
95
  : readonly V[] =>
@@ -1,5 +1,5 @@
1
1
  import {
2
- type ArrayOfLength,
2
+ type FixedLengthTuple,
3
3
  type Increment,
4
4
  type IsFixedLengthList,
5
5
  type NonEmptyArray,
@@ -163,7 +163,7 @@ export function toInserted<
163
163
  index: ArgArrayIndexWithNegative<Ar>,
164
164
  newValue: V,
165
165
  ): IsFixedLengthList<Ar> extends true
166
- ? ArrayOfLength<CastToNumber<Increment<Ar['length']>>, Ar[number] | V>
166
+ ? FixedLengthTuple<CastToNumber<Increment<Ar['length']>>, Ar[number] | V>
167
167
  : NonEmptyArray<Ar[number] | V>;
168
168
 
169
169
  // curried version
@@ -173,7 +173,7 @@ export function toInserted<const V>(
173
173
  ): <const Ar extends readonly unknown[]>(
174
174
  array: Ar,
175
175
  ) => IsFixedLengthList<Ar> extends true
176
- ? ArrayOfLength<CastToNumber<Increment<Ar['length']>>, Ar[number] | V>
176
+ ? FixedLengthTuple<CastToNumber<Increment<Ar['length']>>, Ar[number] | V>
177
177
  : NonEmptyArray<Ar[number] | V>;
178
178
 
179
179
  export function toInserted<E, const V = E>(
@@ -367,7 +367,7 @@ export function toFilled<const Ar extends readonly unknown[], const V>(
367
367
  array: Ar,
368
368
  value: V,
369
369
  ): IsFixedLengthList<Ar> extends true
370
- ? ArrayOfLength<Ar['length'], V>
370
+ ? FixedLengthTuple<Ar['length'], V>
371
371
  : Ar extends NonEmptyArray<unknown>
372
372
  ? NonEmptyArray<V>
373
373
  : readonly V[];
@@ -378,7 +378,7 @@ export function toFilled<const V>(
378
378
  ): <const Ar extends readonly unknown[]>(
379
379
  array: Ar,
380
380
  ) => IsFixedLengthList<Ar> extends true
381
- ? ArrayOfLength<Ar['length'], V>
381
+ ? FixedLengthTuple<Ar['length'], V>
382
382
  : Ar extends NonEmptyArray<unknown>
383
383
  ? NonEmptyArray<V>
384
384
  : readonly V[];
@@ -426,7 +426,7 @@ export function toRangeFilled<const Ar extends readonly unknown[], const V>(
426
426
  end: ArgArrayIndexWithNegative<Ar>,
427
427
  ],
428
428
  ): IsFixedLengthList<Ar> extends true
429
- ? ArrayOfLength<Ar['length'], V | Ar[number]>
429
+ ? FixedLengthTuple<Ar['length'], V | Ar[number]>
430
430
  : Ar extends NonEmptyArray<unknown>
431
431
  ? NonEmptyArray<V | Ar[number]>
432
432
  : readonly (V | Ar[number])[];
@@ -441,7 +441,7 @@ export function toRangeFilled<const V>(
441
441
  ): <const Ar extends readonly unknown[]>(
442
442
  array: Ar,
443
443
  ) => IsFixedLengthList<Ar> extends true
444
- ? ArrayOfLength<Ar['length'], V | Ar[number]>
444
+ ? FixedLengthTuple<Ar['length'], V | Ar[number]>
445
445
  : Ar extends NonEmptyArray<unknown>
446
446
  ? NonEmptyArray<V | Ar[number]>
447
447
  : readonly (V | Ar[number])[];
@@ -1,4 +1,4 @@
1
- import { type ArrayOfLength, type NonEmptyArray } from 'ts-type-forge';
1
+ import { type FixedLengthTuple, type NonEmptyArray } from 'ts-type-forge';
2
2
  import { expectType } from '../../expect-type.mjs';
3
3
  import { asUint32 } from '../../number/index.mjs';
4
4
  import {
@@ -18,7 +18,7 @@ describe('Arr modifications', () => {
18
18
 
19
19
  const result = toUpdated(xs, 1, (x) => x + 2);
20
20
 
21
- expectType<typeof result, ArrayOfLength<3, number>>('=');
21
+ expectType<typeof result, FixedLengthTuple<3, number>>('=');
22
22
 
23
23
  test('case 1', () => {
24
24
  assert.deepStrictEqual(result, [1, 4, 3]);
@@ -39,7 +39,7 @@ describe('Arr modifications', () => {
39
39
  test('case 1', () => {
40
40
  const result = toInserted(xs, 1, 5);
41
41
 
42
- expectType<typeof result, ArrayOfLength<4, 1 | 2 | 3 | 5>>('=');
42
+ expectType<typeof result, FixedLengthTuple<4, 1 | 2 | 3 | 5>>('=');
43
43
 
44
44
  assert.deepStrictEqual(result, [1, 5, 2, 3]);
45
45
  });
@@ -47,7 +47,7 @@ describe('Arr modifications', () => {
47
47
  test('case 2 (insert head)', () => {
48
48
  const result = toInserted(xs, 0, 5);
49
49
 
50
- expectType<typeof result, ArrayOfLength<4, 1 | 2 | 3 | 5>>('=');
50
+ expectType<typeof result, FixedLengthTuple<4, 1 | 2 | 3 | 5>>('=');
51
51
 
52
52
  assert.deepStrictEqual(result, [5, 1, 2, 3]);
53
53
  });
@@ -1,5 +1,5 @@
1
1
  import {
2
- type ArrayOfLength,
2
+ type FixedLengthTuple,
3
3
  type IsFixedLengthList,
4
4
  type List,
5
5
  type MutableNonEmptyArray,
@@ -220,7 +220,7 @@ export const toSorted = <const Ar extends readonly unknown[]>(
220
220
  ]
221
221
  : readonly [array: Ar, comparator: (x: Ar[number], y: Ar[number]) => number]
222
222
  ): IsFixedLengthList<Ar> extends true
223
- ? ArrayOfLength<Ar['length'], Ar[number]>
223
+ ? FixedLengthTuple<Ar['length'], Ar[number]>
224
224
  : Ar extends NonEmptyArray<unknown>
225
225
  ? NonEmptyArray<Ar[number]>
226
226
  : readonly Ar[number][] =>
@@ -278,7 +278,7 @@ export function toSortedBy<const Ar extends readonly unknown[]>(
278
278
  // If the array elements are mapped to numbers, comparator is optional.
279
279
  comparator?: (x: number, y: number) => number,
280
280
  ): IsFixedLengthList<Ar> extends true
281
- ? ArrayOfLength<Ar['length'], Ar[number]>
281
+ ? FixedLengthTuple<Ar['length'], Ar[number]>
282
282
  : Ar extends NonEmptyArray<unknown>
283
283
  ? NonEmptyArray<Ar[number]>
284
284
  : readonly Ar[number][];
@@ -288,7 +288,7 @@ export function toSortedBy<const Ar extends readonly unknown[], const V>(
288
288
  comparatorValueMapper: (value: Ar[number]) => V,
289
289
  comparator: (x: V, y: V) => number,
290
290
  ): IsFixedLengthList<Ar> extends true
291
- ? ArrayOfLength<Ar['length'], Ar[number]>
291
+ ? FixedLengthTuple<Ar['length'], Ar[number]>
292
292
  : Ar extends NonEmptyArray<unknown>
293
293
  ? NonEmptyArray<Ar[number]>
294
294
  : readonly Ar[number][];
@@ -1,4 +1,4 @@
1
- import { type ArrayOfLength } from 'ts-type-forge';
1
+ import { type FixedLengthTuple } from 'ts-type-forge';
2
2
  import { IMap } from '../../collections/index.mjs';
3
3
  import { expectType } from '../../expect-type.mjs';
4
4
  import { Optional } from '../../functional/index.mjs';
@@ -26,7 +26,7 @@ describe('Arr transformations', () => {
26
26
  describe(map, () => {
27
27
  const mapped = map([1, 2, 3], (x, i): number => x ** 2 * i);
28
28
 
29
- expectType<typeof mapped, ArrayOfLength<3, number>>('=');
29
+ expectType<typeof mapped, FixedLengthTuple<3, number>>('=');
30
30
 
31
31
  test('case 1', () => {
32
32
  assert.deepStrictEqual(mapped, [0, 4, 18]);
@@ -215,7 +215,7 @@ describe('Arr transformations', () => {
215
215
 
216
216
  const result = toSorted(xs);
217
217
 
218
- expectType<typeof result, ArrayOfLength<3, 1 | 2 | 3>>('=');
218
+ expectType<typeof result, FixedLengthTuple<3, 1 | 2 | 3>>('=');
219
219
 
220
220
  test('case 1', () => {
221
221
  assert.deepStrictEqual(result, [1, 2, 3]);
@@ -227,7 +227,7 @@ describe('Arr transformations', () => {
227
227
 
228
228
  const result = toSorted(xs, (a, b) => a - b);
229
229
 
230
- expectType<typeof result, ArrayOfLength<3, 1 | 2 | 3>>('=');
230
+ expectType<typeof result, FixedLengthTuple<3, 1 | 2 | 3>>('=');
231
231
 
232
232
  test('case 2', () => {
233
233
  assert.deepStrictEqual(result, [1, 2, 3]);
@@ -239,7 +239,7 @@ describe('Arr transformations', () => {
239
239
 
240
240
  const result = toSorted(xs, (a, b) => b - a);
241
241
 
242
- expectType<typeof result, ArrayOfLength<3, 1 | 2 | 3>>('=');
242
+ expectType<typeof result, FixedLengthTuple<3, 1 | 2 | 3>>('=');
243
243
 
244
244
  test('case 3', () => {
245
245
  assert.deepStrictEqual(result, [3, 2, 1]);
@@ -255,7 +255,7 @@ describe('Arr transformations', () => {
255
255
 
256
256
  expectType<
257
257
  typeof sorted,
258
- ArrayOfLength<3, Readonly<{ v: 1 } | { v: 2 } | { v: 3 }>>
258
+ FixedLengthTuple<3, Readonly<{ v: 1 } | { v: 2 } | { v: 3 }>>
259
259
  >('=');
260
260
 
261
261
  test('case 1', () => {
@@ -274,7 +274,7 @@ describe('Arr transformations', () => {
274
274
 
275
275
  expectType<
276
276
  typeof sorted,
277
- ArrayOfLength<3, Readonly<{ v: 1 } | { v: 2 } | { v: 3 }>>
277
+ FixedLengthTuple<3, Readonly<{ v: 1 } | { v: 2 } | { v: 3 }>>
278
278
  >('=');
279
279
 
280
280
  test('case 2', () => {
@@ -1,9 +1,9 @@
1
1
  import {
2
- type ArrayAtLeastLen,
3
- type ArrayAtMostLen,
4
- type ArrayBoundedLen,
5
- type ArrayOfLength,
6
2
  type BoolOr,
3
+ type BoundedLengthTuple,
4
+ type FixedLengthTuple,
5
+ type MaxLengthTuple,
6
+ type MinLengthTuple,
7
7
  type NonEmptyArray,
8
8
  type TypeEq,
9
9
  } from 'ts-type-forge';
@@ -100,19 +100,19 @@ export const isNonEmpty = <E,>(
100
100
  *
101
101
  * const triple: readonly number[] = [1, 2, 3] as const;
102
102
  *
103
- * assert.isTrue(Arr.isArrayOfLength(pair, 2));
103
+ * assert.isTrue(Arr.isFixedLengthTuple(pair, 2));
104
104
  *
105
- * assert.isFalse(Arr.isArrayOfLength(triple, 2));
105
+ * assert.isFalse(Arr.isFixedLengthTuple(triple, 2));
106
106
  *
107
- * if (Arr.isArrayOfLength(pair, 2)) {
107
+ * if (Arr.isFixedLengthTuple(pair, 2)) {
108
108
  * assert.deepStrictEqual(pair, [1, 2]);
109
109
  * }
110
110
  * ```
111
111
  */
112
- export const isArrayOfLength = <E, N extends SizeType.ArgArr>(
112
+ export const isFixedLengthTuple = <E, N extends SizeType.ArgArr>(
113
113
  array: readonly E[],
114
114
  len: N,
115
- ): array is ArrayOfLength<N, E> => array.length === len;
115
+ ): array is FixedLengthTuple<N, E> => array.length === len;
116
116
 
117
117
  /**
118
118
  * Checks if an array has at least a specific length.
@@ -124,19 +124,19 @@ export const isArrayOfLength = <E, N extends SizeType.ArgArr>(
124
124
  *
125
125
  * const emptyQueue: readonly string[] = [] as const;
126
126
  *
127
- * assert.isTrue(Arr.isArrayAtLeastLength(queue, 1));
127
+ * assert.isTrue(Arr.isMinLengthTuple(queue, 1));
128
128
  *
129
- * assert.isFalse(Arr.isArrayAtLeastLength(emptyQueue, 1));
129
+ * assert.isFalse(Arr.isMinLengthTuple(emptyQueue, 1));
130
130
  *
131
- * if (Arr.isArrayAtLeastLength(queue, 1)) {
131
+ * if (Arr.isMinLengthTuple(queue, 1)) {
132
132
  * assert.isTrue(queue[0] === 'task-1');
133
133
  * }
134
134
  * ```
135
135
  */
136
- export const isArrayAtLeastLength = <E, N extends SizeType.ArgArr>(
136
+ export const isMinLengthTuple = <E, N extends SizeType.ArgArr>(
137
137
  array: readonly E[],
138
138
  len: N,
139
- ): array is ArrayAtLeastLen<N, E> => array.length >= len;
139
+ ): array is MinLengthTuple<N, E> => array.length >= len;
140
140
 
141
141
  /**
142
142
  * Checks if an array has at most a specific length.
@@ -148,19 +148,19 @@ export const isArrayAtLeastLength = <E, N extends SizeType.ArgArr>(
148
148
  *
149
149
  * const triple: readonly number[] = [1, 2, 3] as const;
150
150
  *
151
- * assert.isTrue(Arr.isArrayAtMostLength(pair, 2));
151
+ * assert.isTrue(Arr.isMaxLengthTuple(pair, 2));
152
152
  *
153
- * assert.isFalse(Arr.isArrayAtMostLength(triple, 2));
153
+ * assert.isFalse(Arr.isMaxLengthTuple(triple, 2));
154
154
  *
155
- * if (Arr.isArrayAtMostLength(pair, 2)) {
155
+ * if (Arr.isMaxLengthTuple(pair, 2)) {
156
156
  * assert.isTrue(pair.length <= 2);
157
157
  * }
158
158
  * ```
159
159
  */
160
- export const isArrayAtMostLength = <E, N extends SizeType.ArgArr>(
160
+ export const isMaxLengthTuple = <E, N extends SizeType.ArgArr>(
161
161
  array: readonly E[],
162
162
  len: N,
163
- ): array is ArrayAtMostLen<N, E> => array.length <= len;
163
+ ): array is MaxLengthTuple<N, E> => array.length <= len;
164
164
 
165
165
  /**
166
166
  * Checks if an array's length is within a specific inclusive range.
@@ -172,16 +172,16 @@ export const isArrayAtMostLength = <E, N extends SizeType.ArgArr>(
172
172
  *
173
173
  * const quad: readonly number[] = [1, 2, 3, 4] as const;
174
174
  *
175
- * assert.isTrue(Arr.isArrayBoundedLength(pair, 1, 3));
175
+ * assert.isTrue(Arr.isBoundedLengthTuple(pair, 1, 3));
176
176
  *
177
- * assert.isFalse(Arr.isArrayBoundedLength(quad, 1, 3));
177
+ * assert.isFalse(Arr.isBoundedLengthTuple(quad, 1, 3));
178
178
  *
179
- * if (Arr.isArrayBoundedLength(pair, 1, 3)) {
179
+ * if (Arr.isBoundedLengthTuple(pair, 1, 3)) {
180
180
  * assert.isTrue(pair.length >= 1 && pair.length <= 3);
181
181
  * }
182
182
  * ```
183
183
  */
184
- export const isArrayBoundedLength = <
184
+ export const isBoundedLengthTuple = <
185
185
  E,
186
186
  Min extends SizeType.ArgArr,
187
187
  Max extends SizeType.ArgArr,
@@ -189,7 +189,7 @@ export const isArrayBoundedLength = <
189
189
  array: readonly E[],
190
190
  min: Min,
191
191
  max: Max,
192
- ): array is ArrayBoundedLen<Min, Max, E> =>
192
+ ): array is BoundedLengthTuple<Min, Max, E> =>
193
193
  array.length >= min && array.length <= max;
194
194
 
195
195
  /**