ts-data-forge 13.0.0 → 14.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 (72) hide show
  1. package/README.md +1 -1
  2. package/dist/array/impl/array-utils-creation.d.mts +2 -2
  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-length-bounded-array-cast.d.mts +56 -29
  6. package/dist/array/impl/array-utils-length-bounded-array-cast.d.mts.map +1 -1
  7. package/dist/array/impl/array-utils-length-bounded-array-cast.mjs +23 -15
  8. package/dist/array/impl/array-utils-length-bounded-array-cast.mjs.map +1 -1
  9. package/dist/array/impl/array-utils-length-bounded-array-guard.d.mts +126 -28
  10. package/dist/array/impl/array-utils-length-bounded-array-guard.d.mts.map +1 -1
  11. package/dist/array/impl/array-utils-length-bounded-array-guard.mjs +39 -5
  12. package/dist/array/impl/array-utils-length-bounded-array-guard.mjs.map +1 -1
  13. package/dist/array/impl/array-utils-length-bounded-tuple-cast.d.mts +167 -0
  14. package/dist/array/impl/array-utils-length-bounded-tuple-cast.d.mts.map +1 -0
  15. package/dist/array/impl/array-utils-length-bounded-tuple-cast.mjs +87 -0
  16. package/dist/array/impl/array-utils-length-bounded-tuple-cast.mjs.map +1 -0
  17. package/dist/array/impl/array-utils-length-bounded-tuple-guard.d.mts +135 -0
  18. package/dist/array/impl/array-utils-length-bounded-tuple-guard.d.mts.map +1 -0
  19. package/dist/array/impl/array-utils-length-bounded-tuple-guard.mjs +41 -0
  20. package/dist/array/impl/array-utils-length-bounded-tuple-guard.mjs.map +1 -0
  21. package/dist/array/impl/array-utils-modification.d.mts +32 -18
  22. package/dist/array/impl/array-utils-modification.d.mts.map +1 -1
  23. package/dist/array/impl/array-utils-modification.mjs.map +1 -1
  24. package/dist/array/impl/array-utils-reducing-value.d.mts +3 -3
  25. package/dist/array/impl/array-utils-reducing-value.d.mts.map +1 -1
  26. package/dist/array/impl/array-utils-reducing-value.mjs +1 -1
  27. package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
  28. package/dist/array/impl/array-utils-slicing.d.mts +11 -11
  29. package/dist/array/impl/array-utils-slicing.d.mts.map +1 -1
  30. package/dist/array/impl/array-utils-slicing.mjs +1 -1
  31. package/dist/array/impl/array-utils-slicing.mjs.map +1 -1
  32. package/dist/array/impl/array-utils-transformation.d.mts +35 -23
  33. package/dist/array/impl/array-utils-transformation.d.mts.map +1 -1
  34. package/dist/array/impl/array-utils-transformation.mjs +2 -2
  35. package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
  36. package/dist/array/impl/array-utils-validation.d.mts +2 -124
  37. package/dist/array/impl/array-utils-validation.d.mts.map +1 -1
  38. package/dist/array/impl/array-utils-validation.mjs +1 -7
  39. package/dist/array/impl/array-utils-validation.mjs.map +1 -1
  40. package/dist/array/impl/index.d.mts +2 -0
  41. package/dist/array/impl/index.d.mts.map +1 -1
  42. package/dist/array/impl/index.mjs +5 -3
  43. package/dist/array/impl/index.mjs.map +1 -1
  44. package/dist/object/object.mjs +1 -1
  45. package/dist/string/str.d.mts +44 -44
  46. package/dist/string/str.d.mts.map +1 -1
  47. package/dist/string/str.mjs +17 -17
  48. package/dist/string/str.mjs.map +1 -1
  49. package/package.json +2 -2
  50. package/src/array/impl/array-utils-creation.mts +7 -3
  51. package/src/array/impl/array-utils-length-bounded-array-cast.mts +88 -50
  52. package/src/array/impl/array-utils-length-bounded-array-cast.test.mts +40 -13
  53. package/src/array/impl/array-utils-length-bounded-array-guard.mts +248 -39
  54. package/src/array/impl/array-utils-length-bounded-array-guard.test.mts +135 -24
  55. package/src/array/impl/array-utils-length-bounded-tuple-cast.mts +364 -0
  56. package/src/array/impl/array-utils-length-bounded-tuple-cast.test.mts +207 -0
  57. package/src/array/impl/array-utils-length-bounded-tuple-guard.mts +266 -0
  58. package/src/array/impl/array-utils-length-bounded-tuple-guard.test.mts +441 -0
  59. package/src/array/impl/array-utils-length-constraint-preservation.test.mts +287 -0
  60. package/src/array/impl/array-utils-modification.mts +72 -57
  61. package/src/array/impl/array-utils-modification.test.mts +93 -6
  62. package/src/array/impl/array-utils-reducing-value.mts +5 -5
  63. package/src/array/impl/array-utils-slicing.mts +65 -43
  64. package/src/array/impl/array-utils-slicing.test.mts +55 -0
  65. package/src/array/impl/array-utils-transformation.mts +66 -39
  66. package/src/array/impl/array-utils-transformation.test.mts +62 -16
  67. package/src/array/impl/array-utils-validation.mts +2 -162
  68. package/src/array/impl/array-utils-validation.test.mts +0 -371
  69. package/src/array/impl/index.mts +2 -0
  70. package/src/collections/queue.test.mts +1 -1
  71. package/src/string/str.mts +69 -69
  72. package/src/string/str.test.mts +40 -40
package/README.md CHANGED
@@ -381,7 +381,7 @@ const sum = Arr.sum(numbers);
381
381
  assert.isTrue(sum === 20);
382
382
 
383
383
  // Type-safe length checking
