ts-data-forge 12.2.0 → 12.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -6
- package/dist/array/impl/array-utils-creation.d.mts +1 -1
- package/dist/array/impl/array-utils-creation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-element-access.d.mts +1 -1
- package/dist/array/impl/array-utils-element-access.d.mts.map +1 -1
- package/dist/array/impl/array-utils-element-access.mjs +10 -13
- package/dist/array/impl/array-utils-element-access.mjs.map +1 -1
- package/dist/array/impl/array-utils-iterators.d.mts +1 -1
- package/dist/array/impl/array-utils-iterators.d.mts.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-array-cast.d.mts.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-array-cast.mjs +53 -53
- package/dist/array/impl/array-utils-length-bounded-array-cast.mjs.map +1 -1
- package/dist/array/impl/array-utils-modification.d.mts.map +1 -1
- package/dist/array/impl/array-utils-modification.mjs +61 -70
- package/dist/array/impl/array-utils-modification.mjs.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.d.mts.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.mjs +37 -47
- package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
- package/dist/array/impl/array-utils-search.d.mts.map +1 -1
- package/dist/array/impl/array-utils-search.mjs +80 -92
- package/dist/array/impl/array-utils-search.mjs.map +1 -1
- package/dist/array/impl/array-utils-set-op.d.mts +1 -1
- package/dist/array/impl/array-utils-set-op.d.mts.map +1 -1
- package/dist/array/impl/array-utils-size.d.mts +1 -1
- package/dist/array/impl/array-utils-size.d.mts.map +1 -1
- package/dist/array/impl/array-utils-slice-clamped.mjs +9 -10
- package/dist/array/impl/array-utils-slice-clamped.mjs.map +1 -1
- package/dist/array/impl/array-utils-slicing.d.mts +1 -1
- package/dist/array/impl/array-utils-slicing.d.mts.map +1 -1
- package/dist/array/impl/array-utils-slicing.mjs +20 -32
- package/dist/array/impl/array-utils-slicing.mjs.map +1 -1
- package/dist/array/impl/array-utils-transformation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-transformation.mjs +41 -52
- package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
- package/dist/array/impl/array-utils-validation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-validation.mjs +10 -16
- package/dist/array/impl/array-utils-validation.mjs.map +1 -1
- package/dist/json/json.mjs +1 -1
- package/dist/json/json.mjs.map +1 -1
- package/dist/number/branded-types/finite-number.d.mts +6 -3
- package/dist/number/branded-types/finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/negative-finite-number.d.mts +8 -4
- package/dist/number/branded-types/negative-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/negative-int.d.mts +2 -1
- package/dist/number/branded-types/negative-int.d.mts.map +1 -1
- package/dist/number/branded-types/negative-safe-int.d.mts +2 -1
- package/dist/number/branded-types/negative-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.d.mts +6 -3
- package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-finite-number.d.mts +6 -3
- package/dist/number/branded-types/non-positive-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-finite-number.d.mts +6 -3
- package/dist/number/branded-types/non-zero-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/positive-finite-number.d.mts +6 -3
- package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -1
- package/dist/number/enum/int8.d.mts +26 -13
- package/dist/number/enum/int8.d.mts.map +1 -1
- package/dist/number/enum/uint8.d.mts +24 -12
- package/dist/number/enum/uint8.d.mts.map +1 -1
- package/dist/others/if-then.d.mts +1 -1
- package/dist/others/if-then.d.mts.map +1 -1
- package/dist/string/str.d.mts.map +1 -1
- package/dist/string/str.mjs +52 -52
- package/dist/string/str.mjs.map +1 -1
- package/package.json +4 -4
- package/src/array/impl/array-utils-element-access.mts +15 -16
- package/src/array/impl/array-utils-length-bounded-array-cast.mts +73 -60
- package/src/array/impl/array-utils-modification.mts +96 -94
- package/src/array/impl/array-utils-reducing-value.mts +68 -57
- package/src/array/impl/array-utils-search.mts +146 -148
- package/src/array/impl/array-utils-slice-clamped.mts +16 -14
- package/src/array/impl/array-utils-slicing.mts +37 -40
- package/src/array/impl/array-utils-transformation.mts +64 -62
- package/src/array/impl/array-utils-transformation.test.mts +1 -1
- package/src/array/impl/array-utils-validation.mts +18 -20
- package/src/collections/iset.test.mts +2 -2
- package/src/functional/pipe.test.mts +1 -1
- package/src/json/json.mts +1 -1
- package/src/string/str.mts +74 -61
package/README.md
CHANGED
|
@@ -200,12 +200,9 @@ const divideAndFormat = (
|
|
|
200
200
|
): Result<string, string> =>
|
|
201
201
|
pipe(denominator)
|
|
202
202
|
.map((d) => (d !== 0 ? Result.ok(d) : Result.err('Division by zero')))
|
|
203
|
-
.map(
|
|
204
|
-
.map((
|
|
205
|
-
|
|
206
|
-
)
|
|
207
|
-
.map((result) => Result.mapErr(result, (error) => `Error: ${error}`))
|
|
208
|
-
.value;
|
|
203
|
+
.map(Result.map((d: number) => numerator / d))
|
|
204
|
+
.map(Result.map((value: number) => `Result: ${value.toFixed(2)}`))
|
|
205
|
+
.map(Result.mapErr((error: string) => `Error: ${error}`)).value;
|
|
209
206
|
|
|
210
207
|
assert.deepStrictEqual(divideAndFormat(10, 2), Result.ok('Result: 5.00'));
|
|
211
208
|
|
|
@@ -53,7 +53,7 @@ export declare const create: <N extends SizeType.ArgArr, const V>(len: N, init:
|
|
|
53
53
|
*
|
|
54
54
|
* @see {@link create}
|
|
55
55
|
*/
|
|
56
|
-
export declare const newArray:
|
|
56
|
+
export declare const newArray: typeof create;
|
|
57
57
|
/**
|
|
58
58
|
* Generates an array from a generator function.
|
|
59
59
|
*
|
|
@@ -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,K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AAS,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"}
|
|
@@ -69,5 +69,5 @@ export declare const last: <const Ar extends readonly unknown[]>(array: Ar) => A
|
|
|
69
69
|
*
|
|
70
70
|
* @see {@link head}
|
|
71
71
|
*/
|
|
72
|
-
export declare const first:
|
|
72
|
+
export declare const first: typeof head;
|
|
73
73
|
//# sourceMappingURL=array-utils-element-access.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-utils-element-access.d.mts","sourceRoot":"","sources":["../../../src/array/impl/array-utils-element-access.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAQ,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EACL,KAAK,yBAAyB,EAC9B,KAAK,IAAI,EACT,KAAK,QAAQ,EACb,KAAK,IAAI,EACV,MAAM,iBAAiB,CAAC;AAEzB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,EAAE,CAAC,KAAK,CAAC,EAAE,SAAS,SAAS,OAAO,EAAE,EACpD,KAAK,EAAE,EAAE,EACT,KAAK,EAAE,yBAAyB,CAAC,EAAE,CAAC,GACnC,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;AAIxB,wBAAgB,EAAE,CA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;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,IAAI,GAAI,KAAK,CAAC,EAAE,SAAS,SAAS,OAAO,EAAE,SAC/C,EAAE,KACR,EAAE,SAAS,SAAS,EAAE,GACrB,IAAI,GACJ,EAAE,SAAS,SAAS,CAAC,GAAG,OAAO,EAAE,EAAE,MAAM,CAAC,CAAC,GACzC,IAAI,CAAC,CAAC,CAAC,GACP,EAAE,SAAS,aAAa,CAAC,MAAM,CAAC,CAAC,GAC/B,IAAI,CAAC,CAAC,CAAC,GACP,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,CAEkD,CAAC;AAE9E;;;;GAIG;AACH,eAAO,MAAM,KAAK,aAAO,CAAC"}
|
|
@@ -5,21 +5,18 @@ import '@sindresorhus/is';
|
|
|
5
5
|
|
|
6
6
|
function at(...args) {
|
|
7
7
|
switch (args.length) {
|
|
8
|
-
case 2:
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
13
|
-
some(array[normalizedIndex])
|
|
14
|
-
)
|
|
15
|
-
).value;
|
|
16
|
-
}
|
|
17
|
-
case 1: {
|
|
18
|
-
const [index] = args;
|
|
19
|
-
return (array) => at(array, index);
|
|
20
|
-
}
|
|
8
|
+
case 2:
|
|
9
|
+
return atImpl(...args);
|
|
10
|
+
case 1:
|
|
11
|
+
return (array) => atImpl(array, ...args);
|
|
21
12
|
}
|
|
22
13
|
}
|
|
14
|
+
const atImpl = (array, index$1) => pipe(index$1 < 0 ? array.length + index$1 : index$1).map(
|
|
15
|
+
(normalizedIndex) => normalizedIndex < 0 || normalizedIndex >= array.length ? none : (
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
17
|
+
some(array[normalizedIndex])
|
|
18
|
+
)
|
|
19
|
+
).value;
|
|
23
20
|
const head = (array) => (
|
|
24
21
|
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
25
22
|
array.length === 0 ? none : some(array.at(0))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-utils-element-access.mjs","sources":["../../../src/array/impl/array-utils-element-access.mts"],"sourcesContent":["import { type NonEmptyTuple } from 'ts-type-forge';\nimport { Optional, pipe } from '../../functional/index.mjs';\nimport {\n type ArgArrayIndexWithNegative,\n type None,\n type SizeType,\n type Some,\n} from '../../types.mjs';\n\n/**\n * Safely retrieves an element at a given index from an array, returning an Optional.\n *\n * @example\n *\n * ```ts\n * const letters: readonly string[] = ['a', 'b', 'c'] as const;\n *\n * const two = Arr.at(letters, 1);\n *\n * const last = Arr.at(-1)(letters);\n *\n * const missing = Arr.at(letters, 5);\n *\n * assert.deepStrictEqual(two, Optional.some('b'));\n *\n * assert.deepStrictEqual(last, Optional.some('c'));\n *\n * assert.deepStrictEqual(missing, Optional.none);\n * ```\n */\nexport function at<const Ar extends readonly unknown[]>(\n array: Ar,\n index: ArgArrayIndexWithNegative<Ar>,\n): Optional<Ar[number]>;\n\n// Curried version\n\nexport function at(\n index: SizeType.ArgArrWithNegative,\n): <E>(array: readonly E[]) => Optional<E>;\n\nexport function at<E>(\n ...args:\n | readonly [array: readonly E[], index: SizeType.ArgArrWithNegative]\n | readonly [index: SizeType.ArgArrWithNegative]\n): Optional<E> | ((array: readonly E[]) => Optional<E>) {\n switch (args.length) {\n case 2
|
|
1
|
+
{"version":3,"file":"array-utils-element-access.mjs","sources":["../../../src/array/impl/array-utils-element-access.mts"],"sourcesContent":["import { type NonEmptyTuple } from 'ts-type-forge';\nimport { Optional, pipe } from '../../functional/index.mjs';\nimport {\n type ArgArrayIndexWithNegative,\n type None,\n type SizeType,\n type Some,\n} from '../../types.mjs';\n\n/**\n * Safely retrieves an element at a given index from an array, returning an Optional.\n *\n * @example\n *\n * ```ts\n * const letters: readonly string[] = ['a', 'b', 'c'] as const;\n *\n * const two = Arr.at(letters, 1);\n *\n * const last = Arr.at(-1)(letters);\n *\n * const missing = Arr.at(letters, 5);\n *\n * assert.deepStrictEqual(two, Optional.some('b'));\n *\n * assert.deepStrictEqual(last, Optional.some('c'));\n *\n * assert.deepStrictEqual(missing, Optional.none);\n * ```\n */\nexport function at<const Ar extends readonly unknown[]>(\n array: Ar,\n index: ArgArrayIndexWithNegative<Ar>,\n): Optional<Ar[number]>;\n\n// Curried version\n\nexport function at(\n index: SizeType.ArgArrWithNegative,\n): <E>(array: readonly E[]) => Optional<E>;\n\nexport function at<E>(\n ...args:\n | readonly [array: readonly E[], index: SizeType.ArgArrWithNegative]\n | readonly [index: SizeType.ArgArrWithNegative]\n): Optional<E> | ((array: readonly E[]) => Optional<E>) {\n switch (args.length) {\n case 2:\n return atImpl(...args);\n\n case 1:\n return (array) => atImpl(array, ...args);\n }\n}\n\nconst atImpl = <E,>(\n array: readonly E[],\n index: SizeType.ArgArrWithNegative,\n): Optional<E> =>\n pipe(index < 0 ? array.length + index : index).map((normalizedIndex) =>\n normalizedIndex < 0 || normalizedIndex >= array.length\n ? Optional.none\n : // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n Optional.some(array[normalizedIndex]!),\n ).value;\n\n/**\n * Returns the first element of an array as an Optional.\n *\n * @example\n *\n * ```ts\n * const users = [{ id: 1 }, { id: 2 }] as const;\n *\n * const empty: readonly Readonly<{ id: number }>[] = [] as const;\n *\n * const first = Arr.head(users);\n *\n * const none = Arr.head(empty);\n *\n * assert.deepStrictEqual(first, Optional.some({ id: 1 }));\n *\n * assert.deepStrictEqual(none, Optional.none);\n * ```\n */\nexport const head = <const Ar extends readonly unknown[]>(\n array: Ar,\n): Ar extends readonly []\n ? None\n : Ar extends readonly [infer E, ...unknown[]]\n ? Some<E>\n : Ar extends NonEmptyTuple<infer E>\n ? Some<E>\n : Optional<Ar[number]> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n (array.length === 0 ? Optional.none : Optional.some(array.at(0))) as never;\n\n/**\n * Returns the last element of an array as an Optional.\n *\n * @example\n *\n * ```ts\n * const queue = ['first', 'second'] as const;\n *\n * const emptyQueue: readonly string[] = [] as const;\n *\n * const lastValue = Arr.last(queue);\n *\n * const none = Arr.last(emptyQueue);\n *\n * assert.deepStrictEqual(lastValue, Optional.some('second'));\n *\n * assert.deepStrictEqual(none, Optional.none);\n * ```\n */\nexport const last = <const Ar extends readonly unknown[]>(\n array: Ar,\n): Ar extends readonly []\n ? None\n : Ar extends readonly [...unknown[], infer E]\n ? Some<E>\n : Ar extends NonEmptyTuple<infer E>\n ? Some<E>\n : Optional<Ar[number]> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n (array.length === 0 ? Optional.none : Optional.some(array.at(-1))) as never;\n\n/**\n * Alias for `head`.\n *\n * @see {@link head}\n */\nexport const first = head;\n"],"names":["index","Optional.none","Optional.some"],"mappings":";;;;;AAyCO,SAAS,MACX,IAAA,EAGmD;AACtD,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA;AACH,MAAA,OAAO,MAAA,CAAO,GAAG,IAAI,CAAA;AAAA,IAEvB,KAAK,CAAA;AACH,MAAA,OAAO,CAAC,KAAA,KAAU,MAAA,CAAO,KAAA,EAAO,GAAG,IAAI,CAAA;AAAA;AAE7C;AAEA,MAAM,MAAA,GAAS,CACb,KAAA,EACAA,OAAA,KAEA,IAAA,CAAKA,OAAA,GAAQ,CAAA,GAAI,KAAA,CAAM,MAAA,GAASA,OAAA,GAAQA,OAAK,CAAA,CAAE,GAAA;AAAA,EAAI,CAAC,eAAA,KAClD,eAAA,GAAkB,KAAK,eAAA,IAAmB,KAAA,CAAM,SAC5CC,IAAS;AAAA;AAAA,IAETC,IAAS,CAAK,KAAA,CAAM,eAAe,CAAE;AAAA;AAC3C,CAAA,CAAE,KAAA;AAqBG,MAAM,OAAO,CAClB,KAAA;AAAA;AAAA,EASC,KAAA,CAAM,MAAA,KAAW,CAAA,GAAID,IAAS,GAAOC,IAAS,CAAK,KAAA,CAAM,EAAA,CAAG,CAAC,CAAC;AAAA;AAqB1D,MAAM,OAAO,CAClB,KAAA;AAAA;AAAA,EASC,KAAA,CAAM,MAAA,KAAW,CAAA,GAAID,IAAS,GAAOC,IAAS,CAAK,KAAA,CAAM,EAAA,CAAG,EAAE,CAAC;AAAA;AAO3D,MAAM,KAAA,GAAQ;;;;"}
|
|
@@ -56,5 +56,5 @@ export declare const indices: <E>(array: readonly E[]) => ArrayIterator<SizeType
|
|
|
56
56
|
*
|
|
57
57
|
* @see {@link indices}
|
|
58
58
|
*/
|
|
59
|
-
export declare const keys:
|
|
59
|
+
export declare const keys: typeof indices;
|
|
60
60
|
//# sourceMappingURL=array-utils-iterators.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-utils-iterators.d.mts","sourceRoot":"","sources":["../../../src/array/impl/array-utils-iterators.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,OAAO,GAAc,CAAC,SAC1B,SAAS,CAAC,EAAE,KAClB,aAAa,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC,CAI1C,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,MAAM,GAAc,CAAC,SAAS,SAAS,CAAC,EAAE,KAAG,aAAa,CAAC,CAAC,CAIxE,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,OAAO,GAAc,CAAC,SAC1B,SAAS,CAAC,EAAE,KAClB,aAAa,CAAC,QAAQ,CAAC,GAAG,CAI5B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,IAAI,
|
|
1
|
+
{"version":3,"file":"array-utils-iterators.d.mts","sourceRoot":"","sources":["../../../src/array/impl/array-utils-iterators.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,OAAO,GAAc,CAAC,SAC1B,SAAS,CAAC,EAAE,KAClB,aAAa,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC,CAI1C,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,MAAM,GAAc,CAAC,SAAS,SAAS,CAAC,EAAE,KAAG,aAAa,CAAC,CAAC,CAIxE,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,OAAO,GAAc,CAAC,SAC1B,SAAS,CAAC,EAAE,KAClB,aAAa,CAAC,QAAQ,CAAC,GAAG,CAI5B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,IAAI,gBAAU,CAAC"}
|
|
@@ -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,EAAE,EAC/B,EAAE,EAAE,EAAE,KACH,gBAAgB,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,EAAE,EAC/B,EAAE,EAAE,EAAE,KACH,gBAAgB,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC;AA+B/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,gBAAgB,CAC9B,EAAE,SAAS,SAAS,OAAO,EAAE,EAC7B,SAAS,SAAS,eAAe,EACjC,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,SAAS,GAAG,cAAc,CAAC,SAAS,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC;AAG5E,wBAAgB,gBAAgB,CAAC,SAAS,SAAS,eAAe,EAChE,SAAS,EAAE,SAAS,GACnB,CAAC,EAAE,SAAS,SAAS,OAAO,EAAE,EAC/B,EAAE,EAAE,EAAE,KACH,cAAc,CAAC,SAAS,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC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AC,MAAM,CAAC,CAAC,GAAG,EAM9B,CAAC"}
|
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
import { isBoundedLengthArray, isFixedLengthArray, isMaxLengthArray
|
|
1
|
+
import { isMinLengthArray, isBoundedLengthArray, isFixedLengthArray, isMaxLengthArray } from './array-utils-length-bounded-array-guard.mjs';
|
|
2
2
|
|
|
3
3
|
function asFixedLengthArray(...args) {
|
|
4
4
|
switch (args.length) {
|
|
5
|
-
case 2:
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
`Expected an array of length ${length}, got an array of length ${xs.length}`
|
|
10
|
-
);
|
|
11
|
-
}
|
|
12
|
-
return xs;
|
|
13
|
-
}
|
|
14
|
-
case 1: {
|
|
15
|
-
const [length] = args;
|
|
16
|
-
return (xs) => asFixedLengthArray(xs, length);
|
|
17
|
-
}
|
|
5
|
+
case 2:
|
|
6
|
+
return asFixedLengthArrayImpl(...args);
|
|
7
|
+
case 1:
|
|
8
|
+
return (xs) => asFixedLengthArrayImpl(xs, ...args);
|
|
18
9
|
}
|
|
19
10
|
}
|
|
11
|
+
const asFixedLengthArrayImpl = (xs, length) => {
|
|
12
|
+
const actualLength = xs.length;
|
|
13
|
+
if (!isFixedLengthArray(xs, length)) {
|
|
14
|
+
throw new TypeError(
|
|
15
|
+
`Expected an array of length ${length}, got an array of length ${actualLength}`
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
return xs;
|
|
19
|
+
};
|
|
20
20
|
function asMinLengthArray(...args) {
|
|
21
21
|
switch (args.length) {
|
|
22
|
-
case 2:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
`Expected an array of length >= ${minLength}, got an array of length ${xs.length}`
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
return xs;
|
|
30
|
-
}
|
|
31
|
-
case 1: {
|
|
32
|
-
const [minLength] = args;
|
|
33
|
-
return (xs) => asMinLengthArray(xs, minLength);
|
|
34
|
-
}
|
|
22
|
+
case 2:
|
|
23
|
+
return asMinLengthArrayImpl(...args);
|
|
24
|
+
case 1:
|
|
25
|
+
return (xs) => asMinLengthArrayImpl(xs, ...args);
|
|
35
26
|
}
|
|
36
27
|
}
|
|
28
|
+
const asMinLengthArrayImpl = (xs, minLength) => {
|
|
29
|
+
const actualLength = xs.length;
|
|
30
|
+
if (!isMinLengthArray(xs, minLength)) {
|
|
31
|
+
throw new TypeError(
|
|
32
|
+
`Expected an array of length >= ${minLength}, got an array of length ${actualLength}`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
return xs;
|
|
36
|
+
};
|
|
37
37
|
function asMaxLengthArray(...args) {
|
|
38
38
|
switch (args.length) {
|
|
39
|
-
case 2:
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
`Expected an array of length <= ${maxLength}, got an array of length ${xs.length}`
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
return xs;
|
|
47
|
-
}
|
|
48
|
-
case 1: {
|
|
49
|
-
const [maxLength] = args;
|
|
50
|
-
return (xs) => asMaxLengthArray(xs, maxLength);
|
|
51
|
-
}
|
|
39
|
+
case 2:
|
|
40
|
+
return asMaxLengthArrayImpl(...args);
|
|
41
|
+
case 1:
|
|
42
|
+
return (xs) => asMaxLengthArrayImpl(xs, ...args);
|
|
52
43
|
}
|
|
53
44
|
}
|
|
45
|
+
const asMaxLengthArrayImpl = (xs, maxLength) => {
|
|
46
|
+
const actualLength = xs.length;
|
|
47
|
+
if (!isMaxLengthArray(xs, maxLength)) {
|
|
48
|
+
throw new TypeError(
|
|
49
|
+
`Expected an array of length <= ${maxLength}, got an array of length ${actualLength}`
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
return xs;
|
|
53
|
+
};
|
|
54
54
|
function asBoundedLengthArray(...args) {
|
|
55
55
|
switch (args.length) {
|
|
56
|
-
case 3:
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
`Expected an array of length in [${minLength}, ${maxLength}], got an array of length ${xs.length}`
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
return xs;
|
|
64
|
-
}
|
|
65
|
-
case 2: {
|
|
66
|
-
const [minLength, maxLength] = args;
|
|
67
|
-
return (xs) => asBoundedLengthArray(xs, minLength, maxLength);
|
|
68
|
-
}
|
|
56
|
+
case 3:
|
|
57
|
+
return asBoundedLengthArrayImpl(...args);
|
|
58
|
+
case 2:
|
|
59
|
+
return (xs) => asBoundedLengthArrayImpl(xs, ...args);
|
|
69
60
|
}
|
|
70
61
|
}
|
|
62
|
+
const asBoundedLengthArrayImpl = (xs, minLength, maxLength) => {
|
|
63
|
+
const actualLength = xs.length;
|
|
64
|
+
if (!isBoundedLengthArray(xs, minLength, maxLength)) {
|
|
65
|
+
throw new TypeError(
|
|
66
|
+
`Expected an array of length in [${minLength}, ${maxLength}], got an array of length ${actualLength}`
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
return xs;
|
|
70
|
+
};
|
|
71
71
|
const asNonEmptyArray = (xs) => {
|
|
72
72
|
if (!isMinLengthArray(xs, 1)) {
|
|
73
73
|
throw new TypeError("Expected a non-empty array, got an empty array");
|
|
@@ -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 const [xs, length] = args;\n\n if (!isFixedLengthArray(xs, length)) {\n throw new TypeError(\n `Expected an array of length ${length}, got an array of length ${xs.length}`,\n );\n }\n\n return xs;\n }\n\n case 1: {\n const [length] = args;\n\n return (xs) => asFixedLengthArray(xs, length);\n }\n }\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 const [xs, minLength] = args;\n\n if (!isMinLengthArray(xs, minLength)) {\n throw new TypeError(\n `Expected an array of length >= ${minLength}, got an array of length ${xs.length}`,\n );\n }\n\n return xs;\n }\n\n case 1: {\n const [minLength] = args;\n\n return (xs) => asMinLengthArray(xs, minLength);\n }\n }\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 const [xs, maxLength] = args;\n\n if (!isMaxLengthArray(xs, maxLength)) {\n throw new TypeError(\n `Expected an array of length <= ${maxLength}, got an array of length ${xs.length}`,\n );\n }\n\n return xs;\n }\n\n case 1: {\n const [maxLength] = args;\n\n return (xs) => asMaxLengthArray(xs, maxLength);\n }\n }\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 const [xs, minLength, maxLength] = args;\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 ${xs.length}`,\n );\n }\n\n return xs;\n }\n\n case 2: {\n const [minLength, maxLength] = args;\n\n return (xs) => asBoundedLengthArray(xs, minLength, maxLength);\n }\n }\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,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA,EAAG;AACN,MAAA,MAAM,CAAC,EAAA,EAAI,MAAM,CAAA,GAAI,IAAA;AAErB,MAAA,IAAI,CAAC,kBAAA,CAAmB,EAAA,EAAI,MAAM,CAAA,EAAG;AACnC,QAAA,MAAM,IAAI,SAAA;AAAA,UACR,CAAA,4BAAA,EAA+B,MAAM,CAAA,yBAAA,EAA4B,EAAA,CAAG,MAAM,CAAA;AAAA,SAC5E;AAAA,MACF;AAEA,MAAA,OAAO,E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AA;AAEpB,MAAA,OAAO,CAAC,EAAA,KAAO,gBAAA,CAAiB,EAAA,EAAI,SAAS,CAAA;AAAA,IAC/C;AAAA;AAEJ;AA6DO,SAAS,wBACX,IAAA,EAOkD;AACrD,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA,EAAG;AACN,MAAA,MAAM,CAAC,EAAA,EAAI,SAAA,EAAW,SAAS,CAAA,GAAI,IAAA;AAEnC,MAAA,IAAI,CAAC,oBAAA,CAAqB,EAAA,EAAI,SAAA,EAAW,SAAS,CAAA,EAAG;AACnD,QAAA,MAAM,IAAI,SAAA;AAAA,UACR,mCAAmC,SAAS,CAAA,EAAA,EAAK,SAAS,CAAA,0BAAA,EAA6B,GAAG,MAAM,CAAA;AAAA,SAClG;AAAA,MACF;AAEA,MAAA,OAAO,EAAA;AAAA,IACT;AAAA,IAEA,KAAK,CAAA,EAAG;AACN,MAAA,MAAM,CAAC,SAAA,EAAW,SAAS,CAAA,GAAI,IAAA;AAE/B,MAAA,OAAO,CAAC,EAAA,KAAO,oBAAA,CAAqB,EAAA,EAAI,WAAW,SAAS,CAAA;AAAA,IAC9D;AAAA;AAEJ;AA4BO,MAAM,eAAA,GAAkB,CAC7B,EAAA,KACmC;AACnC,EAAA,IAAI,CAAC,gBAAA,CAAiB,EAAA,EAAI,CAAC,CAAA,EAAG;AAC5B,IAAA,MAAM,IAAI,UAAU,gDAAgD,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 * 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,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA;AACH,MAAA,OAAO,sBAAA,CAAuB,GAAG,IAAI,CAAA;AAAA,IAEvC,KAAK,CAAA;AACH,MAAA,OAAO,CAAC,EAAA,KAAO,sBAAA,CAAuB,EAAA,EAAI,GAAG,IAAI,CAAA;AAAA;AAEvD;AAEA,MAAM,sBAAA,GAAyB,CAC7B,EAAA,EACA,MAAA,KACiB;AACjB,EAAA,MAAM,eAAe,EAAA,CAAG,MAAA;AAExB,EAAA,IAAI,CAAC,kBAAA,CAAmB,EAAA,EAAI,MAAM,CAAA,EAAG;AACnC,IAAA,MAAM,IAAI,SAAA;AAAA,MACR,CAAA,4BAAA,EAA+B,MAAM,CAAA,yBAAA,EAA4B,YAAY,CAAA;AAAA,KAC/E;AAAA,EACF;AAEA,EAAA,OAAO,EAAA;AACT,CAAA;AAiDO,SAAS,oBACX,IAAA,EAGkD;AACrD,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA;AACH,MAAA,OAAO,oBAAA,CAAqB,GAAG,IAAI,CAAA;AAAA,IAErC,KAAK,CAAA;AACH,MAAA,OAAO,CAAC,EAAA,KAAO,oBAAA,CAAqB,EAAA,EAAI,GAAG,IAAI,CAAA;AAAA;AAErD;AAEA,MAAM,oBAAA,GAAuB,CAC3B,EAAA,EACA,SAAA,KACiB;AACjB,EAAA,MAAM,eAAe,EAAA,CAAG,MAAA;AAExB,EAAA,IAAI,CAAC,gBAAA,CAAiB,EAAA,EAAI,SAAS,CAAA,EAAG;AACpC,IAAA,MAAM,IAAI,SAAA;AAAA,MACR,CAAA,+BAAA,EAAkC,SAAS,CAAA,yBAAA,EAA4B,YAAY,CAAA;AAAA,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AA;AACT,CAAA;AA4BO,MAAM,eAAA,GAAkB,CAC7B,EAAA,KACmC;AACnC,EAAA,IAAI,CAAC,gBAAA,CAAiB,EAAA,EAAI,CAAC,CAAA,EAAG;AAC5B,IAAA,MAAM,IAAI,UAAU,gDAAgD,CAAA;AAAA,EACtE;AAEA,EAAA,OAAO,EAAA;AACT;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-utils-modification.d.mts","sourceRoot":"","sources":["../../../src/array/impl/array-utils-modification.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,aAAa,EACnB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,yBAAyB,EAC9B,KAAK,QAAQ,EACd,MAAM,iBAAiB,CAAC;AAGzB;;;;;;;;;;;;GAYG;AACH,wBAAgB,GAAG,CAAC,KAAK,CAAC,EAAE,SAAS,SAAS,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,EAC3E,KAAK,EAAE,EAAE,EACT,KAAK,EAAE,aAAa,CAAC,EAAE,CAAC,EACxB,QAAQ,EAAE,CAAC,GACV,iBAAiB,CAAC,EAAE,CAAC,SAAS,IAAI,GACjC,QAAQ,CAAC;KAAG,CAAC,IAAI,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;CAAE,CAAC,GACxC,EAAE,SAAS,aAAa,CAAC,OAAO,CAAC,GAC/B,aAAa,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAC7B,SAAS,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;AAGlC,wBAAgB,GAAG,CAAC,KAAK,CAAC,CAAC,EACzB,KAAK,EAAE,QAAQ,CAAC,MAAM,EACtB,QAAQ,EAAE,CA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AAC,EAAE,EAC/B,KAAK,EAAE,EAAE,KACN,iBAAiB,CAAC,EAAE,CAAC,SAAS,IAAI,GACnC,QAAQ,CAAC;KAAG,CAAC,IAAI,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;CAAE,CAAC,GACxC,EAAE,SAAS,aAAa,CAAC,OAAO,CAAC,GAC/B,aAAa,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAC7B,SAAS,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"array-utils-modification.d.mts","sourceRoot":"","sources":["../../../src/array/impl/array-utils-modification.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,aAAa,EACnB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,yBAAyB,EAC9B,KAAK,QAAQ,EACd,MAAM,iBAAiB,CAAC;AAGzB;;;;;;;;;;;;GAYG;AACH,wBAAgB,GAAG,CAAC,KAAK,CAAC,EAAE,SAAS,SAAS,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,EAC3E,KAAK,EAAE,EAAE,EACT,KAAK,EAAE,aAAa,CAAC,EAAE,CAAC,EACxB,QAAQ,EAAE,CAAC,GACV,iBAAiB,CAAC,EAAE,CAAC,SAAS,IAAI,GACjC,QAAQ,CAAC;KAAG,CAAC,IAAI,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;CAAE,CAAC,GACxC,EAAE,SAAS,aAAa,CAAC,OAAO,CAAC,GAC/B,aAAa,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAC7B,SAAS,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,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
40
40
|
|
|
41
41
|
function set(...args) {
|
|
42
42
|
switch (args.length) {
|
|
43
|
-
case 3:
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
case 2: {
|
|
48
|
-
const [index, newValue] = args;
|
|
49
|
-
return (array) => set(array, index, newValue);
|
|
50
|
-
}
|
|
43
|
+
case 3:
|
|
44
|
+
return setImpl(...args);
|
|
45
|
+
case 2:
|
|
46
|
+
return (array) => setImpl(array, ...args);
|
|
51
47
|
}
|
|
52
48
|
}
|
|
49
|
+
const setImpl = (array, index, newValue) => array.with(index, newValue);
|
|
53
50
|
function toUpdated(...args) {
|
|
54
51
|
switch (args.length) {
|
|
55
|
-
case 3:
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
case 2: {
|
|
60
|
-
const [index, updater] = args;
|
|
61
|
-
return (array) => toUpdated(array, index, updater);
|
|
62
|
-
}
|
|
52
|
+
case 3:
|
|
53
|
+
return toUpdatedImpl(...args);
|
|
54
|
+
case 2:
|
|
55
|
+
return (array) => toUpdatedImpl(array, ...args);
|
|
63
56
|
}
|
|
64
57
|
}
|
|
58
|
+
const toUpdatedImpl = (array, index, updater) => (
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
60
|
+
array.with(index, updater(array[index]))
|
|
61
|
+
);
|
|
65
62
|
function toInserted(...args) {
|
|
66
63
|
switch (args.length) {
|
|
67
|
-
case 3:
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
0,
|
|
72
|
-
newValue
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
case 2: {
|
|
76
|
-
const [index, newValue] = args;
|
|
77
|
-
return (array) => toInserted(array, index, newValue);
|
|
78
|
-
}
|
|
64
|
+
case 3:
|
|
65
|
+
return toInsertedImpl(...args);
|
|
66
|
+
case 2:
|
|
67
|
+
return (array) => toInsertedImpl(array, ...args);
|
|
79
68
|
}
|
|
80
69
|
}
|
|
70
|
+
const toInsertedImpl = (array, index, newValue) => (
|
|
71
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
72
|
+
array.toSpliced(
|
|
73
|
+
index,
|
|
74
|
+
0,
|
|
75
|
+
newValue
|
|
76
|
+
)
|
|
77
|
+
);
|
|
81
78
|
function toRemoved(...args) {
|
|
82
79
|
switch (args.length) {
|
|
83
|
-
case 2:
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
case 1: {
|
|
88
|
-
const [index] = args;
|
|
89
|
-
return (array) => toRemoved(array, index);
|
|
90
|
-
}
|
|
80
|
+
case 2:
|
|
81
|
+
return toRemovedImpl(...args);
|
|
82
|
+
case 1:
|
|
83
|
+
return (array) => toRemovedImpl(array, ...args);
|
|
91
84
|
}
|
|
92
85
|
}
|
|
86
|
+
const toRemovedImpl = (array, index) => array.toSpliced(index, 1);
|
|
93
87
|
function toPushed(...args) {
|
|
94
88
|
switch (args.length) {
|
|
95
|
-
case 2:
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
case 1: {
|
|
100
|
-
const [newValue] = args;
|
|
101
|
-
return (array) => toPushed(array, newValue);
|
|
102
|
-
}
|
|
89
|
+
case 2:
|
|
90
|
+
return toPushedImpl(...args);
|
|
91
|
+
case 1:
|
|
92
|
+
return (array) => toPushedImpl(array, ...args);
|
|
103
93
|
}
|
|
104
94
|
}
|
|
95
|
+
const toPushedImpl = (array, newValue) => (
|
|
96
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
97
|
+
array.toSpliced(array.length, 0, newValue)
|
|
98
|
+
);
|
|
105
99
|
function toUnshifted(...args) {
|
|
106
100
|
switch (args.length) {
|
|
107
|
-
case 2:
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
case 1: {
|
|
112
|
-
const [newValue] = args;
|
|
113
|
-
return (array) => toUnshifted(array, newValue);
|
|
114
|
-
}
|
|
101
|
+
case 2:
|
|
102
|
+
return toUnshiftedImpl(...args);
|
|
103
|
+
case 1:
|
|
104
|
+
return (array) => toUnshiftedImpl(array, ...args);
|
|
115
105
|
}
|
|
116
106
|
}
|
|
107
|
+
const toUnshiftedImpl = (array, newValue) => (
|
|
108
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
109
|
+
array.toSpliced(0, 0, newValue)
|
|
110
|
+
);
|
|
117
111
|
function toFilled(...args) {
|
|
118
112
|
switch (args.length) {
|
|
119
|
-
case 2:
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
case 1: {
|
|
124
|
-
const [value] = args;
|
|
125
|
-
return (array) => toFilled(array, value);
|
|
126
|
-
}
|
|
113
|
+
case 2:
|
|
114
|
+
return toFilledImpl(...args);
|
|
115
|
+
case 1:
|
|
116
|
+
return (array) => toFilledImpl(array, ...args);
|
|
127
117
|
}
|
|
128
118
|
}
|
|
119
|
+
const toFilledImpl = (array, value) => create(asPositiveUint32(array.length), value);
|
|
129
120
|
function toRangeFilled(...args) {
|
|
130
121
|
switch (args.length) {
|
|
131
|
-
case 3:
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return mut_cp;
|
|
136
|
-
}
|
|
137
|
-
case 2: {
|
|
138
|
-
const [value, fillRange] = args;
|
|
139
|
-
return (array) => toRangeFilled(array, value, fillRange);
|
|
140
|
-
}
|
|
122
|
+
case 3:
|
|
123
|
+
return toRangeFilledImpl(...args);
|
|
124
|
+
case 2:
|
|
125
|
+
return (array) => toRangeFilledImpl(array, ...args);
|
|
141
126
|
}
|
|
142
127
|
}
|
|
128
|
+
const toRangeFilledImpl = (array, value, fillRange) => {
|
|
129
|
+
const [start, end] = fillRange;
|
|
130
|
+
const mut_cp = castMutable(copy(array));
|
|
131
|
+
mut_cp.fill(value, start, end);
|
|
132
|
+
return mut_cp;
|
|
133
|
+
};
|
|
143
134
|
|
|
144
135
|
export { set, toFilled, toInserted, toPushed, toRangeFilled, toRemoved, toUnshifted, toUpdated };
|
|
145
136
|
//# sourceMappingURL=array-utils-modification.mjs.map
|