384
- if (Arr.isMinLengthTuple(numbers, 2)) {
384
+ if (Arr.isMinLengthTuple(2, numbers)) {
385
385
  // numbers is now guaranteed to have at least 2 elements
386
386
  expectType<typeof numbers, readonly [number, number, ...number[]]>('=');
387
387
 
@@ -1,4 +1,4 @@
1
- import { type BoolOr, type FixedLengthTuple, type Index, type IsUnion, type List, type Min, type NonEmptyArray, type NonZeroSafeIntWithSmallInt, type PositiveSafeIntWithSmallInt, type RelaxedExclude, type SafeInt, type SafeIntWithSmallInt, type SafeUint, type SafeUintWithSmallInt, type Seq, type SmallUint, type StructuralPrefixLength } from 'ts-type-forge';
1
+ import { type BoolOr, type FixedLengthArray, type FixedLengthTuple, type Index, type IsUnion, type List, type Min, type NonEmptyArray, type NonZeroSafeIntWithSmallInt, type PositiveSafeIntWithSmallInt, type RelaxedExclude, type SafeInt, type SafeIntWithSmallInt, type SafeUint, type SafeUintWithSmallInt, type Seq, type SmallUint, type StructuralPrefixLength, type SupportedLength } from 'ts-type-forge';
2
2
  import { type SizeType } from '../../types.mjs';
3
3
  /**
4
4
  * Creates an array of zeros with the specified length.
@@ -47,7 +47,7 @@ export declare const seq: <N extends SizeType.ArgArr>(len: N) => N extends Small
47
47
  * assert.deepStrictEqual(emptyStrings, []);
48
48
  * ```
49
49
  */
50
- export declare const create: <N extends SizeType.ArgArr, const V>(len: N, init: V) => N extends StructuralPrefixLength ? FixedLengthTuple<N, V> : N extends SizeType.ArgArrPositive ? NonEmptyArray<V> : readonly V[];
50
+ export declare const create: <N extends SizeType.ArgArr, const V>(len: N, init: V) => N extends StructuralPrefixLength ? FixedLengthTuple<N, V> : N extends SupportedLength ? FixedLengthArray<N, V> : N extends SizeType.ArgArrPositive ? NonEmptyArray<V> : readonly V[];
51
51
  /**
52
52
  * Alias for `create`.
53
53
  *
@@ -1 +1 @@
1
- {"version":3,"file":"array-utils-creation.d.mts","sourceRoot":"","sources":["../../../src/array/impl/array-utils-creation.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,MAAM,EACX,KAAK,gBAAgB,EACrB,KAAK,KAAK,EACV,KAAK,OAAO,EACZ,KAAK,IAAI,EACT,KAAK,GAAG,EACR,KAAK,aAAa,EAClB,KAAK,0BAA0B,EAC/B,KAAK,2BAA2B,EAChC,KAAK,cAAc,EACnB,KAAK,OAAO,EACZ,KAAK,mBAAmB,EACxB,KAAK,QAAQ,EACb,KAAK,oBAAoB,EACzB,KAAK,GAAG,EACR,KAAK,SAAS,EACd,KAAK,sBAAsB,EAC5B,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,KAAK,GAAI,CAAC,SAAS,QAAQ,CAAC,MAAM,OACxC,CAAC,KACL,CAAC,SAAS,SAAS,GAClB,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,GACtB,CAAC,SAAS,QAAQ,CAAC,cAAc,GAC/B,aAAa,CAAC,CAAC,CAAC,GAChB,SAAS,CAAC,EAE+B,CAAC;AAEhD;;;;;;;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AC,SAAS,SAAS,EAAE,CAAC,SAAS,SAAS,IACrD,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,IAAI,GACvC,SAAS,cAAc,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,GAC5C,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAkB3B;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,SAAS,EAAE,CAAC,SAAS,SAAS,EAC5D,KAAK,EAAE,CAAC,EACR,GAAG,EAAE,CAAC,EACN,IAAI,CAAC,EAAE,CAAC,GACP,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAEnB,wBAAgB,KAAK,CACnB,KAAK,EAAE,oBAAoB,EAC3B,GAAG,EAAE,oBAAoB,EACzB,IAAI,CAAC,EAAE,2BAA2B,GACjC,SAAS,QAAQ,EAAE,CAAC;AAEvB,wBAAgB,KAAK,CACnB,KAAK,EAAE,mBAAmB,EAC1B,GAAG,EAAE,mBAAmB,EACxB,IAAI,CAAC,EAAE,0BAA0B,GAChC,SAAS,OAAO,EAAE,CAAC"}
1
+ {"version":3,"file":"array-utils-creation.d.mts","sourceRoot":"","sources":["../../../src/array/impl/array-utils-creation.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,MAAM,EACX,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,KAAK,EACV,KAAK,OAAO,EACZ,KAAK,IAAI,EACT,KAAK,GAAG,EACR,KAAK,aAAa,EAClB,KAAK,0BAA0B,EAC/B,KAAK,2BAA2B,EAChC,KAAK,cAAc,EACnB,KAAK,OAAO,EACZ,KAAK,mBAAmB,EACxB,KAAK,QAAQ,EACb,KAAK,oBAAoB,EACzB,KAAK,GAAG,EACR,KAAK,SAA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xB,IAAI,CAAC,EAAE,0BAA0B,GAChC,SAAS,OAAO,EAAE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"array-utils-creation.mjs","sources":["../../../src/array/impl/array-utils-creation.mts"],"sourcesContent":["import {\n type BoolOr,\n type FixedLengthTuple,\n type Index,\n type IsUnion,\n type List,\n type Min,\n type NonEmptyArray,\n type NonZeroSafeIntWithSmallInt,\n type PositiveSafeIntWithSmallInt,\n type RelaxedExclude,\n type SafeInt,\n type SafeIntWithSmallInt,\n type SafeUint,\n type SafeUintWithSmallInt,\n type Seq,\n type SmallUint,\n type StructuralPrefixLength,\n} from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { range as rangeIterator } from '../../iterator/index.mjs';\nimport { type SizeType } from '../../types.mjs';\n\n/**\n * Creates an array of zeros with the specified length.\n *\n * @example\n *\n * ```ts\n * const emptyZeros = Arr.zeros(0);\n *\n * const threeZeros = Arr.zeros(3);\n *\n * assert.deepStrictEqual(emptyZeros, []);\n *\n * assert.deepStrictEqual(threeZeros, [0, 0, 0]);\n * ```\n */\nexport const zeros = <N extends SizeType.ArgArr>(\n len: N,\n): N extends SmallUint\n ? FixedLengthTuple<N, 0>\n : N extends SizeType.ArgArrPositive\n ? NonEmptyArray<0>\n : readonly 0[] =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Array.from({ length: len }, () => 0) as never;\n\n/**\n * Creates a sequence of consecutive integers from 0 to `len-1`.\n *\n * @example\n *\n * ```ts\n * const emptySeq = Arr.seq(0);\n *\n * const firstFive = Arr.seq(5);\n *\n * assert.deepStrictEqual(emptySeq, []);\n *\n * assert.deepStrictEqual(firstFive, [0, 1, 2, 3, 4]);\n * ```\n */\nexport const seq = <N extends SizeType.ArgArr>(\n len: N,\n): N extends SmallUint\n ? Seq<N>\n : N extends SizeType.ArgArrPositive\n ? NonEmptyArray<SizeType.Arr>\n : readonly SizeType.Arr[] =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Array.from({ length: len }, (_, i) => i) as never;\n\n/**\n * Creates a new array of the specified length, filled with the initial value.\n *\n * @example\n *\n * ```ts\n * const threeOnes = Arr.create(3, 1);\n *\n * const emptyStrings = Arr.create(0, 'Ada');\n *\n * assert.deepStrictEqual(threeOnes, [1, 1, 1]);\n *\n * assert.deepStrictEqual(emptyStrings, []);\n * ```\n */\nexport const create = <N extends SizeType.ArgArr, const V>(\n len: N,\n init: V,\n): N extends StructuralPrefixLength\n ? FixedLengthTuple<N, V>\n : N extends SizeType.ArgArrPositive\n ? NonEmptyArray<V>\n : readonly V[] =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Array.from({ length: Math.max(0, len) }, () => init) as never;\n\n/**\n * Alias for `create`.\n *\n * @see {@link create}\n */\nexport const newArray = create;\n\n/**\n * Generates an array from a generator function.\n *\n * @example\n *\n * ```ts\n * const numbers = Arr.generate(function* () {\n * yield 1;\n *\n * yield 2;\n *\n * yield 3;\n * });\n *\n * assert.deepStrictEqual(numbers, [1, 2, 3]);\n * ```\n */\nexport const generate = <T,>(\n generatorFn: () => Generator<T, void, unknown>,\n): readonly T[] => Array.from(generatorFn());\n\n/**\n * Generates an array from an async generator function.\n *\n * @example\n *\n * ```ts\n * const values = await Arr.generateAsync(async function* () {\n * yield 'Ada';\n *\n * await Promise.resolve();\n *\n * yield 'Lovelace';\n * });\n *\n * assert.deepStrictEqual(values, ['Ada', 'Lovelace']);\n * ```\n */\nexport const generateAsync = <T,>(\n generatorFn: () => AsyncGenerator<T, void, unknown>,\n): Promise<readonly T[]> => Array.fromAsync(generatorFn());\n\n/**\n * Creates a shallow copy of an array.\n *\n * @example\n *\n * ```ts\n * const original = [{ id: 1 }, { id: 2 }] as const;\n *\n * const cloned = Arr.copy(original);\n *\n * assert.deepStrictEqual(cloned, original);\n *\n * assert.notStrictEqual(cloned, original);\n * ```\n */\nexport const copy = <const Ar extends readonly unknown[]>(array: Ar): Ar =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n array.slice() as unknown as Ar;\n\ntype LT = Readonly<{ [N in SmallUint]: Index<N> }>;\n\ntype RangeList<S extends SmallUint, E extends SmallUint> =\n BoolOr<IsUnion<S>, IsUnion<E>> extends true\n ? readonly RelaxedExclude<LT[E], LT[Min<S>]>[] // Avoid incorrect type calculation for unions with Seq\n : List.Skip<S, Seq<E>>;\n\nexpectType<RangeList<1, 5>, readonly [1, 2, 3, 4]>('=');\n\nexpectType<RangeList<1, 2>, readonly [1]>('=');\n\nexpectType<RangeList<1, 1>, readonly []>('=');\n\nexpectType<RangeList<1, 1 | 3>, readonly (1 | 2)[]>('=');\n\nexpectType<RangeList<1 | 3, 3 | 5>, readonly (1 | 2 | 3 | 4)[]>('=');\n\nexpectType<RangeList<1 | 2 | 3, 5 | 6 | 7>, readonly (1 | 2 | 3 | 4 | 5 | 6)[]>(\n '=',\n);\n\nexpectType<RangeList<5, 1>, readonly []>('=');\n\n/**\n * Creates an array of numbers within a specified range with optional step.\n *\n * @example\n *\n * ```ts\n * const ascending = Arr.range(asUint32(1), asUint32(5));\n *\n * const empty = Arr.range(asUint32(2), asUint32(2));\n *\n * assert.deepStrictEqual(ascending, [1, 2, 3, 4]);\n *\n * assert.deepStrictEqual(empty, []);\n * ```\n */\nexport function range<S extends SmallUint, E extends SmallUint>(\n start: S,\n end: E,\n step?: 1,\n): RangeList<S, E>;\n\nexport function range(\n start: SafeUintWithSmallInt,\n end: SafeUintWithSmallInt,\n step?: PositiveSafeIntWithSmallInt,\n): readonly SafeUint[];\n\nexport function range(\n start: SafeIntWithSmallInt,\n end: SafeIntWithSmallInt,\n step?: NonZeroSafeIntWithSmallInt,\n): readonly SafeInt[];\n\nexport function range(\n start: SafeIntWithSmallInt,\n end: SafeIntWithSmallInt,\n step: NonZeroSafeIntWithSmallInt = 1,\n): readonly SafeInt[] {\n return Array.from(rangeIterator(start, end, step));\n}\n"],"names":["rangeIterator"],"mappings":";;AAsCO,MAAM,QAAQ,CACnB,GAAA;AAAA;AAAA,EAOA,MAAM,IAAA,CAAK,EAAE,QAAQ,GAAA,EAAI,EAAG,MAAM,CAAC;AAAA;AAiB9B,MAAM,MAAM,CACjB,GAAA;AAAA;AAAA,EAOA,KAAA,CAAM,KAAK,EAAE,MAAA,EAAQ,KAAI,EAAG,CAAC,CAAA,EAAG,CAAA,KAAM,CAAC;AAAA;MAiB5B,MAAA,GAAS,CACpB,GAAA,EACA,IAAA;AAAA;AAAA,EAOA,KAAA,CAAM,IAAA,CAAK,EAAE,MAAA,EAAQ,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,GAAG,CAAA,EAAE,EAAG,MAAM,IAAI;AAAA;AAO9C,MAAM,QAAA,GAAW;AAmBjB,MAAM,WAAW,CACtB,WAAA,KACiB,KAAA,CAAM,IAAA,CAAK,aAAa;AAmBpC,MAAM,gBAAgB,CAC3B,WAAA,KAC0B,KAAA,CAAM,SAAA,CAAU,aAAa;AAiBlD,MAAM,OAAO,CAAsC,KAAA;AAAA;AAAA,EAExD,MAAM,KAAA;AAAM;AA0DP,SAAS,KAAA,CACd,KAAA,EACA,GAAA,EACA,IAAA,GAAmC,CAAA,EACf;AACpB,EAAA,OAAO,MAAM,IAAA,CAAKA,OAAA,CAAc,KAAA,EAAO,GAAA,EAAK,IAAI,CAAC,CAAA;AACnD;;;;"}
1
+ {"version":3,"file":"array-utils-creation.mjs","sources":["../../../src/array/impl/array-utils-creation.mts"],"sourcesContent":["import {\n type BoolOr,\n type FixedLengthArray,\n type FixedLengthTuple,\n type Index,\n type IsUnion,\n type List,\n type Min,\n type NonEmptyArray,\n type NonZeroSafeIntWithSmallInt,\n type PositiveSafeIntWithSmallInt,\n type RelaxedExclude,\n type SafeInt,\n type SafeIntWithSmallInt,\n type SafeUint,\n type SafeUintWithSmallInt,\n type Seq,\n type SmallUint,\n type StructuralPrefixLength,\n type SupportedLength,\n} from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { range as rangeIterator } from '../../iterator/index.mjs';\nimport { type SizeType } from '../../types.mjs';\n\n/**\n * Creates an array of zeros with the specified length.\n *\n * @example\n *\n * ```ts\n * const emptyZeros = Arr.zeros(0);\n *\n * const threeZeros = Arr.zeros(3);\n *\n * assert.deepStrictEqual(emptyZeros, []);\n *\n * assert.deepStrictEqual(threeZeros, [0, 0, 0]);\n * ```\n */\nexport const zeros = <N extends SizeType.ArgArr>(\n len: N,\n): N extends SmallUint\n ? FixedLengthTuple<N, 0>\n : N extends SizeType.ArgArrPositive\n ? NonEmptyArray<0>\n : readonly 0[] =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Array.from({ length: len }, () => 0) as never;\n\n/**\n * Creates a sequence of consecutive integers from 0 to `len-1`.\n *\n * @example\n *\n * ```ts\n * const emptySeq = Arr.seq(0);\n *\n * const firstFive = Arr.seq(5);\n *\n * assert.deepStrictEqual(emptySeq, []);\n *\n * assert.deepStrictEqual(firstFive, [0, 1, 2, 3, 4]);\n * ```\n */\nexport const seq = <N extends SizeType.ArgArr>(\n len: N,\n): N extends SmallUint\n ? Seq<N>\n : N extends SizeType.ArgArrPositive\n ? NonEmptyArray<SizeType.Arr>\n : readonly SizeType.Arr[] =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Array.from({ length: len }, (_, i) => i) as never;\n\n/**\n * Creates a new array of the specified length, filled with the initial value.\n *\n * @example\n *\n * ```ts\n * const threeOnes = Arr.create(3, 1);\n *\n * const emptyStrings = Arr.create(0, 'Ada');\n *\n * assert.deepStrictEqual(threeOnes, [1, 1, 1]);\n *\n * assert.deepStrictEqual(emptyStrings, []);\n * ```\n */\nexport const create = <N extends SizeType.ArgArr, const V>(\n len: N,\n init: V,\n): N extends StructuralPrefixLength\n ? FixedLengthTuple<N, V>\n : N extends SupportedLength\n ? FixedLengthArray<N, V>\n : N extends SizeType.ArgArrPositive\n ? NonEmptyArray<V>\n : readonly V[] =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Array.from({ length: Math.max(0, len) }, () => init) as never;\n\n/**\n * Alias for `create`.\n *\n * @see {@link create}\n */\nexport const newArray = create;\n\n/**\n * Generates an array from a generator function.\n *\n * @example\n *\n * ```ts\n * const numbers = Arr.generate(function* () {\n * yield 1;\n *\n * yield 2;\n *\n * yield 3;\n * });\n *\n * assert.deepStrictEqual(numbers, [1, 2, 3]);\n * ```\n */\nexport const generate = <T,>(\n generatorFn: () => Generator<T, void, unknown>,\n): readonly T[] => Array.from(generatorFn());\n\n/**\n * Generates an array from an async generator function.\n *\n * @example\n *\n * ```ts\n * const values = await Arr.generateAsync(async function* () {\n * yield 'Ada';\n *\n * await Promise.resolve();\n *\n * yield 'Lovelace';\n * });\n *\n * assert.deepStrictEqual(values, ['Ada', 'Lovelace']);\n * ```\n */\nexport const generateAsync = <T,>(\n generatorFn: () => AsyncGenerator<T, void, unknown>,\n): Promise<readonly T[]> => Array.fromAsync(generatorFn());\n\n/**\n * Creates a shallow copy of an array.\n *\n * @example\n *\n * ```ts\n * const original = [{ id: 1 }, { id: 2 }] as const;\n *\n * const cloned = Arr.copy(original);\n *\n * assert.deepStrictEqual(cloned, original);\n *\n * assert.notStrictEqual(cloned, original);\n * ```\n */\nexport const copy = <const Ar extends readonly unknown[]>(array: Ar): Ar =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n array.slice() as unknown as Ar;\n\ntype LT = Readonly<{ [N in SmallUint]: Index<N> }>;\n\ntype RangeList<S extends SmallUint, E extends SmallUint> =\n BoolOr<IsUnion<S>, IsUnion<E>> extends true\n ? readonly RelaxedExclude<LT[E], LT[Min<S>]>[] // Avoid incorrect type calculation for unions with Seq\n : List.Skip<S, Seq<E>>;\n\nexpectType<RangeList<1, 5>, readonly [1, 2, 3, 4]>('=');\n\nexpectType<RangeList<1, 2>, readonly [1]>('=');\n\nexpectType<RangeList<1, 1>, readonly []>('=');\n\nexpectType<RangeList<1, 1 | 3>, readonly (1 | 2)[]>('=');\n\nexpectType<RangeList<1 | 3, 3 | 5>, readonly (1 | 2 | 3 | 4)[]>('=');\n\nexpectType<RangeList<1 | 2 | 3, 5 | 6 | 7>, readonly (1 | 2 | 3 | 4 | 5 | 6)[]>(\n '=',\n);\n\nexpectType<RangeList<5, 1>, readonly []>('=');\n\n/**\n * Creates an array of numbers within a specified range with optional step.\n *\n * @example\n *\n * ```ts\n * const ascending = Arr.range(asUint32(1), asUint32(5));\n *\n * const empty = Arr.range(asUint32(2), asUint32(2));\n *\n * assert.deepStrictEqual(ascending, [1, 2, 3, 4]);\n *\n * assert.deepStrictEqual(empty, []);\n * ```\n */\nexport function range<S extends SmallUint, E extends SmallUint>(\n start: S,\n end: E,\n step?: 1,\n): RangeList<S, E>;\n\nexport function range(\n start: SafeUintWithSmallInt,\n end: SafeUintWithSmallInt,\n step?: PositiveSafeIntWithSmallInt,\n): readonly SafeUint[];\n\nexport function range(\n start: SafeIntWithSmallInt,\n end: SafeIntWithSmallInt,\n step?: NonZeroSafeIntWithSmallInt,\n): readonly SafeInt[];\n\nexport function range(\n start: SafeIntWithSmallInt,\n end: SafeIntWithSmallInt,\n step: NonZeroSafeIntWithSmallInt = 1,\n): readonly SafeInt[] {\n return Array.from(rangeIterator(start, end, step));\n}\n"],"names":["rangeIterator"],"mappings":";;AAwCO,MAAM,QAAQ,CACnB,GAAA;AAAA;AAAA,EAOA,MAAM,IAAA,CAAK,EAAE,QAAQ,GAAA,EAAI,EAAG,MAAM,CAAC;AAAA;AAiB9B,MAAM,MAAM,CACjB,GAAA;AAAA;AAAA,EAOA,KAAA,CAAM,KAAK,EAAE,MAAA,EAAQ,KAAI,EAAG,CAAC,CAAA,EAAG,CAAA,KAAM,CAAC;AAAA;MAiB5B,MAAA,GAAS,CACpB,GAAA,EACA,IAAA;AAAA;AAAA,EASA,KAAA,CAAM,IAAA,CAAK,EAAE,MAAA,EAAQ,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,GAAG,CAAA,EAAE,EAAG,MAAM,IAAI;AAAA;AAO9C,MAAM,QAAA,GAAW;AAmBjB,MAAM,WAAW,CACtB,WAAA,KACiB,KAAA,CAAM,IAAA,CAAK,aAAa;AAmBpC,MAAM,gBAAgB,CAC3B,WAAA,KAC0B,KAAA,CAAM,SAAA,CAAU,aAAa;AAiBlD,MAAM,OAAO,CAAsC,KAAA;AAAA;AAAA,EAExD,MAAM,KAAA;AAAM;AA0DP,SAAS,KAAA,CACd,KAAA,EACA,GAAA,EACA,IAAA,GAAmC,CAAA,EACf;AACpB,EAAA,OAAO,MAAM,IAAA,CAAKA,OAAA,CAAc,KAAA,EAAO,GAAA,EAAK,IAAI,CAAC,CAAA;AACnD;;;;"}
@@ -9,13 +9,14 @@ import { type BoundedLengthArray, type FixedLengthArray, type MaxLengthArray, ty
9
9
  * structural tuple prefix (in-range indexed access without `undefined` under
10
10
  * `noUncheckedIndexedAccess`).
11
11
  *
12
- * Supports a curried overload: calling it with only `length` returns a
13
- * function that casts an array, which is convenient for `pipe`/`map`.
12
+ * The length argument comes first, matching the type-parameter order of
13
+ * `FixedLengthArray<Length, Elm>`. Omitting the array returns a function that
14
+ * casts one, which is convenient for `pipe`/`map`.
14
15
  *
15
16
  * @example
16
17
  *
17
18
  * ```ts
18
- * const rgb = Arr.asFixedLengthArray([255, 128, 0], 3);
19
+ * const rgb = Arr.asFixedLengthArray(3, [255, 128, 0]);
19
20
  *
20
21
  * const atMost5: MaxLengthArray<5, number> = rgb; // OK (3 <= 5)
21
22
  * const red: number = rgb[0]; // OK — no `undefined`
@@ -24,17 +25,17 @@ import { type BoundedLengthArray, type FixedLengthArray, type MaxLengthArray, ty
24
25
  * const asRgb = Arr.asFixedLengthArray(3);
25
26
  * const green = asRgb([0, 255, 0]);
26
27
  *
27
- * // Arr.asFixedLengthArray([255, 128], 3); // throws TypeError
28
+ * // Arr.asFixedLengthArray(3, [255, 128]); // throws TypeError
28
29
  * ```
29
30
  *
30
- * @template Xs - The input array type (tuple types are preserved).
31
31
  * @template Length - The exact number of elements.
32
- * @param xs - The array to cast.
32
+ * @template Xs - The input array type (tuple types are preserved).
33
33
  * @param length - The exact number of elements.
34
+ * @param xs - The array to cast.
34
35
  * @returns `xs` typed as `FixedLengthArray<Length, Xs[number]> & Xs`.
35
36
  * @throws {TypeError} If `xs.length !== length`.
36
37
  */
37
- export declare function asFixedLengthArray<Xs extends readonly unknown[], Length extends SupportedLength>(xs: Xs, length: Length): FixedLengthArray<Length, Xs[number]> & Xs;
38
+ export declare function asFixedLengthArray<Length extends SupportedLength, Xs extends readonly unknown[]>(length: Length, xs: Xs): FixedLengthArray<Length, Xs[number]> & Xs;
38
39
  export declare function asFixedLengthArray<Length extends SupportedLength>(length: Length): <Xs extends readonly unknown[]>(xs: Xs) => FixedLengthArray<Length, Xs[number]> & Xs;
39
40
  /**
40
41
  * Casts an array to `MinLengthArray<MinLength, E>` after checking that it has
@@ -46,13 +47,14 @@ export declare function asFixedLengthArray<Length extends SupportedLength>(lengt
46
47
  * structural tuple prefix (indexed access below `min(N, 10)` without
47
48
  * `undefined` under `noUncheckedIndexedAccess`).
48
49
  *
49
- * Supports a curried overload: calling it with only `minLength` returns a
50
- * function that casts an array, which is convenient for `pipe`/`map`.
50
+ * The length argument comes first, matching the type-parameter order of
51
+ * `MinLengthArray<MinLength, Elm>`. Omitting the array returns a function that
52
+ * casts one, which is convenient for `pipe`/`map`.
51
53
  *
52
54
  * @example
53
55
  *
54
56
  * ```ts
55
- * const history = Arr.asMinLengthArray([0, 1, 2, 3], 3);
57
+ * const history = Arr.asMinLengthArray(3, [0, 1, 2, 3]);
56
58
  *
57
59
  * const nonEmpty: MinLengthArray<1, number> = history; // OK (3 >= 1)
58
60
  * const first: number = history[0]; // OK — no `undefined`
@@ -61,17 +63,17 @@ export declare function asFixedLengthArray<Length extends SupportedLength>(lengt
61
63
  * const asHistory = Arr.asMinLengthArray(3);
62
64
  * const next = asHistory([4, 5, 6, 7]);
63
65
  *
64
- * // Arr.asMinLengthArray([0], 3); // throws TypeError
66
+ * // Arr.asMinLengthArray(3, [0]); // throws TypeError
65
67
  * ```
66
68
  *
67
- * @template Xs - The input array type (tuple types are preserved).
68
69
  * @template MinLength - The minimum number of elements (inclusive).
69
- * @param xs - The array to cast.
70
+ * @template Xs - The input array type (tuple types are preserved).
70
71
  * @param minLength - The minimum number of elements (inclusive).
72
+ * @param xs - The array to cast.
71
73
  * @returns `xs` typed as `MinLengthArray<MinLength, Xs[number]> & Xs`.
72
74
  * @throws {TypeError} If `xs.length < minLength`.
73
75
  */
74
- export declare function asMinLengthArray<Xs extends readonly unknown[], MinLength extends SupportedLength>(xs: Xs, minLength: MinLength): MinLengthArray<MinLength, Xs[number]> & Xs;
76
+ export declare function asMinLengthArray<MinLength extends SupportedLength, Xs extends readonly unknown[]>(minLength: MinLength, xs: Xs): MinLengthArray<MinLength, Xs[number]> & Xs;
75
77
  export declare function asMinLengthArray<MinLength extends SupportedLength>(minLength: MinLength): <Xs extends readonly unknown[]>(xs: Xs) => MinLengthArray<MinLength, Xs[number]> & Xs;
76
78
  /**
77
79
  * Casts an array to `MaxLengthArray<MaxLength, E>` after checking that it has
@@ -81,13 +83,14 @@ export declare function asMinLengthArray<MinLength extends SupportedLength>(minL
81
83
  * length is verified at runtime, and the original array type (e.g. tuple
82
84
  * types) is preserved via intersection.
83
85
  *
84
- * Supports a curried overload: calling it with only `maxLength` returns a
85
- * function that casts an array, which is convenient for `pipe`/`map`.
86
+ * The length argument comes first, matching the type-parameter order of
87
+ * `MaxLengthArray<MaxLength, Elm>`. Omitting the array returns a function that
88
+ * casts one, which is convenient for `pipe`/`map`.
86
89
  *
87
90
  * @example
88
91
  *
89
92
  * ```ts
90
- * const tags = Arr.asMaxLengthArray(['a', 'b', 'c'], 8);
93
+ * const tags = Arr.asMaxLengthArray(8, ['a', 'b', 'c']);
91
94
  *
92
95
  * const relaxed: MaxLengthArray<16, string> = tags; // OK (8 <= 16)
93
96
  *
@@ -95,17 +98,17 @@ export declare function asMinLengthArray<MinLength extends SupportedLength>(minL
95
98
  * const asTags = Arr.asMaxLengthArray(8);
96
99
  * const more = asTags(['d', 'e']);
97
100
  *
98
- * // Arr.asMaxLengthArray(['a', 'b', 'c'], 2); // throws TypeError
101
+ * // Arr.asMaxLengthArray(2, ['a', 'b', 'c']); // throws TypeError
99
102
  * ```
100
103
  *
101
- * @template Xs - The input array type (tuple types are preserved).
102
104
  * @template MaxLength - The maximum number of elements (inclusive).
103
- * @param xs - The array to cast.
105
+ * @template Xs - The input array type (tuple types are preserved).
104
106
  * @param maxLength - The maximum number of elements (inclusive).
107
+ * @param xs - The array to cast.
105
108
  * @returns `xs` typed as `MaxLengthArray<MaxLength, Xs[number]> & Xs`.
106
109
  * @throws {TypeError} If `xs.length > maxLength`.
107
110
  */
108
- export declare function asMaxLengthArray<Xs extends readonly unknown[], MaxLength extends SupportedLength>(xs: Xs, maxLength: MaxLength): MaxLengthArray<MaxLength, Xs[number]> & Xs;
111
+ export declare function asMaxLengthArray<MaxLength extends SupportedLength, Xs extends readonly unknown[]>(maxLength: MaxLength, xs: Xs): MaxLengthArray<MaxLength, Xs[number]> & Xs;
109
112
  export declare function asMaxLengthArray<MaxLength extends SupportedLength>(maxLength: MaxLength): <Xs extends readonly unknown[]>(xs: Xs) => MaxLengthArray<MaxLength, Xs[number]> & Xs;
110
113
  /**
111
114
  * Casts an array to `BoundedLengthArray<MinLength, MaxLength, E>` after
@@ -117,14 +120,14 @@ export declare function asMaxLengthArray<MaxLength extends SupportedLength>(maxL
117
120
  * at runtime, and the original array type (e.g. tuple types) is preserved via
118
121
  * intersection.
119
122
  *
120
- * Supports a curried overload: calling it with only `minLength` and
121
- * `maxLength` returns a function that casts an array, which is convenient for
122
- * `pipe`/`map`.
123
+ * The length arguments come first, matching the type-parameter order of
124
+ * `BoundedLengthArray<MinLength, MaxLength, Elm>`. Omitting the array returns a
125
+ * function that casts one, which is convenient for `pipe`/`map`.
123
126
  *
124
127
  * @example
125
128
  *
126
129
  * ```ts
127
- * const selection = Arr.asBoundedLengthArray([1, 2, 3], 1, 5);
130
+ * const selection = Arr.asBoundedLengthArray(1, 5, [1, 2, 3]);
128
131
  *
129
132
  * const relaxed: BoundedLengthArray<0, 100, number> = selection; // OK
130
133
  *
@@ -132,21 +135,45 @@ export declare function asMaxLengthArray<MaxLength extends SupportedLength>(maxL
132
135
  * const asSelection = Arr.asBoundedLengthArray(1, 5);
133
136
  * const next = asSelection([4, 5]);
134
137
  *
135
- * // Arr.asBoundedLengthArray([], 1, 5); // throws TypeError
138
+ * // Arr.asBoundedLengthArray(1, 5, []); // throws TypeError
136
139
  * ```
137
140
  *
138
- * @template Xs - The input array type (tuple types are preserved).
139
141
  * @template MinLength - The minimum number of elements (inclusive).
140
142
  * @template MaxLength - The maximum number of elements (inclusive).
141
- * @param xs - The array to cast.
143
+ * @template Xs - The input array type (tuple types are preserved).
142
144
  * @param minLength - The minimum number of elements (inclusive).
143
145
  * @param maxLength - The maximum number of elements (inclusive).
146
+ * @param xs - The array to cast.
144
147
  * @returns `xs` typed as
145
148
  * `BoundedLengthArray<MinLength, MaxLength, Xs[number]> & Xs`.
146
149
  * @throws {TypeError} If `xs.length < minLength || xs.length > maxLength`.
147
150
  */
148
- export declare function asBoundedLengthArray<Xs extends readonly unknown[], MinLength extends SupportedLength, MaxLength extends SupportedLength>(xs: Xs, minLength: MinLength, maxLength: MaxLength): BoundedLengthArray<MinLength, MaxLength, Xs[number]> & Xs;
151
+ export declare function asBoundedLengthArray<MinLength extends SupportedLength, MaxLength extends SupportedLength, Xs extends readonly unknown[]>(minLength: MinLength, maxLength: MaxLength, xs: Xs): BoundedLengthArray<MinLength, MaxLength, Xs[number]> & Xs;
149
152
  export declare function asBoundedLengthArray<MinLength extends SupportedLength, MaxLength extends SupportedLength>(minLength: MinLength, maxLength: MaxLength): <Xs extends readonly unknown[]>(xs: Xs) => BoundedLengthArray<MinLength, MaxLength, Xs[number]> & Xs;
153
+ /**
154
+ * Casts an array to `FixedLengthArray<0, E>` after checking that it is empty.
155
+ *
156
+ * `Arr.isEmpty` narrows to that same type, so this is its cast counterpart —
157
+ * the length-0 specialization of {@link asFixedLengthArray}. Use this instead
158
+ * of writing `xs as unknown as FixedLengthArray<0, E>`: the length is verified
159
+ * at runtime, and the original array type is preserved via intersection.
160
+ *
161
+ * @example
162
+ *
163
+ * ```ts
164
+ * const nothing = Arr.asEmptyArray([]);
165
+ *
166
+ * const atMost5: MaxLengthArray<5, never> = nothing; // OK (0 <= 5)
167
+ *
168
+ * // Arr.asEmptyArray([1]); // throws TypeError
169
+ * ```
170
+ *
171
+ * @template Xs - The input array type (tuple types are preserved).
172
+ * @param xs - The array to cast.
173
+ * @returns `xs` typed as `FixedLengthArray<0, Xs[number]> & Xs`.
174
+ * @throws {TypeError} If `xs` is not empty.
175
+ */
176
+ export declare const asEmptyArray: <Xs extends readonly unknown[]>(xs: Xs) => FixedLengthArray<0, Xs[number]> & Xs;
150
177
  /**
151
178
  * Casts an array to `NonEmptyArray<E>` after checking that it has at least one
152
179
  * element.
@@ -1 +1 @@
1
- {"version":3,"file":"array-utils-length-bounded-array-cast.d.mts","sourceRoot":"","sources":["../../../src/array/impl/array-utils-length-bounded-array-cast.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,eAAe,EACrB,MAAM,eAAe,CAAC;AAQvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,kBAAkB,CAChC,EAAE,SAAS,SAAS,OAAO,EAAE,EAC7B,MAAM,SAAS,eAAe,EAC9B,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,gBAAgB,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC;AAGrE,wBAAgB,kBAAkB,CAAC,MAAM,SAAS,eAAe,EAC/D,MAAM,EAAE,MAAM,GACb,CAAC,EAAE,SAAS,SAAS,OAAO,EAA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e,EAEjC,EAAE,EAAE,EAAE,EACN,SAAS,EAAE,SAAS,EACpB,SAAS,EAAE,SAAS,GACnB,kBAAkB,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC;AAG7D,wBAAgB,oBAAoB,CAClC,SAAS,SAAS,eAAe,EACjC,SAAS,SAAS,eAAe,EAEjC,SAAS,EAAE,SAAS,EACpB,SAAS,EAAE,SAAS,GACnB,CAAC,EAAE,SAAS,SAAS,OAAO,EAAE,EAC/B,EAAE,EAAE,EAAE,KACH,kBAAkB,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC;AAoC/D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,eAAe,GAAI,EAAE,SAAS,SAAS,OAAO,EAAE,MACvD,EAAE,KACL,aAAa,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,EAM9B,CAAC"}
1
+ {"version":3,"file":"array-utils-length-bounded-array-cast.d.mts","sourceRoot":"","sources":["../../../src/array/impl/array-utils-length-bounded-array-cast.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,eAAe,EACrB,MAAM,eAAe,CAAC;AAQvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,SAAS,eAAe,EAC9B,EAAE,SAAS,SAAS,OAAO,EAAE,EAC7B,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,GAAG,gBAAgB,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC;AAGrE,wBAAgB,kBAAkB,CAAC,MAAM,SAAS,eAAe,EAC/D,MAAM,EAAE,MAAM,GACb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e,EACjC,EAAE,SAAS,SAAS,OAAO,EAAE,EAE7B,SAAS,EAAE,SAAS,EACpB,SAAS,EAAE,SAAS,EACpB,EAAE,EAAE,EAAE,GACL,kBAAkB,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC;AAG7D,wBAAgB,oBAAoB,CAClC,SAAS,SAAS,eAAe,EACjC,SAAS,SAAS,eAAe,EAEjC,SAAS,EAAE,SAAS,EACpB,SAAS,EAAE,SAAS,GACnB,CAAC,EAAE,SAAS,SAAS,OAAO,EAAE,EAC/B,EAAE,EAAE,EAAE,KACH,kBAAkB,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC;AAoC/D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,YAAY,GAAI,EAAE,SAAS,SAAS,OAAO,EAAE,MACpD,EAAE,KACL,gBAAgB,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,EAQpC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,eAAe,GAAI,EAAE,SAAS,SAAS,OAAO,EAAE,MACvD,EAAE,KACL,aAAa,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,EAM9B,CAAC"}
@@ -1,16 +1,16 @@
1
- import { isMinLengthArray, isBoundedLengthArray, isFixedLengthArray, isMaxLengthArray } from './array-utils-length-bounded-array-guard.mjs';
1
+ import { isFixedLengthArray, isMinLengthArray, isBoundedLengthArray, isMaxLengthArray } from './array-utils-length-bounded-array-guard.mjs';
2
2
 
3
3
  function asFixedLengthArray(...args) {
4
4
  switch (args.length) {
5
5
  case 2:
6
6
  return asFixedLengthArrayImpl(...args);
7
7
  case 1:
8
- return (xs) => asFixedLengthArrayImpl(xs, ...args);
8
+ return (xs) => asFixedLengthArrayImpl(args[0], xs);
9
9
  }
10
10
  }
11
- const asFixedLengthArrayImpl = (xs, length) => {
11
+ const asFixedLengthArrayImpl = (length, xs) => {
12
12
  const actualLength = xs.length;
13
- if (!isFixedLengthArray(xs, length)) {
13
+ if (!isFixedLengthArray(length, xs)) {
14
14
  throw new TypeError(
15
15
  `Expected an array of length ${length}, got an array of length ${actualLength}`
16
16
  );
@@ -22,12 +22,12 @@ function asMinLengthArray(...args) {
22
22
  case 2:
23
23
  return asMinLengthArrayImpl(...args);
24
24
  case 1:
25
- return (xs) => asMinLengthArrayImpl(xs, ...args);
25
+ return (xs) => asMinLengthArrayImpl(args[0], xs);
26
26
  }
27
27
  }
28
- const asMinLengthArrayImpl = (xs, minLength) => {
28
+ const asMinLengthArrayImpl = (minLength, xs) => {
29
29
  const actualLength = xs.length;
30
- if (!isMinLengthArray(xs, minLength)) {
30
+ if (!isMinLengthArray(minLength, xs)) {
31
31
  throw new TypeError(
32
32
  `Expected an array of length >= ${minLength}, got an array of length ${actualLength}`
33
33
  );
@@ -39,12 +39,12 @@ function asMaxLengthArray(...args) {
39
39
  case 2:
40
40
  return asMaxLengthArrayImpl(...args);
41
41
  case 1:
42
- return (xs) => asMaxLengthArrayImpl(xs, ...args);
42
+ return (xs) => asMaxLengthArrayImpl(args[0], xs);
43
43
  }
44
44
  }
45
- const asMaxLengthArrayImpl = (xs, maxLength) => {
45
+ const asMaxLengthArrayImpl = (maxLength, xs) => {
46
46
  const actualLength = xs.length;
47
- if (!isMaxLengthArray(xs, maxLength)) {
47
+ if (!isMaxLengthArray(maxLength, xs)) {
48
48
  throw new TypeError(
49
49
  `Expected an array of length <= ${maxLength}, got an array of length ${actualLength}`
50
50
  );
@@ -56,24 +56,32 @@ function asBoundedLengthArray(...args) {
56
56
  case 3:
57
57
  return asBoundedLengthArrayImpl(...args);
58
58
  case 2:
59
- return (xs) => asBoundedLengthArrayImpl(xs, ...args);
59
+ return (xs) => asBoundedLengthArrayImpl(args[0], args[1], xs);
60
60
  }
61
61
  }
62
- const asBoundedLengthArrayImpl = (xs, minLength, maxLength) => {
62
+ const asBoundedLengthArrayImpl = (minLength, maxLength, xs) => {
63
63
  const actualLength = xs.length;
64
- if (!isBoundedLengthArray(xs, minLength, maxLength)) {
64
+ if (!isBoundedLengthArray(minLength, maxLength, xs)) {
65
65
  throw new TypeError(
66
66
  `Expected an array of length in [${minLength}, ${maxLength}], got an array of length ${actualLength}`
67
67
  );
68
68
  }
69
69
  return xs;
70
70
  };
71
+ const asEmptyArray = (xs) => {
72
+ if (!isFixedLengthArray(0, xs)) {
73
+ throw new TypeError(
74
+ `Expected an empty array, got an array of length ${xs.length}`
75
+ );
76
+ }
77
+ return xs;
78
+ };
71
79
  const asNonEmptyArray = (xs) => {
72
- if (!isMinLengthArray(xs, 1)) {
80
+ if (!isMinLengthArray(1, xs)) {
73
81
  throw new TypeError("Expected a non-empty array, got an empty array");
74
82
  }
75
83
  return xs;
76
84
  };
77
85
 
78
- export { asBoundedLengthArray, asFixedLengthArray, asMaxLengthArray, asMinLengthArray, asNonEmptyArray };
86
+ export { asBoundedLengthArray, asEmptyArray, asFixedLengthArray, asMaxLengthArray, asMinLengthArray, asNonEmptyArray };
79
87
  //# sourceMappingURL=array-utils-length-bounded-array-cast.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"array-utils-length-bounded-array-cast.mjs","sources":["../../../src/array/impl/array-utils-length-bounded-array-cast.mts"],"sourcesContent":["import {\n type BoundedLengthArray,\n type FixedLengthArray,\n type MaxLengthArray,\n type MinLengthArray,\n type NonEmptyArray,\n type SupportedLength,\n} from 'ts-type-forge';\nimport {\n isBoundedLengthArray,\n isFixedLengthArray,\n isMaxLengthArray,\n isMinLengthArray,\n} from './array-utils-length-bounded-array-guard.mjs';\n\n/**\n * Casts an array to `FixedLengthArray<Length, E>` after checking that it has\n * exactly `length` elements.\n *\n * Use this instead of writing `xs as unknown as FixedLengthArray<N, E>`: the\n * length is verified at runtime, and the original array type (e.g. tuple\n * types) is preserved via intersection, so the result also benefits from the\n * structural tuple prefix (in-range indexed access without `undefined` under\n * `noUncheckedIndexedAccess`).\n *\n * Supports a curried overload: calling it with only `length` returns a\n * function that casts an array, which is convenient for `pipe`/`map`.\n *\n * @example\n *\n * ```ts\n * const rgb = Arr.asFixedLengthArray([255, 128, 0], 3);\n *\n * const atMost5: MaxLengthArray<5, number> = rgb; // OK (3 <= 5)\n * const red: number = rgb[0]; // OK — no `undefined`\n *\n * // curried version\n * const asRgb = Arr.asFixedLengthArray(3);\n * const green = asRgb([0, 255, 0]);\n *\n * // Arr.asFixedLengthArray([255, 128], 3); // throws TypeError\n * ```\n *\n * @template Xs - The input array type (tuple types are preserved).\n * @template Length - The exact number of elements.\n * @param xs - The array to cast.\n * @param length - The exact number of elements.\n * @returns `xs` typed as `FixedLengthArray<Length, Xs[number]> & Xs`.\n * @throws {TypeError} If `xs.length !== length`.\n */\nexport function asFixedLengthArray<\n Xs extends readonly unknown[],\n Length extends SupportedLength,\n>(xs: Xs, length: Length): FixedLengthArray<Length, Xs[number]> & Xs;\n\n// Curried version\nexport function asFixedLengthArray<Length extends SupportedLength>(\n length: Length,\n): <Xs extends readonly unknown[]>(\n xs: Xs,\n) => FixedLengthArray<Length, Xs[number]> & Xs;\n\nexport function asFixedLengthArray<E>(\n ...args:\n | readonly [xs: readonly E[], length: SupportedLength]\n | readonly [length: SupportedLength]\n): readonly E[] | ((xs: readonly E[]) => readonly E[]) {\n switch (args.length) {\n case 2:\n return asFixedLengthArrayImpl(...args);\n\n case 1:\n return (xs) => asFixedLengthArrayImpl(xs, ...args);\n }\n}\n\nconst asFixedLengthArrayImpl = <E,>(\n xs: readonly E[],\n length: SupportedLength,\n): readonly E[] => {\n const actualLength = xs.length;\n\n if (!isFixedLengthArray(xs, length)) {\n throw new TypeError(\n `Expected an array of length ${length}, got an array of length ${actualLength}`,\n );\n }\n\n return xs;\n};\n\n/**\n * Casts an array to `MinLengthArray<MinLength, E>` after checking that it has\n * at least `minLength` elements.\n *\n * Use this instead of writing `xs as unknown as MinLengthArray<N, E>`: the\n * length is verified at runtime, and the original array type (e.g. tuple\n * types) is preserved via intersection, so the result also benefits from the\n * structural tuple prefix (indexed access below `min(N, 10)` without\n * `undefined` under `noUncheckedIndexedAccess`).\n *\n * Supports a curried overload: calling it with only `minLength` returns a\n * function that casts an array, which is convenient for `pipe`/`map`.\n *\n * @example\n *\n * ```ts\n * const history = Arr.asMinLengthArray([0, 1, 2, 3], 3);\n *\n * const nonEmpty: MinLengthArray<1, number> = history; // OK (3 >= 1)\n * const first: number = history[0]; // OK — no `undefined`\n *\n * // curried version\n * const asHistory = Arr.asMinLengthArray(3);\n * const next = asHistory([4, 5, 6, 7]);\n *\n * // Arr.asMinLengthArray([0], 3); // throws TypeError\n * ```\n *\n * @template Xs - The input array type (tuple types are preserved).\n * @template MinLength - The minimum number of elements (inclusive).\n * @param xs - The array to cast.\n * @param minLength - The minimum number of elements (inclusive).\n * @returns `xs` typed as `MinLengthArray<MinLength, Xs[number]> & Xs`.\n * @throws {TypeError} If `xs.length < minLength`.\n */\nexport function asMinLengthArray<\n Xs extends readonly unknown[],\n MinLength extends SupportedLength,\n>(xs: Xs, minLength: MinLength): MinLengthArray<MinLength, Xs[number]> & Xs;\n\n// Curried version\nexport function asMinLengthArray<MinLength extends SupportedLength>(\n minLength: MinLength,\n): <Xs extends readonly unknown[]>(\n xs: Xs,\n) => MinLengthArray<MinLength, Xs[number]> & Xs;\n\nexport function asMinLengthArray<E>(\n ...args:\n | readonly [xs: readonly E[], minLength: SupportedLength]\n | readonly [minLength: SupportedLength]\n): readonly E[] | ((xs: readonly E[]) => readonly E[]) {\n switch (args.length) {\n case 2:\n return asMinLengthArrayImpl(...args);\n\n case 1:\n return (xs) => asMinLengthArrayImpl(xs, ...args);\n }\n}\n\nconst asMinLengthArrayImpl = <E,>(\n xs: readonly E[],\n minLength: SupportedLength,\n): readonly E[] => {\n const actualLength = xs.length;\n\n if (!isMinLengthArray(xs, minLength)) {\n throw new TypeError(\n `Expected an array of length >= ${minLength}, got an array of length ${actualLength}`,\n );\n }\n\n return xs;\n};\n\n/**\n * Casts an array to `MaxLengthArray<MaxLength, E>` after checking that it has\n * at most `maxLength` elements.\n *\n * Use this instead of writing `xs as unknown as MaxLengthArray<N, E>`: the\n * length is verified at runtime, and the original array type (e.g. tuple\n * types) is preserved via intersection.\n *\n * Supports a curried overload: calling it with only `maxLength` returns a\n * function that casts an array, which is convenient for `pipe`/`map`.\n *\n * @example\n *\n * ```ts\n * const tags = Arr.asMaxLengthArray(['a', 'b', 'c'], 8);\n *\n * const relaxed: MaxLengthArray<16, string> = tags; // OK (8 <= 16)\n *\n * // curried version\n * const asTags = Arr.asMaxLengthArray(8);\n * const more = asTags(['d', 'e']);\n *\n * // Arr.asMaxLengthArray(['a', 'b', 'c'], 2); // throws TypeError\n * ```\n *\n * @template Xs - The input array type (tuple types are preserved).\n * @template MaxLength - The maximum number of elements (inclusive).\n * @param xs - The array to cast.\n * @param maxLength - The maximum number of elements (inclusive).\n * @returns `xs` typed as `MaxLengthArray<MaxLength, Xs[number]> & Xs`.\n * @throws {TypeError} If `xs.length > maxLength`.\n */\nexport function asMaxLengthArray<\n Xs extends readonly unknown[],\n MaxLength extends SupportedLength,\n>(xs: Xs, maxLength: MaxLength): MaxLengthArray<MaxLength, Xs[number]> & Xs;\n\n// Curried version\nexport function asMaxLengthArray<MaxLength extends SupportedLength>(\n maxLength: MaxLength,\n): <Xs extends readonly unknown[]>(\n xs: Xs,\n) => MaxLengthArray<MaxLength, Xs[number]> & Xs;\n\nexport function asMaxLengthArray<E>(\n ...args:\n | readonly [xs: readonly E[], maxLength: SupportedLength]\n | readonly [maxLength: SupportedLength]\n): readonly E[] | ((xs: readonly E[]) => readonly E[]) {\n switch (args.length) {\n case 2:\n return asMaxLengthArrayImpl(...args);\n\n case 1:\n return (xs) => asMaxLengthArrayImpl(xs, ...args);\n }\n}\n\nconst asMaxLengthArrayImpl = <E,>(\n xs: readonly E[],\n maxLength: SupportedLength,\n): readonly E[] => {\n const actualLength = xs.length;\n\n if (!isMaxLengthArray(xs, maxLength)) {\n throw new TypeError(\n `Expected an array of length <= ${maxLength}, got an array of length ${actualLength}`,\n );\n }\n\n return xs;\n};\n\n/**\n * Casts an array to `BoundedLengthArray<MinLength, MaxLength, E>` after\n * checking that its length is within the inclusive range\n * `[minLength, maxLength]`.\n *\n * Use this instead of writing\n * `xs as unknown as BoundedLengthArray<Min, Max, E>`: the length is verified\n * at runtime, and the original array type (e.g. tuple types) is preserved via\n * intersection.\n *\n * Supports a curried overload: calling it with only `minLength` and\n * `maxLength` returns a function that casts an array, which is convenient for\n * `pipe`/`map`.\n *\n * @example\n *\n * ```ts\n * const selection = Arr.asBoundedLengthArray([1, 2, 3], 1, 5);\n *\n * const relaxed: BoundedLengthArray<0, 100, number> = selection; // OK\n *\n * // curried version\n * const asSelection = Arr.asBoundedLengthArray(1, 5);\n * const next = asSelection([4, 5]);\n *\n * // Arr.asBoundedLengthArray([], 1, 5); // throws TypeError\n * ```\n *\n * @template Xs - The input array type (tuple types are preserved).\n * @template MinLength - The minimum number of elements (inclusive).\n * @template MaxLength - The maximum number of elements (inclusive).\n * @param xs - The array to cast.\n * @param minLength - The minimum number of elements (inclusive).\n * @param maxLength - The maximum number of elements (inclusive).\n * @returns `xs` typed as\n * `BoundedLengthArray<MinLength, MaxLength, Xs[number]> & Xs`.\n * @throws {TypeError} If `xs.length < minLength || xs.length > maxLength`.\n */\nexport function asBoundedLengthArray<\n Xs extends readonly unknown[],\n MinLength extends SupportedLength,\n MaxLength extends SupportedLength,\n>(\n xs: Xs,\n minLength: MinLength,\n maxLength: MaxLength,\n): BoundedLengthArray<MinLength, MaxLength, Xs[number]> & Xs;\n\n// Curried version\nexport function asBoundedLengthArray<\n MinLength extends SupportedLength,\n MaxLength extends SupportedLength,\n>(\n minLength: MinLength,\n maxLength: MaxLength,\n): <Xs extends readonly unknown[]>(\n xs: Xs,\n) => BoundedLengthArray<MinLength, MaxLength, Xs[number]> & Xs;\n\nexport function asBoundedLengthArray<E>(\n ...args:\n | readonly [\n xs: readonly E[],\n minLength: SupportedLength,\n maxLength: SupportedLength,\n ]\n | readonly [minLength: SupportedLength, maxLength: SupportedLength]\n): readonly E[] | ((xs: readonly E[]) => readonly E[]) {\n switch (args.length) {\n case 3:\n return asBoundedLengthArrayImpl(...args);\n\n case 2:\n return (xs) => asBoundedLengthArrayImpl(xs, ...args);\n }\n}\n\nconst asBoundedLengthArrayImpl = <E,>(\n xs: readonly E[],\n minLength: SupportedLength,\n maxLength: SupportedLength,\n): readonly E[] => {\n const actualLength = xs.length;\n\n if (!isBoundedLengthArray(xs, minLength, maxLength)) {\n throw new TypeError(\n `Expected an array of length in [${minLength}, ${maxLength}], got an array of length ${actualLength}`,\n );\n }\n\n return xs;\n};\n\n/**\n * Casts an array to `NonEmptyArray<E>` after checking that it has at least one\n * element.\n *\n * `NonEmptyArray<E>` is an alias of `MinLengthArray<1, E>`, so this is the\n * length-1 specialization of {@link asMinLengthArray}. Use this instead of\n * writing `xs as unknown as NonEmptyArray<E>`: the length is verified at\n * runtime, and the original array type (e.g. tuple types) is preserved via\n * intersection, so the result also benefits from the structural tuple prefix\n * (`xs[0]` without `undefined` under `noUncheckedIndexedAccess`).\n *\n * @example\n *\n * ```ts\n * const history = Arr.asNonEmptyArray([0, 1, 2, 3]);\n *\n * const first: number = history[0]; // OK — no `undefined`\n *\n * // Arr.asNonEmptyArray([]); // throws TypeError\n * ```\n *\n * @template Xs - The input array type (tuple types are preserved).\n * @param xs - The array to cast.\n * @returns `xs` typed as `NonEmptyArray<Xs[number]> & Xs`.\n * @throws {TypeError} If `xs` is empty.\n */\nexport const asNonEmptyArray = <Xs extends readonly unknown[]>(\n xs: Xs,\n): NonEmptyArray<Xs[number]> & Xs => {\n if (!isMinLengthArray(xs, 1)) {\n throw new TypeError('Expected a non-empty array, got an empty array');\n }\n\n return xs;\n};\n"],"names":[],"mappings":";;AA8DO,SAAS,sBACX,IAAA,EAGkD;AACrD,EAAA,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,CAAA;AAAA,EACtE;AAEA,EAAA,OAAO,EAAA;AACT;;;;"}
1
+ {"version":3,"file":"array-utils-length-bounded-array-cast.mjs","sources":["../../../src/array/impl/array-utils-length-bounded-array-cast.mts"],"sourcesContent":["import {\n type BoundedLengthArray,\n type FixedLengthArray,\n type MaxLengthArray,\n type MinLengthArray,\n type NonEmptyArray,\n type SupportedLength,\n} from 'ts-type-forge';\nimport {\n isBoundedLengthArray,\n isFixedLengthArray,\n isMaxLengthArray,\n isMinLengthArray,\n} from './array-utils-length-bounded-array-guard.mjs';\n\n/**\n * Casts an array to `FixedLengthArray<Length, E>` after checking that it has\n * exactly `length` elements.\n *\n * Use this instead of writing `xs as unknown as FixedLengthArray<N, E>`: the\n * length is verified at runtime, and the original array type (e.g. tuple\n * types) is preserved via intersection, so the result also benefits from the\n * structural tuple prefix (in-range indexed access without `undefined` under\n * `noUncheckedIndexedAccess`).\n *\n * The length argument comes first, matching the type-parameter order of\n * `FixedLengthArray<Length, Elm>`. Omitting the array returns a function that\n * casts one, which is convenient for `pipe`/`map`.\n *\n * @example\n *\n * ```ts\n * const rgb = Arr.asFixedLengthArray(3, [255, 128, 0]);\n *\n * const atMost5: MaxLengthArray<5, number> = rgb; // OK (3 <= 5)\n * const red: number = rgb[0]; // OK — no `undefined`\n *\n * // curried version\n * const asRgb = Arr.asFixedLengthArray(3);\n * const green = asRgb([0, 255, 0]);\n *\n * // Arr.asFixedLengthArray(3, [255, 128]); // throws TypeError\n * ```\n *\n * @template Length - The exact number of elements.\n * @template Xs - The input array type (tuple types are preserved).\n * @param length - The exact number of elements.\n * @param xs - The array to cast.\n * @returns `xs` typed as `FixedLengthArray<Length, Xs[number]> & Xs`.\n * @throws {TypeError} If `xs.length !== length`.\n */\nexport function asFixedLengthArray<\n Length extends SupportedLength,\n Xs extends readonly unknown[],\n>(length: Length, xs: Xs): FixedLengthArray<Length, Xs[number]> & Xs;\n\n// Curried version\nexport function asFixedLengthArray<Length extends SupportedLength>(\n length: Length,\n): <Xs extends readonly unknown[]>(\n xs: Xs,\n) => FixedLengthArray<Length, Xs[number]> & Xs;\n\nexport function asFixedLengthArray<E>(\n ...args:\n | readonly [length: SupportedLength, xs: readonly E[]]\n | readonly [length: SupportedLength]\n): readonly E[] | ((xs: readonly E[]) => readonly E[]) {\n switch (args.length) {\n case 2:\n return asFixedLengthArrayImpl(...args);\n\n case 1:\n return (xs) => asFixedLengthArrayImpl(args[0], xs);\n }\n}\n\nconst asFixedLengthArrayImpl = <E,>(\n length: SupportedLength,\n xs: readonly E[],\n): readonly E[] => {\n const actualLength = xs.length;\n\n if (!isFixedLengthArray(length, xs)) {\n throw new TypeError(\n `Expected an array of length ${length}, got an array of length ${actualLength}`,\n );\n }\n\n return xs;\n};\n\n/**\n * Casts an array to `MinLengthArray<MinLength, E>` after checking that it has\n * at least `minLength` elements.\n *\n * Use this instead of writing `xs as unknown as MinLengthArray<N, E>`: the\n * length is verified at runtime, and the original array type (e.g. tuple\n * types) is preserved via intersection, so the result also benefits from the\n * structural tuple prefix (indexed access below `min(N, 10)` without\n * `undefined` under `noUncheckedIndexedAccess`).\n *\n * The length argument comes first, matching the type-parameter order of\n * `MinLengthArray<MinLength, Elm>`. Omitting the array returns a function that\n * casts one, which is convenient for `pipe`/`map`.\n *\n * @example\n *\n * ```ts\n * const history = Arr.asMinLengthArray(3, [0, 1, 2, 3]);\n *\n * const nonEmpty: MinLengthArray<1, number> = history; // OK (3 >= 1)\n * const first: number = history[0]; // OK — no `undefined`\n *\n * // curried version\n * const asHistory = Arr.asMinLengthArray(3);\n * const next = asHistory([4, 5, 6, 7]);\n *\n * // Arr.asMinLengthArray(3, [0]); // throws TypeError\n * ```\n *\n * @template MinLength - The minimum number of elements (inclusive).\n * @template Xs - The input array type (tuple types are preserved).\n * @param minLength - The minimum number of elements (inclusive).\n * @param xs - The array to cast.\n * @returns `xs` typed as `MinLengthArray<MinLength, Xs[number]> & Xs`.\n * @throws {TypeError} If `xs.length < minLength`.\n */\nexport function asMinLengthArray<\n MinLength extends SupportedLength,\n Xs extends readonly unknown[],\n>(minLength: MinLength, xs: Xs): MinLengthArray<MinLength, Xs[number]> & Xs;\n\n// Curried version\nexport function asMinLengthArray<MinLength extends SupportedLength>(\n minLength: MinLength,\n): <Xs extends readonly unknown[]>(\n xs: Xs,\n) => MinLengthArray<MinLength, Xs[number]> & Xs;\n\nexport function asMinLengthArray<E>(\n ...args:\n | readonly [minLength: SupportedLength, xs: readonly E[]]\n | readonly [minLength: SupportedLength]\n): readonly E[] | ((xs: readonly E[]) => readonly E[]) {\n switch (args.length) {\n case 2:\n return asMinLengthArrayImpl(...args);\n\n case 1:\n return (xs) => asMinLengthArrayImpl(args[0], xs);\n }\n}\n\nconst asMinLengthArrayImpl = <E,>(\n minLength: SupportedLength,\n xs: readonly E[],\n): readonly E[] => {\n const actualLength = xs.length;\n\n if (!isMinLengthArray(minLength, xs)) {\n throw new TypeError(\n `Expected an array of length >= ${minLength}, got an array of length ${actualLength}`,\n );\n }\n\n return xs;\n};\n\n/**\n * Casts an array to `MaxLengthArray<MaxLength, E>` after checking that it has\n * at most `maxLength` elements.\n *\n * Use this instead of writing `xs as unknown as MaxLengthArray<N, E>`: the\n * length is verified at runtime, and the original array type (e.g. tuple\n * types) is preserved via intersection.\n *\n * The length argument comes first, matching the type-parameter order of\n * `MaxLengthArray<MaxLength, Elm>`. Omitting the array returns a function that\n * casts one, which is convenient for `pipe`/`map`.\n *\n * @example\n *\n * ```ts\n * const tags = Arr.asMaxLengthArray(8, ['a', 'b', 'c']);\n *\n * const relaxed: MaxLengthArray<16, string> = tags; // OK (8 <= 16)\n *\n * // curried version\n * const asTags = Arr.asMaxLengthArray(8);\n * const more = asTags(['d', 'e']);\n *\n * // Arr.asMaxLengthArray(2, ['a', 'b', 'c']); // throws TypeError\n * ```\n *\n * @template MaxLength - The maximum number of elements (inclusive).\n * @template Xs - The input array type (tuple types are preserved).\n * @param maxLength - The maximum number of elements (inclusive).\n * @param xs - The array to cast.\n * @returns `xs` typed as `MaxLengthArray<MaxLength, Xs[number]> & Xs`.\n * @throws {TypeError} If `xs.length > maxLength`.\n */\nexport function asMaxLengthArray<\n MaxLength extends SupportedLength,\n Xs extends readonly unknown[],\n>(maxLength: MaxLength, xs: Xs): MaxLengthArray<MaxLength, Xs[number]> & Xs;\n\n// Curried version\nexport function asMaxLengthArray<MaxLength extends SupportedLength>(\n maxLength: MaxLength,\n): <Xs extends readonly unknown[]>(\n xs: Xs,\n) => MaxLengthArray<MaxLength, Xs[number]> & Xs;\n\nexport function asMaxLengthArray<E>(\n ...args:\n | readonly [maxLength: SupportedLength, xs: readonly E[]]\n | readonly [maxLength: SupportedLength]\n): readonly E[] | ((xs: readonly E[]) => readonly E[]) {\n switch (args.length) {\n case 2:\n return asMaxLengthArrayImpl(...args);\n\n case 1:\n return (xs) => asMaxLengthArrayImpl(args[0], xs);\n }\n}\n\nconst asMaxLengthArrayImpl = <E,>(\n maxLength: SupportedLength,\n xs: readonly E[],\n): readonly E[] => {\n const actualLength = xs.length;\n\n if (!isMaxLengthArray(maxLength, xs)) {\n throw new TypeError(\n `Expected an array of length <= ${maxLength}, got an array of length ${actualLength}`,\n );\n }\n\n return xs;\n};\n\n/**\n * Casts an array to `BoundedLengthArray<MinLength, MaxLength, E>` after\n * checking that its length is within the inclusive range\n * `[minLength, maxLength]`.\n *\n * Use this instead of writing\n * `xs as unknown as BoundedLengthArray<Min, Max, E>`: the length is verified\n * at runtime, and the original array type (e.g. tuple types) is preserved via\n * intersection.\n *\n * The length arguments come first, matching the type-parameter order of\n * `BoundedLengthArray<MinLength, MaxLength, Elm>`. Omitting the array returns a\n * function that casts one, which is convenient for `pipe`/`map`.\n *\n * @example\n *\n * ```ts\n * const selection = Arr.asBoundedLengthArray(1, 5, [1, 2, 3]);\n *\n * const relaxed: BoundedLengthArray<0, 100, number> = selection; // OK\n *\n * // curried version\n * const asSelection = Arr.asBoundedLengthArray(1, 5);\n * const next = asSelection([4, 5]);\n *\n * // Arr.asBoundedLengthArray(1, 5, []); // throws TypeError\n * ```\n *\n * @template MinLength - The minimum number of elements (inclusive).\n * @template MaxLength - The maximum number of elements (inclusive).\n * @template Xs - The input array type (tuple types are preserved).\n * @param minLength - The minimum number of elements (inclusive).\n * @param maxLength - The maximum number of elements (inclusive).\n * @param xs - The array to cast.\n * @returns `xs` typed as\n * `BoundedLengthArray<MinLength, MaxLength, Xs[number]> & Xs`.\n * @throws {TypeError} If `xs.length < minLength || xs.length > maxLength`.\n */\nexport function asBoundedLengthArray<\n MinLength extends SupportedLength,\n MaxLength extends SupportedLength,\n Xs extends readonly unknown[],\n>(\n minLength: MinLength,\n maxLength: MaxLength,\n xs: Xs,\n): BoundedLengthArray<MinLength, MaxLength, Xs[number]> & Xs;\n\n// Curried version\nexport function asBoundedLengthArray<\n MinLength extends SupportedLength,\n MaxLength extends SupportedLength,\n>(\n minLength: MinLength,\n maxLength: MaxLength,\n): <Xs extends readonly unknown[]>(\n xs: Xs,\n) => BoundedLengthArray<MinLength, MaxLength, Xs[number]> & Xs;\n\nexport function asBoundedLengthArray<E>(\n ...args:\n | readonly [\n minLength: SupportedLength,\n maxLength: SupportedLength,\n xs: readonly E[],\n ]\n | readonly [minLength: SupportedLength, maxLength: SupportedLength]\n): readonly E[] | ((xs: readonly E[]) => readonly E[]) {\n switch (args.length) {\n case 3:\n return asBoundedLengthArrayImpl(...args);\n\n case 2:\n return (xs) => asBoundedLengthArrayImpl(args[0], args[1], xs);\n }\n}\n\nconst asBoundedLengthArrayImpl = <E,>(\n minLength: SupportedLength,\n maxLength: SupportedLength,\n xs: readonly E[],\n): readonly E[] => {\n const actualLength = xs.length;\n\n if (!isBoundedLengthArray(minLength, maxLength, xs)) {\n throw new TypeError(\n `Expected an array of length in [${minLength}, ${maxLength}], got an array of length ${actualLength}`,\n );\n }\n\n return xs;\n};\n\n/**\n * Casts an array to `FixedLengthArray<0, E>` after checking that it is empty.\n *\n * `Arr.isEmpty` narrows to that same type, so this is its cast counterpart —\n * the length-0 specialization of {@link asFixedLengthArray}. Use this instead\n * of writing `xs as unknown as FixedLengthArray<0, E>`: the length is verified\n * at runtime, and the original array type is preserved via intersection.\n *\n * @example\n *\n * ```ts\n * const nothing = Arr.asEmptyArray([]);\n *\n * const atMost5: MaxLengthArray<5, never> = nothing; // OK (0 <= 5)\n *\n * // Arr.asEmptyArray([1]); // throws TypeError\n * ```\n *\n * @template Xs - The input array type (tuple types are preserved).\n * @param xs - The array to cast.\n * @returns `xs` typed as `FixedLengthArray<0, Xs[number]> & Xs`.\n * @throws {TypeError} If `xs` is not empty.\n */\nexport const asEmptyArray = <Xs extends readonly unknown[]>(\n xs: Xs,\n): FixedLengthArray<0, Xs[number]> & Xs => {\n if (!isFixedLengthArray(0, xs)) {\n throw new TypeError(\n `Expected an empty array, got an array of length ${xs.length}`,\n );\n }\n\n return xs;\n};\n\n/**\n * Casts an array to `NonEmptyArray<E>` after checking that it has at least one\n * element.\n *\n * `NonEmptyArray<E>` is an alias of `MinLengthArray<1, E>`, so this is the\n * length-1 specialization of {@link asMinLengthArray}. Use this instead of\n * writing `xs as unknown as NonEmptyArray<E>`: the length is verified at\n * runtime, and the original array type (e.g. tuple types) is preserved via\n * intersection, so the result also benefits from the structural tuple prefix\n * (`xs[0]` without `undefined` under `noUncheckedIndexedAccess`).\n *\n * @example\n *\n * ```ts\n * const history = Arr.asNonEmptyArray([0, 1, 2, 3]);\n *\n * const first: number = history[0]; // OK — no `undefined`\n *\n * // Arr.asNonEmptyArray([]); // throws TypeError\n * ```\n *\n * @template Xs - The input array type (tuple types are preserved).\n * @param xs - The array to cast.\n * @returns `xs` typed as `NonEmptyArray<Xs[number]> & Xs`.\n * @throws {TypeError} If `xs` is empty.\n */\nexport const asNonEmptyArray = <Xs extends readonly unknown[]>(\n xs: Xs,\n): NonEmptyArray<Xs[number]> & Xs => {\n if (!isMinLengthArray(1, xs)) {\n throw new TypeError('Expected a non-empty array, got an empty array');\n }\n\n return xs;\n};\n"],"names":[],"mappings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