ts-data-forge 10.0.0 → 11.0.1
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/dist/array/impl/array-utils-creation.d.mts +3 -3
- package/dist/array/impl/array-utils-creation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-creation.mjs.map +1 -1
- package/dist/array/impl/array-utils-element-access.d.mts +4 -4
- package/dist/array/impl/array-utils-element-access.mjs.map +1 -1
- package/dist/{guard/as-length-bounded-array.d.mts → array/impl/array-utils-length-bounded-array-cast.d.mts} +9 -9
- package/dist/array/impl/array-utils-length-bounded-array-cast.d.mts.map +1 -0
- package/dist/{guard/as-length-bounded-array.mjs → array/impl/array-utils-length-bounded-array-cast.mjs} +2 -2
- package/dist/array/impl/array-utils-length-bounded-array-cast.mjs.map +1 -0
- package/dist/{guard/is-length-bounded-array.d.mts → array/impl/array-utils-length-bounded-array-guard.d.mts} +13 -13
- package/dist/array/impl/array-utils-length-bounded-array-guard.d.mts.map +1 -0
- package/dist/{guard/is-length-bounded-array.mjs → array/impl/array-utils-length-bounded-array-guard.mjs} +1 -1
- package/dist/array/impl/array-utils-length-bounded-array-guard.mjs.map +1 -0
- package/dist/array/impl/array-utils-modification.d.mts +9 -9
- package/dist/array/impl/array-utils-modification.d.mts.map +1 -1
- package/dist/array/impl/array-utils-modification.mjs.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.d.mts +9 -9
- package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
- package/dist/array/impl/array-utils-size.d.mts +3 -3
- package/dist/array/impl/array-utils-size.mjs.map +1 -1
- package/dist/array/impl/array-utils-slicing.d.mts +9 -9
- package/dist/array/impl/array-utils-slicing.d.mts.map +1 -1
- package/dist/array/impl/array-utils-slicing.mjs.map +1 -1
- package/dist/array/impl/array-utils-transformation.d.mts +16 -10
- package/dist/array/impl/array-utils-transformation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
- package/dist/array/impl/index.d.mts +2 -0
- package/dist/array/impl/index.d.mts.map +1 -1
- package/dist/array/impl/index.mjs +2 -0
- package/dist/array/impl/index.mjs.map +1 -1
- package/dist/entry-point.mjs +1 -3
- package/dist/entry-point.mjs.map +1 -1
- package/dist/guard/index.d.mts +0 -3
- package/dist/guard/index.d.mts.map +1 -1
- package/dist/guard/index.mjs +0 -3
- package/dist/guard/index.mjs.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -3
- package/dist/index.mjs.map +1 -1
- package/dist/number/branded-types/finite-number.d.mts +47 -61
- package/dist/number/branded-types/finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/finite-number.mjs +37 -41
- package/dist/number/branded-types/finite-number.mjs.map +1 -1
- package/dist/number/branded-types/int.d.mts +40 -46
- package/dist/number/branded-types/int.d.mts.map +1 -1
- package/dist/number/branded-types/int.mjs +29 -31
- package/dist/number/branded-types/int.mjs.map +1 -1
- package/dist/number/branded-types/int16.d.mts +65 -58
- package/dist/number/branded-types/int16.d.mts.map +1 -1
- package/dist/number/branded-types/int16.mjs +49 -45
- package/dist/number/branded-types/int16.mjs.map +1 -1
- package/dist/number/branded-types/int32.d.mts +65 -58
- package/dist/number/branded-types/int32.d.mts.map +1 -1
- package/dist/number/branded-types/int32.mjs +49 -45
- package/dist/number/branded-types/int32.mjs.map +1 -1
- package/dist/number/branded-types/negative-finite-number.d.mts +68 -59
- package/dist/number/branded-types/negative-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/negative-finite-number.mjs +52 -46
- package/dist/number/branded-types/negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/negative-int.d.mts +60 -48
- package/dist/number/branded-types/negative-int.d.mts.map +1 -1
- package/dist/number/branded-types/negative-int.mjs +40 -36
- package/dist/number/branded-types/negative-int.mjs.map +1 -1
- package/dist/number/branded-types/negative-safe-int.d.mts +57 -56
- package/dist/number/branded-types/negative-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/negative-safe-int.mjs +40 -41
- package/dist/number/branded-types/negative-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.d.mts +74 -64
- package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.mjs +58 -51
- package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int16.d.mts +64 -57
- package/dist/number/branded-types/non-negative-int16.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-int16.mjs +47 -43
- package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int32.d.mts +64 -58
- package/dist/number/branded-types/non-negative-int32.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-int32.mjs +47 -44
- package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-finite-number.d.mts +64 -54
- package/dist/number/branded-types/non-positive-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-finite-number.mjs +48 -41
- package/dist/number/branded-types/non-positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-int.d.mts +41 -146
- package/dist/number/branded-types/non-positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-int.mjs +27 -107
- package/dist/number/branded-types/non-positive-int.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-safe-int.d.mts +54 -53
- package/dist/number/branded-types/non-positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-safe-int.mjs +37 -39
- package/dist/number/branded-types/non-positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-finite-number.d.mts +62 -49
- package/dist/number/branded-types/non-zero-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-finite-number.mjs +46 -37
- package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int.d.mts +51 -38
- package/dist/number/branded-types/non-zero-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int.mjs +31 -27
- package/dist/number/branded-types/non-zero-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int16.d.mts +52 -53
- package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int16.mjs +36 -39
- package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int32.d.mts +52 -54
- package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int32.mjs +36 -40
- package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.d.mts +53 -54
- package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.mjs +36 -40
- package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.d.mts +52 -53
- package/dist/number/branded-types/non-zero-uint16.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.mjs +35 -39
- package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.d.mts +52 -53
- package/dist/number/branded-types/non-zero-uint32.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.mjs +35 -39
- package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
- package/dist/number/branded-types/positive-finite-number.d.mts +74 -63
- package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/positive-finite-number.mjs +58 -50
- package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/positive-int.d.mts +46 -68
- package/dist/number/branded-types/positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int.mjs +34 -49
- package/dist/number/branded-types/positive-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-int16.d.mts +61 -57
- package/dist/number/branded-types/positive-int16.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int16.mjs +44 -43
- package/dist/number/branded-types/positive-int16.mjs.map +1 -1
- package/dist/number/branded-types/positive-int32.d.mts +61 -57
- package/dist/number/branded-types/positive-int32.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int32.mjs +44 -43
- package/dist/number/branded-types/positive-int32.mjs.map +1 -1
- package/dist/number/branded-types/positive-safe-int.d.mts +62 -57
- package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-safe-int.mjs +45 -43
- package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint16.d.mts +61 -57
- package/dist/number/branded-types/positive-uint16.d.mts.map +1 -1
- package/dist/number/branded-types/positive-uint16.mjs +44 -43
- package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint32.d.mts +61 -58
- package/dist/number/branded-types/positive-uint32.d.mts.map +1 -1
- package/dist/number/branded-types/positive-uint32.mjs +44 -44
- package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
- package/dist/number/branded-types/safe-int.d.mts +43 -62
- package/dist/number/branded-types/safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/safe-int.mjs +35 -42
- package/dist/number/branded-types/safe-int.mjs.map +1 -1
- package/dist/number/branded-types/safe-uint.d.mts +62 -57
- package/dist/number/branded-types/safe-uint.d.mts.map +1 -1
- package/dist/number/branded-types/safe-uint.mjs +46 -44
- package/dist/number/branded-types/safe-uint.mjs.map +1 -1
- package/dist/number/branded-types/uint.d.mts +63 -50
- package/dist/number/branded-types/uint.d.mts.map +1 -1
- package/dist/number/branded-types/uint.mjs +42 -39
- package/dist/number/branded-types/uint.mjs.map +1 -1
- package/dist/number/branded-types/uint16.d.mts +60 -58
- package/dist/number/branded-types/uint16.d.mts.map +1 -1
- package/dist/number/branded-types/uint16.mjs +44 -43
- package/dist/number/branded-types/uint16.mjs.map +1 -1
- package/dist/number/branded-types/uint32.d.mts +59 -55
- package/dist/number/branded-types/uint32.d.mts.map +1 -1
- package/dist/number/branded-types/uint32.mjs +42 -42
- package/dist/number/branded-types/uint32.mjs.map +1 -1
- package/dist/number/enum/int8.d.mts +56 -65
- package/dist/number/enum/int8.d.mts.map +1 -1
- package/dist/number/enum/int8.mjs +44 -43
- package/dist/number/enum/int8.mjs.map +1 -1
- package/dist/number/enum/uint8.d.mts +60 -58
- package/dist/number/enum/uint8.d.mts.map +1 -1
- package/dist/number/enum/uint8.mjs +44 -43
- package/dist/number/enum/uint8.mjs.map +1 -1
- package/dist/string/index.d.mts +2 -0
- package/dist/string/index.d.mts.map +1 -0
- package/dist/string/index.mjs +2 -0
- package/dist/string/index.mjs.map +1 -0
- package/dist/string/str.d.mts +273 -0
- package/dist/string/str.d.mts.map +1 -0
- package/dist/string/str.mjs +42 -0
- package/dist/string/str.mjs.map +1 -0
- package/package.json +31 -92
- package/src/array/impl/array-utils-creation.mts +2 -1
- package/src/array/impl/array-utils-element-access.mts +3 -3
- package/src/array/impl/array-utils-element-access.test.mts +3 -3
- package/src/{guard/as-length-bounded-array.mts → array/impl/array-utils-length-bounded-array-cast.mts} +9 -9
- package/src/{guard/as-length-bounded-array.test.mts → array/impl/array-utils-length-bounded-array-cast.test.mts} +2 -2
- package/src/{guard/is-length-bounded-array.mts → array/impl/array-utils-length-bounded-array-guard.mts} +12 -12
- package/src/{guard/is-length-bounded-array.test.mts → array/impl/array-utils-length-bounded-array-guard.test.mts} +2 -2
- package/src/array/impl/array-utils-modification.mts +9 -8
- package/src/array/impl/array-utils-modification.test.mts +6 -1
- package/src/array/impl/array-utils-reducing-value.mts +9 -9
- package/src/array/impl/array-utils-size.mts +2 -2
- package/src/array/impl/array-utils-slicing.mts +24 -13
- package/src/array/impl/array-utils-transformation.mts +18 -12
- package/src/array/impl/array-utils-transformation.test.mts +12 -12
- package/src/array/impl/index.mts +2 -0
- package/src/guard/index.mts +0 -3
- package/src/index.mts +1 -0
- package/src/number/branded-types/finite-number.mts +47 -61
- package/src/number/branded-types/int.mts +40 -46
- package/src/number/branded-types/int16.mts +65 -58
- package/src/number/branded-types/int32.mts +65 -58
- package/src/number/branded-types/negative-finite-number.mts +68 -68
- package/src/number/branded-types/negative-int.mts +60 -57
- package/src/number/branded-types/negative-safe-int.mts +57 -65
- package/src/number/branded-types/non-negative-finite-number.mts +74 -64
- package/src/number/branded-types/non-negative-int16.mts +64 -57
- package/src/number/branded-types/non-negative-int32.mts +64 -58
- package/src/number/branded-types/non-positive-finite-number.mts +64 -54
- package/src/number/branded-types/non-positive-int.mts +41 -146
- package/src/number/branded-types/non-positive-safe-int.mts +54 -53
- package/src/number/branded-types/non-zero-finite-number.mts +62 -51
- package/src/number/branded-types/non-zero-int.mts +51 -38
- package/src/number/branded-types/non-zero-int16.mts +52 -53
- package/src/number/branded-types/non-zero-int32.mts +52 -54
- package/src/number/branded-types/non-zero-safe-int.mts +53 -54
- package/src/number/branded-types/non-zero-uint16.mts +52 -53
- package/src/number/branded-types/non-zero-uint32.mts +52 -53
- package/src/number/branded-types/positive-finite-number.mts +74 -63
- package/src/number/branded-types/positive-int.mts +46 -68
- package/src/number/branded-types/positive-int16.mts +61 -57
- package/src/number/branded-types/positive-int32.mts +61 -57
- package/src/number/branded-types/positive-safe-int.mts +62 -57
- package/src/number/branded-types/positive-uint16.mts +61 -57
- package/src/number/branded-types/positive-uint32.mts +61 -58
- package/src/number/branded-types/safe-int.mts +43 -62
- package/src/number/branded-types/safe-uint.mts +62 -57
- package/src/number/branded-types/uint.mts +63 -50
- package/src/number/branded-types/uint16.mts +60 -58
- package/src/number/branded-types/uint32.mts +59 -55
- package/src/number/enum/int8.mts +56 -65
- package/src/number/enum/uint8.mts +60 -58
- package/src/string/index.mts +1 -0
- package/src/string/str.mts +371 -0
- package/src/string/str.test.mts +215 -0
- package/dist/guard/as-length-bounded-array.d.mts.map +0 -1
- package/dist/guard/as-length-bounded-array.mjs.map +0 -1
- package/dist/guard/is-length-bounded-array.d.mts.map +0 -1
- package/dist/guard/is-length-bounded-array.mjs.map +0 -1
- package/dist/guard/is-length-bounded-string.d.mts +0 -163
- package/dist/guard/is-length-bounded-string.d.mts.map +0 -1
- package/dist/guard/is-length-bounded-string.mjs +0 -7
- package/dist/guard/is-length-bounded-string.mjs.map +0 -1
- package/src/guard/is-length-bounded-string.mts +0 -199
- package/src/guard/is-length-bounded-string.test.mts +0 -170
|
@@ -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 } from 'ts-type-forge';
|
|
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';
|
|
2
2
|
import { type SizeType } from '../../types.mjs';
|
|
3
3
|
/**
|
|
4
4
|
* Creates an array of zeros with the specified length.
|
|
@@ -47,13 +47,13 @@ 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
|
|
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[];
|
|
51
51
|
/**
|
|
52
52
|
* Alias for `create`.
|
|
53
53
|
*
|
|
54
54
|
* @see {@link create}
|
|
55
55
|
*/
|
|
56
|
-
export declare const newArray: <N extends SizeType.ArgArr, const V>(len: N, init: V) => N extends
|
|
56
|
+
export declare const newArray: <N extends SizeType.ArgArr, const V>(len: N, init: V) => N extends StructuralPrefixLength ? FixedLengthTuple<N, V> : N extends SizeType.ArgArrPositive ? NonEmptyArray<V> : readonly V[];
|
|
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,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,
|
|
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,CAA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}
|
|
@@ -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} 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
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type NonEmptyTuple } from 'ts-type-forge';
|
|
2
2
|
import { Optional } from '../../functional/index.mjs';
|
|
3
3
|
import { type ArgArrayIndexWithNegative, type None, type SizeType, type Some } from '../../types.mjs';
|
|
4
4
|
/**
|
|
@@ -43,7 +43,7 @@ export declare function at(index: SizeType.ArgArrWithNegative): <E>(array: reado
|
|
|
43
43
|
* assert.deepStrictEqual(none, Optional.none);
|
|
44
44
|
* ```
|
|
45
45
|
*/
|
|
46
|
-
export declare const head: <const Ar extends readonly unknown[]>(array: Ar) => Ar extends readonly [] ? None : Ar extends readonly [infer E, ...unknown[]] ? Some<E> : Ar extends
|
|
46
|
+
export declare const head: <const Ar extends readonly unknown[]>(array: Ar) => Ar extends readonly [] ? None : Ar extends readonly [infer E, ...unknown[]] ? Some<E> : Ar extends NonEmptyTuple<infer E> ? Some<E> : Optional<Ar[number]>;
|
|
47
47
|
/**
|
|
48
48
|
* Returns the last element of an array as an Optional.
|
|
49
49
|
*
|
|
@@ -63,11 +63,11 @@ export declare const head: <const Ar extends readonly unknown[]>(array: Ar) => A
|
|
|
63
63
|
* assert.deepStrictEqual(none, Optional.none);
|
|
64
64
|
* ```
|
|
65
65
|
*/
|
|
66
|
-
export declare const last: <const Ar extends readonly unknown[]>(array: Ar) => Ar extends readonly [] ? None : Ar extends readonly [...unknown[], infer E] ? Some<E> : Ar extends
|
|
66
|
+
export declare const last: <const Ar extends readonly unknown[]>(array: Ar) => Ar extends readonly [] ? None : Ar extends readonly [...unknown[], infer E] ? Some<E> : Ar extends NonEmptyTuple<infer E> ? Some<E> : Optional<Ar[number]>;
|
|
67
67
|
/**
|
|
68
68
|
* Alias for `head`.
|
|
69
69
|
*
|
|
70
70
|
* @see {@link head}
|
|
71
71
|
*/
|
|
72
|
-
export declare const first: <const Ar extends readonly unknown[]>(array: Ar) => Ar extends readonly [] ? None : Ar extends readonly [infer E, ...unknown[]] ? Some<E> : Ar extends
|
|
72
|
+
export declare const first: <const Ar extends readonly unknown[]>(array: Ar) => Ar extends readonly [] ? None : Ar extends readonly [infer E, ...unknown[]] ? Some<E> : Ar extends NonEmptyTuple<infer E> ? Some<E> : Optional<Ar[number]>;
|
|
73
73
|
//# sourceMappingURL=array-utils-element-access.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-utils-element-access.mjs","sources":["../../../src/array/impl/array-utils-element-access.mts"],"sourcesContent":["import { type
|
|
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 const [array, index] = args;\n\n return pipe(index < 0 ? array.length + index : index).map(\n (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 case 1: {\n const [index] = args;\n\n return (array) => at(array, index);\n }\n }\n}\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,EAAG;AACN,MAAA,MAAM,CAAC,KAAA,EAAOA,OAAK,CAAA,GAAI,IAAA;AAEvB,MAAA,OAAO,KAAKA,OAAA,GAAQ,CAAA,GAAI,MAAM,MAAA,GAASA,OAAA,GAAQA,OAAK,CAAA,CAAE,GAAA;AAAA,QACpD,CAAC,eAAA,KACC,eAAA,GAAkB,KAAK,eAAA,IAAmB,KAAA,CAAM,SAC5CC,IAAS;AAAA;AAAA,UAETC,IAAS,CAAK,KAAA,CAAM,eAAe,CAAE;AAAA;AAAA,OAC7C,CAAE,KAAA;AAAA,IACJ;AAAA,IAEA,KAAK,CAAA,EAAG;AACN,MAAA,MAAM,CAAC,KAAK,CAAA,GAAI,IAAA;AAEhB,MAAA,OAAO,CAAC,KAAA,KAAU,EAAA,CAAG,KAAA,EAAO,KAAK,CAAA;AAAA,IACnC;AAAA;AAEJ;AAqBO,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;;;;"}
|
|
@@ -12,12 +12,12 @@ import { type BoundedLengthArray, type FixedLengthArray, type MaxLengthArray, ty
|
|
|
12
12
|
* @example
|
|
13
13
|
*
|
|
14
14
|
* ```ts
|
|
15
|
-
* const rgb = asFixedLengthArray([255, 128, 0], 3);
|
|
15
|
+
* const rgb = Arr.asFixedLengthArray([255, 128, 0], 3);
|
|
16
16
|
*
|
|
17
17
|
* const atMost5: MaxLengthArray<5, number> = rgb; // OK (3 <= 5)
|
|
18
18
|
* const red: number = rgb[0]; // OK — no `undefined`
|
|
19
19
|
*
|
|
20
|
-
* // asFixedLengthArray([255, 128], 3); // throws TypeError
|
|
20
|
+
* // Arr.asFixedLengthArray([255, 128], 3); // throws TypeError
|
|
21
21
|
* ```
|
|
22
22
|
*
|
|
23
23
|
* @template Xs - The input array type (tuple types are preserved).
|
|
@@ -41,12 +41,12 @@ export declare const asFixedLengthArray: <Xs extends readonly unknown[], Length
|
|
|
41
41
|
* @example
|
|
42
42
|
*
|
|
43
43
|
* ```ts
|
|
44
|
-
* const history = asMinLengthArray([0, 1, 2, 3], 3);
|
|
44
|
+
* const history = Arr.asMinLengthArray([0, 1, 2, 3], 3);
|
|
45
45
|
*
|
|
46
46
|
* const nonEmpty: MinLengthArray<1, number> = history; // OK (3 >= 1)
|
|
47
47
|
* const first: number = history[0]; // OK — no `undefined`
|
|
48
48
|
*
|
|
49
|
-
* // asMinLengthArray([0], 3); // throws TypeError
|
|
49
|
+
* // Arr.asMinLengthArray([0], 3); // throws TypeError
|
|
50
50
|
* ```
|
|
51
51
|
*
|
|
52
52
|
* @template Xs - The input array type (tuple types are preserved).
|
|
@@ -68,11 +68,11 @@ export declare const asMinLengthArray: <Xs extends readonly unknown[], MinLength
|
|
|
68
68
|
* @example
|
|
69
69
|
*
|
|
70
70
|
* ```ts
|
|
71
|
-
* const tags = asMaxLengthArray(['a', 'b', 'c'], 8);
|
|
71
|
+
* const tags = Arr.asMaxLengthArray(['a', 'b', 'c'], 8);
|
|
72
72
|
*
|
|
73
73
|
* const relaxed: MaxLengthArray<16, string> = tags; // OK (8 <= 16)
|
|
74
74
|
*
|
|
75
|
-
* // asMaxLengthArray(['a', 'b', 'c'], 2); // throws TypeError
|
|
75
|
+
* // Arr.asMaxLengthArray(['a', 'b', 'c'], 2); // throws TypeError
|
|
76
76
|
* ```
|
|
77
77
|
*
|
|
78
78
|
* @template Xs - The input array type (tuple types are preserved).
|
|
@@ -96,11 +96,11 @@ export declare const asMaxLengthArray: <Xs extends readonly unknown[], MaxLength
|
|
|
96
96
|
* @example
|
|
97
97
|
*
|
|
98
98
|
* ```ts
|
|
99
|
-
* const selection = asBoundedLengthArray([1, 2, 3], 1, 5);
|
|
99
|
+
* const selection = Arr.asBoundedLengthArray([1, 2, 3], 1, 5);
|
|
100
100
|
*
|
|
101
101
|
* const relaxed: BoundedLengthArray<0, 100, number> = selection; // OK
|
|
102
102
|
*
|
|
103
|
-
* // asBoundedLengthArray([], 1, 5); // throws TypeError
|
|
103
|
+
* // Arr.asBoundedLengthArray([], 1, 5); // throws TypeError
|
|
104
104
|
* ```
|
|
105
105
|
*
|
|
106
106
|
* @template Xs - The input array type (tuple types are preserved).
|
|
@@ -114,4 +114,4 @@ export declare const asMaxLengthArray: <Xs extends readonly unknown[], MaxLength
|
|
|
114
114
|
* @throws {TypeError} If `xs.length < minLength || xs.length > maxLength`.
|
|
115
115
|
*/
|
|
116
116
|
export declare const asBoundedLengthArray: <Xs extends readonly unknown[], MinLength extends SupportedLength, MaxLength extends SupportedLength>(xs: Xs, minLength: MinLength, maxLength: MaxLength) => BoundedLengthArray<MinLength, MaxLength, Xs[number]> & Xs;
|
|
117
|
-
//# sourceMappingURL=
|
|
117
|
+
//# sourceMappingURL=array-utils-length-bounded-array-cast.d.mts.map
|
|
@@ -0,0 +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,eAAe,EACrB,MAAM,eAAe,CAAC;AAQvB;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,kBAAkB,GAC7B,EAAE,SAAS,SAAS,OAAO,EAAE,EAC7B,MAAM,SAAS,eAAe,MAE1B,EAAE,UACE,MAAM,KACb,gBAAgB,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,EAQzC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,gBAAgB,GAC3B,EAAE,SAAS,SAAS,OAAO,EAAE,EAC7B,SAAS,SAAS,eAAe,MAE7B,EAAE,aACK,SAAS,KACnB,cAAc,CAAC,SAAS,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,EAQ1C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,gBAAgB,GAC3B,EAAE,SAAS,SAAS,OAAO,EAAE,EAC7B,SAAS,SAAS,eAAe,MAE7B,EAAE,aACK,SAAS,KACnB,cAAc,CAAC,SAAS,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,EAQ1C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,oBAAoB,GAC/B,EAAE,SAAS,SAAS,OAAO,EAAE,EAC7B,SAAS,SAAS,eAAe,EACjC,SAAS,SAAS,eAAe,MAE7B,EAAE,aACK,SAAS,aACT,SAAS,KACnB,kBAAkB,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,EAQzD,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isBoundedLengthArray, isFixedLengthArray, isMaxLengthArray, isMinLengthArray } from './
|
|
1
|
+
import { isBoundedLengthArray, isFixedLengthArray, isMaxLengthArray, isMinLengthArray } from './array-utils-length-bounded-array-guard.mjs';
|
|
2
2
|
|
|
3
3
|
const asFixedLengthArray = (xs, length) => {
|
|
4
4
|
if (!isFixedLengthArray(xs, length)) {
|
|
@@ -34,4 +34,4 @@ const asBoundedLengthArray = (xs, minLength, maxLength) => {
|
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
export { asBoundedLengthArray, asFixedLengthArray, asMaxLengthArray, asMinLengthArray };
|
|
37
|
-
//# sourceMappingURL=
|
|
37
|
+
//# sourceMappingURL=array-utils-length-bounded-array-cast.mjs.map
|
|
@@ -0,0 +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 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 * @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 * // 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 const asFixedLengthArray = <\n Xs extends readonly unknown[],\n Length extends SupportedLength,\n>(\n xs: Xs,\n length: Length,\n): FixedLengthArray<Length, Xs[number]> & Xs => {\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/**\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 * @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 * // 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 const asMinLengthArray = <\n Xs extends readonly unknown[],\n MinLength extends SupportedLength,\n>(\n xs: Xs,\n minLength: MinLength,\n): MinLengthArray<MinLength, Xs[number]> & Xs => {\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/**\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 * @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 * // 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 const asMaxLengthArray = <\n Xs extends readonly unknown[],\n MaxLength extends SupportedLength,\n>(\n xs: Xs,\n maxLength: MaxLength,\n): MaxLengthArray<MaxLength, Xs[number]> & Xs => {\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/**\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 * @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 * // 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 const 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 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"],"names":[],"mappings":";;AA0CO,MAAM,kBAAA,GAAqB,CAIhC,EAAA,EACA,MAAA,KAC8C;AAC9C,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,EAAA,CAAG,MAAM,CAAA;AAAA,KAC5E;AAAA,EACF;AAEA,EAAA,OAAO,EAAA;AACT;AA8BO,MAAM,gBAAA,GAAmB,CAI9B,EAAA,EACA,SAAA,KAC+C;AAC/C,EAAA,IAAI,CAAC,gBAAA,CAAiB,EAAA,EAAI,SAAS,CAAA,EAAG;AACpC,IAAA,MAAM,IAAI,SAAA;AAAA,MACR,CAAA,+BAAA,EAAkC,SAAS,CAAA,yBAAA,EAA4B,EAAA,CAAG,MAAM,CAAA;AAAA,KAClF;AAAA,EACF;AAEA,EAAA,OAAO,EAAA;AACT;AA2BO,MAAM,gBAAA,GAAmB,CAI9B,EAAA,EACA,SAAA,KAC+C;AAC/C,EAAA,IAAI,CAAC,gBAAA,CAAiB,EAAA,EAAI,SAAS,CAAA,EAAG;AACpC,IAAA,MAAM,IAAI,SAAA;AAAA,MACR,CAAA,+BAAA,EAAkC,SAAS,CAAA,yBAAA,EAA4B,EAAA,CAAG,MAAM,CAAA;AAAA,KAClF;AAAA,EACF;AAEA,EAAA,OAAO,EAAA;AACT;AAgCO,MAAM,oBAAA,GAAuB,CAKlC,EAAA,EACA,SAAA,EACA,SAAA,KAC8D;AAC9D,EAAA,IAAI,CAAC,oBAAA,CAAqB,EAAA,EAAI,SAAA,EAAW,SAAS,CAAA,EAAG;AACnD,IAAA,MAAM,IAAI,SAAA;AAAA,MACR,mCAAmC,SAAS,CAAA,EAAA,EAAK,SAAS,CAAA,0BAAA,EAA6B,GAAG,MAAM,CAAA;AAAA,KAClG;AAAA,EACF;AAEA,EAAA,OAAO,EAAA;AACT;;;;"}
|
|
@@ -18,11 +18,11 @@ import { type BoundedLengthArray, type FixedLengthArray, type MaxLengthArray, ty
|
|
|
18
18
|
* ```ts
|
|
19
19
|
* const input: readonly number[] = [0, 1, 2, 3];
|
|
20
20
|
*
|
|
21
|
-
* assert.isTrue(isMinLengthArray(input, 3));
|
|
21
|
+
* assert.isTrue(Arr.isMinLengthArray(input, 3));
|
|
22
22
|
*
|
|
23
|
-
* assert.isFalse(isMinLengthArray([0], 3));
|
|
23
|
+
* assert.isFalse(Arr.isMinLengthArray([0], 3));
|
|
24
24
|
*
|
|
25
|
-
* if (isMinLengthArray(input, 3)) {
|
|
25
|
+
* if (Arr.isMinLengthArray(input, 3)) {
|
|
26
26
|
* const history: MinLengthArray<3, number> = input;
|
|
27
27
|
*
|
|
28
28
|
* const nonEmpty: MinLengthArray<1, number> = input; // OK (3 >= 1)
|
|
@@ -56,11 +56,11 @@ export declare const isMinLengthArray: <Xs extends readonly unknown[], MinLength
|
|
|
56
56
|
* ```ts
|
|
57
57
|
* const input: readonly string[] = ['a', 'b', 'c'];
|
|
58
58
|
*
|
|
59
|
-
* assert.isTrue(isMaxLengthArray(input, 8));
|
|
59
|
+
* assert.isTrue(Arr.isMaxLengthArray(input, 8));
|
|
60
60
|
*
|
|
61
|
-
* assert.isFalse(isMaxLengthArray(input, 2));
|
|
61
|
+
* assert.isFalse(Arr.isMaxLengthArray(input, 2));
|
|
62
62
|
*
|
|
63
|
-
* if (isMaxLengthArray(input, 8)) {
|
|
63
|
+
* if (Arr.isMaxLengthArray(input, 8)) {
|
|
64
64
|
* const tags: MaxLengthArray<8, string> = input;
|
|
65
65
|
*
|
|
66
66
|
* const relaxed: MaxLengthArray<16, string> = input; // OK (8 <= 16)
|
|
@@ -95,11 +95,11 @@ export declare const isMaxLengthArray: <Xs extends readonly unknown[], MaxLength
|
|
|
95
95
|
* ```ts
|
|
96
96
|
* const input: readonly number[] = [1, 2, 3];
|
|
97
97
|
*
|
|
98
|
-
* assert.isTrue(isBoundedLengthArray(input, 1, 5));
|
|
98
|
+
* assert.isTrue(Arr.isBoundedLengthArray(input, 1, 5));
|
|
99
99
|
*
|
|
100
|
-
* assert.isFalse(isBoundedLengthArray([], 1, 5));
|
|
100
|
+
* assert.isFalse(Arr.isBoundedLengthArray([], 1, 5));
|
|
101
101
|
*
|
|
102
|
-
* if (isBoundedLengthArray(input, 1, 5)) {
|
|
102
|
+
* if (Arr.isBoundedLengthArray(input, 1, 5)) {
|
|
103
103
|
* const selection: BoundedLengthArray<1, 5, number> = input;
|
|
104
104
|
*
|
|
105
105
|
* const relaxed: BoundedLengthArray<0, 100, number> = input; // OK ([1, 5] ⊆ [0, 100])
|
|
@@ -137,11 +137,11 @@ export declare const isBoundedLengthArray: <Xs extends readonly unknown[], MinLe
|
|
|
137
137
|
* ```ts
|
|
138
138
|
* const input: readonly number[] = [255, 128, 0];
|
|
139
139
|
*
|
|
140
|
-
* assert.isTrue(isFixedLengthArray(input, 3));
|
|
140
|
+
* assert.isTrue(Arr.isFixedLengthArray(input, 3));
|
|
141
141
|
*
|
|
142
|
-
* assert.isFalse(isFixedLengthArray(input, 4));
|
|
142
|
+
* assert.isFalse(Arr.isFixedLengthArray(input, 4));
|
|
143
143
|
*
|
|
144
|
-
* if (isFixedLengthArray(input, 3)) {
|
|
144
|
+
* if (Arr.isFixedLengthArray(input, 3)) {
|
|
145
145
|
* const rgb: FixedLengthArray<3, number> = input;
|
|
146
146
|
*
|
|
147
147
|
* const atMost5: MaxLengthArray<5, number> = input; // OK (3 <= 5)
|
|
@@ -156,4 +156,4 @@ export declare const isBoundedLengthArray: <Xs extends readonly unknown[], MinLe
|
|
|
156
156
|
* TypeScript narrows `xs` to `FixedLengthArray<Length, Xs[number]> & Xs`.
|
|
157
157
|
*/
|
|
158
158
|
export declare const isFixedLengthArray: <Xs extends readonly unknown[], Length extends SupportedLength>(xs: Xs, length: Length) => xs is FixedLengthArray<Length, Xs[number]> & Xs;
|
|
159
|
-
//# sourceMappingURL=
|
|
159
|
+
//# sourceMappingURL=array-utils-length-bounded-array-guard.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array-utils-length-bounded-array-guard.d.mts","sourceRoot":"","sources":["../../../src/array/impl/array-utils-length-bounded-array-guard.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,eAAe,EACrB,MAAM,eAAe,CAAC;AAEvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,eAAO,MAAM,gBAAgB,GAC3B,EAAE,SAAS,SAAS,OAAO,EAAE,EAC7B,SAAS,SAAS,eAAe,MAE7B,EAAE,aACK,SAAS,KACnB,EAAE,IAAI,cAAc,CAAC,SAAS,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,EAA4B,CAAC;AAE9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,eAAO,MAAM,gBAAgB,GAC3B,EAAE,SAAS,SAAS,OAAO,EAAE,EAC7B,SAAS,SAAS,eAAe,MAE7B,EAAE,aACK,SAAS,KACnB,EAAE,IAAI,cAAc,CAAC,SAAS,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,EAA4B,CAAC;AAE9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,eAAO,MAAM,oBAAoB,GAC/B,EAAE,SAAS,SAAS,OAAO,EAAE,EAC7B,SAAS,SAAS,eAAe,EACjC,SAAS,SAAS,eAAe,MAE7B,EAAE,aACK,SAAS,aACT,SAAS,KACnB,EAAE,IAAI,kBAAkB,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,EACd,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,eAAO,MAAM,kBAAkB,GAC7B,EAAE,SAAS,SAAS,OAAO,EAAE,EAC7B,MAAM,SAAS,eAAe,MAE1B,EAAE,UACE,MAAM,KACb,EAAE,IAAI,gBAAgB,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,EAA0B,CAAC"}
|
|
@@ -4,4 +4,4 @@ const isBoundedLengthArray = (xs, minLength, maxLength) => xs.length >= minLengt
|
|
|
4
4
|
const isFixedLengthArray = (xs, length) => xs.length === length;
|
|
5
5
|
|
|
6
6
|
export { isBoundedLengthArray, isFixedLengthArray, isMaxLengthArray, isMinLengthArray };
|
|
7
|
-
//# sourceMappingURL=
|
|
7
|
+
//# sourceMappingURL=array-utils-length-bounded-array-guard.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array-utils-length-bounded-array-guard.mjs","sources":["../../../src/array/impl/array-utils-length-bounded-array-guard.mts"],"sourcesContent":["import {\n type BoundedLengthArray,\n type FixedLengthArray,\n type MaxLengthArray,\n type MinLengthArray,\n type SupportedLength,\n} from 'ts-type-forge';\n\n/**\n * Type guard that checks if an array has at least `minLength` elements.\n *\n * **Type Narrowing Behavior:**\n *\n * - Narrows the input to `MinLengthArray<MinLength, E>` while preserving the\n * original array type (e.g. tuple types) via intersection.\n * - The length constraint lives only in the brand, so this stays cheap for the\n * type checker even when the element type is large — unlike\n * `isMinLengthTuple`, which narrows to a structural tuple type.\n * - The result participates in the length-constraint subtyping relation: for\n * example, a value narrowed to `MinLengthArray<3, E>` is assignable to\n * `MinLengthArray<1, E>`.\n *\n * @example\n *\n * ```ts\n * const input: readonly number[] = [0, 1, 2, 3];\n *\n * assert.isTrue(Arr.isMinLengthArray(input, 3));\n *\n * assert.isFalse(Arr.isMinLengthArray([0], 3));\n *\n * if (Arr.isMinLengthArray(input, 3)) {\n * const history: MinLengthArray<3, number> = input;\n *\n * const nonEmpty: MinLengthArray<1, number> = input; // OK (3 >= 1)\n * }\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 check.\n * @param minLength - The minimum number of elements (inclusive).\n * @returns `true` if `xs.length >= minLength`, `false` otherwise. When `true`,\n * TypeScript narrows `xs` to `MinLengthArray<MinLength, Xs[number]> & Xs`.\n */\nexport const isMinLengthArray = <\n Xs extends readonly unknown[],\n MinLength extends SupportedLength,\n>(\n xs: Xs,\n minLength: MinLength,\n): xs is MinLengthArray<MinLength, Xs[number]> & Xs => xs.length >= minLength;\n\n/**\n * Type guard that checks if an array has at most `maxLength` elements.\n *\n * **Type Narrowing Behavior:**\n *\n * - Narrows the input to `MaxLengthArray<MaxLength, E>` while preserving the\n * original array type (e.g. tuple types) via intersection.\n * - The length constraint lives only in the brand, so this stays cheap for the\n * type checker even when the element type is large — unlike\n * `isMaxLengthTuple`, which narrows to a union of tuple types.\n * - The result participates in the length-constraint subtyping relation: for\n * example, a value narrowed to `MaxLengthArray<8, E>` is assignable to\n * `MaxLengthArray<16, E>`.\n *\n * @example\n *\n * ```ts\n * const input: readonly string[] = ['a', 'b', 'c'];\n *\n * assert.isTrue(Arr.isMaxLengthArray(input, 8));\n *\n * assert.isFalse(Arr.isMaxLengthArray(input, 2));\n *\n * if (Arr.isMaxLengthArray(input, 8)) {\n * const tags: MaxLengthArray<8, string> = input;\n *\n * const relaxed: MaxLengthArray<16, string> = input; // OK (8 <= 16)\n * }\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 check.\n * @param maxLength - The maximum number of elements (inclusive).\n * @returns `true` if `xs.length <= maxLength`, `false` otherwise. When `true`,\n * TypeScript narrows `xs` to `MaxLengthArray<MaxLength, Xs[number]> & Xs`.\n */\nexport const isMaxLengthArray = <\n Xs extends readonly unknown[],\n MaxLength extends SupportedLength,\n>(\n xs: Xs,\n maxLength: MaxLength,\n): xs is MaxLengthArray<MaxLength, Xs[number]> & Xs => xs.length <= maxLength;\n\n/**\n * Type guard that checks if an array's length is within the inclusive range\n * `[minLength, maxLength]`.\n *\n * **Type Narrowing Behavior:**\n *\n * - Narrows the input to `BoundedLengthArray<MinLength, MaxLength, E>` while\n * preserving the original array type (e.g. tuple types) via intersection.\n * - Since `BoundedLengthArray` is the intersection of `MinLengthArray` and\n * `MaxLengthArray`, the narrowed value is assignable to both, and both\n * bounds can be weakened independently.\n * - The length constraint lives only in the brand, so this stays cheap for the\n * type checker even when the element type is large — unlike\n * `isBoundedLengthTuple`, which narrows to a union of tuple types.\n *\n * @example\n *\n * ```ts\n * const input: readonly number[] = [1, 2, 3];\n *\n * assert.isTrue(Arr.isBoundedLengthArray(input, 1, 5));\n *\n * assert.isFalse(Arr.isBoundedLengthArray([], 1, 5));\n *\n * if (Arr.isBoundedLengthArray(input, 1, 5)) {\n * const selection: BoundedLengthArray<1, 5, number> = input;\n *\n * const relaxed: BoundedLengthArray<0, 100, number> = input; // OK ([1, 5] ⊆ [0, 100])\n * }\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 check.\n * @param minLength - The minimum number of elements (inclusive).\n * @param maxLength - The maximum number of elements (inclusive).\n * @returns `true` if `minLength <= xs.length && xs.length <= maxLength`,\n * `false` otherwise. When `true`, TypeScript narrows `xs` to\n * `BoundedLengthArray<MinLength, MaxLength, Xs[number]> & Xs`.\n */\nexport const isBoundedLengthArray = <\n Xs extends readonly unknown[],\n MinLength extends SupportedLength,\n MaxLength extends SupportedLength,\n>(\n xs: Xs,\n minLength: MinLength,\n maxLength: MaxLength,\n): xs is BoundedLengthArray<MinLength, MaxLength, Xs[number]> & Xs =>\n xs.length >= minLength && xs.length <= maxLength;\n\n/**\n * Type guard that checks if an array has exactly `length` elements.\n *\n * **Type Narrowing Behavior:**\n *\n * - Narrows the input to `FixedLengthArray<Length, E>` while preserving the\n * original array type (e.g. tuple types) via intersection.\n * - Since `FixedLengthArray<Length, E>` is defined as\n * `BoundedLengthArray<Length, Length, E>`, the narrowed value is assignable\n * to any `MinLengthArray<N, E>` with `N <= Length` and any\n * `MaxLengthArray<N, E>` with `N >= Length`.\n * - The length constraint lives only in the brand, so this stays cheap for the\n * type checker even when the element type is large — unlike\n * `isFixedLengthTuple`, which narrows to a structural tuple type.\n *\n * @example\n *\n * ```ts\n * const input: readonly number[] = [255, 128, 0];\n *\n * assert.isTrue(Arr.isFixedLengthArray(input, 3));\n *\n * assert.isFalse(Arr.isFixedLengthArray(input, 4));\n *\n * if (Arr.isFixedLengthArray(input, 3)) {\n * const rgb: FixedLengthArray<3, number> = input;\n *\n * const atMost5: MaxLengthArray<5, number> = input; // OK (3 <= 5)\n * }\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 check.\n * @param length - The exact number of elements.\n * @returns `true` if `xs.length === length`, `false` otherwise. When `true`,\n * TypeScript narrows `xs` to `FixedLengthArray<Length, Xs[number]> & Xs`.\n */\nexport const isFixedLengthArray = <\n Xs extends readonly unknown[],\n Length extends SupportedLength,\n>(\n xs: Xs,\n length: Length,\n): xs is FixedLengthArray<Length, Xs[number]> & Xs => xs.length === length;\n"],"names":[],"mappings":"AA6CO,MAAM,gBAAA,GAAmB,CAI9B,EAAA,EACA,SAAA,KACqD,GAAG,MAAA,IAAU;AAuC7D,MAAM,gBAAA,GAAmB,CAI9B,EAAA,EACA,SAAA,KACqD,GAAG,MAAA,IAAU;AA2C7D,MAAM,oBAAA,GAAuB,CAKlC,EAAA,EACA,SAAA,EACA,cAEA,EAAA,CAAG,MAAA,IAAU,SAAA,IAAa,EAAA,CAAG,MAAA,IAAU;AAwClC,MAAM,kBAAA,GAAqB,CAIhC,EAAA,EACA,MAAA,KACoD,GAAG,MAAA,KAAW;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type FixedLengthTuple, type Increment, type IsFixedLengthList, type NonEmptyArray } from 'ts-type-forge';
|
|
1
|
+
import { type FixedLengthTuple, type Increment, type IsFixedLengthList, type NonEmptyArray, type NonEmptyTuple } from 'ts-type-forge';
|
|
2
2
|
import { type ArgArrayIndex, type ArgArrayIndexWithNegative, type SizeType } from '../../types.mjs';
|
|
3
3
|
/**
|
|
4
4
|
* Returns a new array with an element at the specified index replaced.
|
|
@@ -15,10 +15,10 @@ import { type ArgArrayIndex, type ArgArrayIndexWithNegative, type SizeType } fro
|
|
|
15
15
|
*/
|
|
16
16
|
export declare function set<const Ar extends readonly unknown[], const V = Ar[number]>(array: Ar, index: ArgArrayIndex<Ar>, newValue: V): IsFixedLengthList<Ar> extends true ? Readonly<{
|
|
17
17
|
[K in keyof Ar]: Ar[K] | V;
|
|
18
|
-
}> : Ar extends
|
|
18
|
+
}> : Ar extends NonEmptyTuple<unknown> ? NonEmptyArray<Ar[number] | V> : readonly (Ar[number] | V)[];
|
|
19
19
|
export declare function set<const V>(index: SizeType.ArgArr, newValue: V): <const Ar extends readonly unknown[]>(array: Ar) => IsFixedLengthList<Ar> extends true ? Readonly<{
|
|
20
20
|
[K in keyof Ar]: Ar[K] | V;
|
|
21
|
-
}> : Ar extends
|
|
21
|
+
}> : Ar extends NonEmptyTuple<unknown> ? NonEmptyArray<Ar[number] | V> : readonly (Ar[number] | V)[];
|
|
22
22
|
/**
|
|
23
23
|
* Returns a new array with an element at the specified index updated by applying a function.
|
|
24
24
|
*
|
|
@@ -41,10 +41,10 @@ export declare function set<const V>(index: SizeType.ArgArr, newValue: V): <cons
|
|
|
41
41
|
*/
|
|
42
42
|
export declare function toUpdated<const Ar extends readonly unknown[], const V = Ar[number]>(array: Ar, index: ArgArrayIndex<Ar>, updater: (prev: Ar[number]) => V): IsFixedLengthList<Ar> extends true ? Readonly<{
|
|
43
43
|
[K in keyof Ar]: Ar[K] | V;
|
|
44
|
-
}> : Ar extends
|
|
44
|
+
}> : Ar extends NonEmptyTuple<unknown> ? NonEmptyArray<Ar[number] | V> : readonly (Ar[number] | V)[];
|
|
45
45
|
export declare function toUpdated<E, const V = E>(index: SizeType.ArgArr, updater: (prev: E) => V): <const Ar extends readonly E[]>(array: Ar) => IsFixedLengthList<Ar> extends true ? Readonly<{
|
|
46
46
|
[K in keyof Ar]: Ar[K] | V;
|
|
47
|
-
}> : Ar extends
|
|
47
|
+
}> : Ar extends NonEmptyTuple<unknown> ? NonEmptyArray<Ar[number] | V> : readonly (Ar[number] | V)[];
|
|
48
48
|
/**
|
|
49
49
|
* Returns a new array with a value inserted at the specified index.
|
|
50
50
|
*
|
|
@@ -139,8 +139,8 @@ export declare function toUnshifted<const V>(newValue: V): <const Ar extends rea
|
|
|
139
139
|
* assert.deepStrictEqual(filledCurried, ['x', 'x', 'x']);
|
|
140
140
|
* ```
|
|
141
141
|
*/
|
|
142
|
-
export declare function toFilled<const Ar extends readonly unknown[], const V>(array: Ar, value: V): IsFixedLengthList<Ar> extends true ? FixedLengthTuple<Ar['length'], V> : Ar extends
|
|
143
|
-
export declare function toFilled<const V>(value: V): <const Ar extends readonly unknown[]>(array: Ar) => IsFixedLengthList<Ar> extends true ? FixedLengthTuple<Ar['length'], V> : Ar extends
|
|
142
|
+
export declare function toFilled<const Ar extends readonly unknown[], const V>(array: Ar, value: V): IsFixedLengthList<Ar> extends true ? FixedLengthTuple<Ar['length'], V> : Ar extends NonEmptyTuple<unknown> ? NonEmptyArray<V> : readonly V[];
|
|
143
|
+
export declare function toFilled<const V>(value: V): <const Ar extends readonly unknown[]>(array: Ar) => IsFixedLengthList<Ar> extends true ? FixedLengthTuple<Ar['length'], V> : Ar extends NonEmptyTuple<unknown> ? NonEmptyArray<V> : readonly V[];
|
|
144
144
|
/**
|
|
145
145
|
* Returns a new array with elements in the specified range replaced by the specified value.
|
|
146
146
|
*
|
|
@@ -161,10 +161,10 @@ export declare function toFilled<const V>(value: V): <const Ar extends readonly
|
|
|
161
161
|
export declare function toRangeFilled<const Ar extends readonly unknown[], const V>(array: Ar, value: V, fillRange: readonly [
|
|
162
162
|
start: ArgArrayIndexWithNegative<Ar>,
|
|
163
163
|
end: ArgArrayIndexWithNegative<Ar>
|
|
164
|
-
]): IsFixedLengthList<Ar> extends true ? FixedLengthTuple<Ar['length'], V | Ar[number]> : Ar extends
|
|
164
|
+
]): IsFixedLengthList<Ar> extends true ? FixedLengthTuple<Ar['length'], V | Ar[number]> : Ar extends NonEmptyTuple<unknown> ? NonEmptyArray<V | Ar[number]> : readonly (V | Ar[number])[];
|
|
165
165
|
export declare function toRangeFilled<const V>(value: V, fillRange: readonly [
|
|
166
166
|
start: SizeType.ArgArrWithNegative,
|
|
167
167
|
end: SizeType.ArgArrWithNegative
|
|
168
|
-
]): <const Ar extends readonly unknown[]>(array: Ar) => IsFixedLengthList<Ar> extends true ? FixedLengthTuple<Ar['length'], V | Ar[number]> : Ar extends
|
|
168
|
+
]): <const Ar extends readonly unknown[]>(array: Ar) => IsFixedLengthList<Ar> extends true ? FixedLengthTuple<Ar['length'], V | Ar[number]> : Ar extends NonEmptyTuple<unknown> ? NonEmptyArray<V | Ar[number]> : readonly (V | Ar[number])[];
|
|
169
169
|
export {};
|
|
170
170
|
//# sourceMappingURL=array-utils-modification.d.mts.map
|
|
@@ -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,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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GACA,iBAAiB,CAAC,EAAE,CAAC,SAAS,IAAI,GACjC,gBAAgB,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,GAC9C,EAAE,SAAS,aAAa,CAAC,OAAO,CAAC,GAC/B,aAAa,CAAC,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,GAC7B,SAAS,CAAC,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;AAGlC,wBAAgB,aAAa,CAAC,KAAK,CAAC,CAAC,EACnC,KAAK,EAAE,CAAC,EACR,SAAS,EAAE,SAAS;IAClB,KAAK,EAAE,QAAQ,CAAC,kBAAkB;IAClC,GAAG,EAAE,QAAQ,CAAC,kBAAkB;CACjC,GACA,CAAC,KAAK,CAAC,EAAE,SAAS,SAAS,OAAO,EAAE,EACrC,KAAK,EAAE,EAAE,KACN,iBAAiB,CAAC,EAAE,CAAC,SAAS,IAAI,GACnC,gBAAgB,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,GAC9C,EAAE,SAAS,aAAa,CAAC,OAAO,CAAC,GAC/B,aAAa,CAAC,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,GAC7B,SAAS,CAAC,CAAC,GAAG,EAAE,CAAC,MAAM,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;;;;;;;;;;;;GAY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AAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,GAC9C,EAAE,SAAS,aAAa,CAAC,OAAO,CAAC,GAC/B,aAAa,CAAC,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,GAC7B,SAAS,CAAC,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-utils-modification.mjs","sources":["../../../src/array/impl/array-utils-modification.mts"],"sourcesContent":["import {\n type FixedLengthTuple,\n type Increment,\n type IsFixedLengthList,\n type NonEmptyArray,\n} from 'ts-type-forge';\nimport { asPositiveUint32 } from '../../number/index.mjs';\nimport { castMutable } from '../../others/index.mjs';\nimport {\n type ArgArrayIndex,\n type ArgArrayIndexWithNegative,\n type SizeType,\n} from '../../types.mjs';\nimport { copy, create } from './array-utils-creation.mjs';\n\n/**\n * Returns a new array with an element at the specified index replaced.\n *\n * @example\n *\n * ```ts\n * const scores: readonly number[] = [10, 20, 30] as const;\n *\n * const updated = Arr.set(scores, 1, 25);\n *\n * assert.deepStrictEqual(updated, [10, 25, 30]);\n * ```\n */\nexport function set<const Ar extends readonly unknown[], const V = Ar[number]>(\n array: Ar,\n index: ArgArrayIndex<Ar>,\n newValue: V,\n): IsFixedLengthList<Ar> extends true\n ? Readonly<{ [K in keyof Ar]: Ar[K] | V }>\n : Ar extends NonEmptyArray<unknown>\n ? NonEmptyArray<Ar[number] | V>\n : readonly (Ar[number] | V)[];\n\n// curried version\nexport function set<const V>(\n index: SizeType.ArgArr,\n newValue: V,\n): <const Ar extends readonly unknown[]>(\n array: Ar,\n) => IsFixedLengthList<Ar> extends true\n ? Readonly<{ [K in keyof Ar]: Ar[K] | V }>\n : Ar extends NonEmptyArray<unknown>\n ? NonEmptyArray<Ar[number] | V>\n : readonly (Ar[number] | V)[];\n\nexport function set<E, const V = E>(\n ...args:\n | readonly [array: readonly E[], index: SizeType.ArgArr, newValue: V]\n | readonly [index: SizeType.ArgArr, newValue: V]\n): readonly (E | V)[] | ((array: readonly E[]) => readonly (E | V)[]) {\n switch (args.length) {\n case 3: {\n const [array, index, newValue] = args;\n\n return (array as readonly (E | V)[]).with(index, newValue);\n }\n\n case 2: {\n const [index, newValue] = args;\n\n return (array) => set(array, index, newValue);\n }\n }\n}\n\n/**\n * Returns a new array with an element at the specified index updated by applying a function.\n *\n * @example\n *\n * ```ts\n * const temperatures: readonly number[] = [20, 21, 22] as const;\n *\n * const increased = Arr.toUpdated(temperatures, 1, (value) => value + 5);\n *\n * const incrementLast = Arr.toUpdated<number>(\n * 2,\n * (value) => value + 1,\n * )(temperatures);\n *\n * assert.deepStrictEqual(increased, [20, 26, 22]);\n *\n * assert.deepStrictEqual(incrementLast, [20, 21, 23]);\n * ```\n */\nexport function toUpdated<\n const Ar extends readonly unknown[],\n const V = Ar[number],\n>(\n array: Ar,\n index: ArgArrayIndex<Ar>,\n updater: (prev: Ar[number]) => V,\n): IsFixedLengthList<Ar> extends true\n ? Readonly<{ [K in keyof Ar]: Ar[K] | V }>\n : Ar extends NonEmptyArray<unknown>\n ? NonEmptyArray<Ar[number] | V>\n : readonly (Ar[number] | V)[];\n\n// curried version\nexport function toUpdated<E, const V = E>(\n index: SizeType.ArgArr,\n updater: (prev: E) => V,\n): <const Ar extends readonly E[]>(\n array: Ar,\n) => IsFixedLengthList<Ar> extends true\n ? Readonly<{ [K in keyof Ar]: Ar[K] | V }>\n : Ar extends NonEmptyArray<unknown>\n ? NonEmptyArray<Ar[number] | V>\n : readonly (Ar[number] | V)[];\n\nexport function toUpdated<E, V = E>(\n ...args:\n | readonly [\n array: readonly E[],\n index: SizeType.ArgArr,\n updater: (prev: E) => V,\n ]\n | readonly [index: SizeType.ArgArr, updater: (prev: E) => V]\n): readonly (E | V)[] | ((array: readonly E[]) => readonly (E | V)[]) {\n switch (args.length) {\n case 3: {\n const [array, index, updater] = args;\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return (array as readonly (E | V)[]).with(index, updater(array[index]!));\n }\n\n case 2: {\n const [index, updater] = args;\n\n return (array) => toUpdated(array, index, updater);\n }\n }\n}\n\n/**\n * Returns a new array with a value inserted at the specified index.\n *\n * @example\n *\n * ```ts\n * const numbers = [1, 2, 4] as const;\n *\n * const withThree = Arr.toInserted(numbers, 2, 3);\n *\n * const appendFive = Arr.toInserted(3, 5)(numbers);\n *\n * assert.deepStrictEqual(withThree, [1, 2, 3, 4]);\n *\n * assert.deepStrictEqual(appendFive, [1, 2, 4, 5]);\n * ```\n */\nexport function toInserted<\n const Ar extends readonly unknown[],\n const V = Ar[number],\n>(\n array: Ar,\n index: ArgArrayIndexWithNegative<Ar>,\n newValue: V,\n): IsFixedLengthList<Ar> extends true\n ? FixedLengthTuple<CastToNumber<Increment<Ar['length']>>, Ar[number] | V>\n : NonEmptyArray<Ar[number] | V>;\n\n// curried version\nexport function toInserted<const V>(\n index: SizeType.ArgArrWithNegative,\n newValue: V,\n): <const Ar extends readonly unknown[]>(\n array: Ar,\n) => IsFixedLengthList<Ar> extends true\n ? FixedLengthTuple<CastToNumber<Increment<Ar['length']>>, Ar[number] | V>\n : NonEmptyArray<Ar[number] | V>;\n\nexport function toInserted<E, const V = E>(\n ...args:\n | readonly [\n array: readonly E[],\n index: SizeType.ArgArrWithNegative,\n newValue: V,\n ]\n | readonly [index: SizeType.ArgArrWithNegative, newValue: V]\n): NonEmptyArray<E | V> | ((array: readonly E[]) => NonEmptyArray<E | V>) {\n switch (args.length) {\n case 3: {\n const [array, index, newValue] = args;\n\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n return (array as readonly (E | V)[]).toSpliced(\n index,\n 0,\n newValue,\n ) as unknown as NonEmptyArray<E | V>;\n }\n\n case 2: {\n const [index, newValue] = args;\n\n return (array) => toInserted(array, index, newValue);\n }\n }\n}\n\ntype CastToNumber<T> = T extends number ? T : never;\n\n/**\n * Returns a new array with the element at the specified index removed.\n *\n * @example\n *\n * ```ts\n * const letters = ['a', 'b', 'c', 'd'] as const;\n *\n * const withoutSecond = Arr.toRemoved(letters, 1);\n *\n * const withoutFirstCurried = Arr.toRemoved(0)(letters);\n *\n * assert.deepStrictEqual(withoutSecond, ['a', 'c', 'd']);\n *\n * assert.deepStrictEqual(withoutFirstCurried, ['b', 'c', 'd']);\n * ```\n */\nexport function toRemoved<const Ar extends readonly unknown[]>(\n array: Ar,\n index: ArgArrayIndexWithNegative<Ar>,\n): readonly Ar[number][];\n\nexport function toRemoved(\n index: SizeType.ArgArrWithNegative,\n): <E>(array: readonly E[]) => readonly E[];\n\nexport function toRemoved<E>(\n ...args:\n | readonly [array: readonly E[], index: SizeType.ArgArrWithNegative]\n | readonly [index: SizeType.ArgArrWithNegative]\n): readonly E[] | ((array: readonly E[]) => readonly E[]) {\n switch (args.length) {\n case 2: {\n const [array, index] = args;\n\n return array.toSpliced(index, 1);\n }\n\n case 1: {\n const [index] = args;\n\n return (array) => toRemoved(array, index);\n }\n }\n}\n\n/**\n * Returns a new array with a value appended to the end.\n *\n * @example\n *\n * ```ts\n * const base = [1, 2] as const;\n *\n * const appended = Arr.toPushed(base, 3);\n *\n * const appendedCurried = Arr.toPushed(4)(base);\n *\n * assert.deepStrictEqual(appended, [1, 2, 3]);\n *\n * assert.deepStrictEqual(appendedCurried, [1, 2, 4]);\n * ```\n */\nexport function toPushed<const Ar extends readonly unknown[], const V>(\n array: Ar,\n newValue: V,\n): readonly [...Ar, V];\n\nexport function toPushed<const V>(\n newValue: V,\n): <const Ar extends readonly unknown[]>(array: Ar) => readonly [...Ar, V];\n\nexport function toPushed<const Ar extends readonly unknown[], const V>(\n ...args: readonly [array: Ar, newValue: V] | readonly [newValue: V]\n): readonly [...Ar, V] | ((array: Ar) => readonly [...Ar, V]) {\n switch (args.length) {\n case 2: {\n const [array, newValue] = args;\n\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n return array.toSpliced(array.length, 0, newValue) as unknown as readonly [\n ...Ar,\n V,\n ];\n }\n\n case 1: {\n const [newValue] = args;\n\n return (array) => toPushed(array, newValue);\n }\n }\n}\n\n/**\n * Returns a new array with a value prepended to the beginning.\n *\n * @example\n *\n * ```ts\n * const base = [2, 3] as const;\n *\n * const prefixed = Arr.toUnshifted(base, 1);\n *\n * const prefixedCurried = Arr.toUnshifted(0)(base);\n *\n * assert.deepStrictEqual(prefixed, [1, 2, 3]);\n *\n * assert.deepStrictEqual(prefixedCurried, [0, 2, 3]);\n * ```\n */\nexport function toUnshifted<const Ar extends readonly unknown[], const V>(\n array: Ar,\n newValue: V,\n): readonly [V, ...Ar];\n\nexport function toUnshifted<const V>(\n newValue: V,\n): <const Ar extends readonly unknown[]>(array: Ar) => readonly [V, ...Ar];\n\nexport function toUnshifted<Ar extends readonly unknown[], const V>(\n ...args: readonly [array: Ar, newValue: V] | readonly [newValue: V]\n): readonly [V, ...Ar] | ((array: Ar) => readonly [V, ...Ar]) {\n switch (args.length) {\n case 2: {\n const [array, newValue] = args;\n\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n return array.toSpliced(0, 0, newValue) as unknown as readonly [V, ...Ar];\n }\n\n case 1: {\n const [newValue] = args;\n\n return (array) => toUnshifted(array, newValue);\n }\n }\n}\n\n/**\n * Returns a new array with all elements replaced by the specified value.\n *\n * @example\n *\n * ```ts\n * const base = [1, 2, 3] as const;\n *\n * const filled = Arr.toFilled(base, 0);\n *\n * const filledCurried = Arr.toFilled('x')(base);\n *\n * assert.deepStrictEqual(filled, [0, 0, 0]);\n *\n * assert.deepStrictEqual(filledCurried, ['x', 'x', 'x']);\n * ```\n */\nexport function toFilled<const Ar extends readonly unknown[], const V>(\n array: Ar,\n value: V,\n): IsFixedLengthList<Ar> extends true\n ? FixedLengthTuple<Ar['length'], V>\n : Ar extends NonEmptyArray<unknown>\n ? NonEmptyArray<V>\n : readonly V[];\n\n// curried version\nexport function toFilled<const V>(\n value: V,\n): <const Ar extends readonly unknown[]>(\n array: Ar,\n) => IsFixedLengthList<Ar> extends true\n ? FixedLengthTuple<Ar['length'], V>\n : Ar extends NonEmptyArray<unknown>\n ? NonEmptyArray<V>\n : readonly V[];\n\nexport function toFilled<E>(\n ...args: readonly [array: readonly E[], value: E] | readonly [value: E]\n): readonly E[] | ((array: readonly E[]) => readonly E[]) {\n switch (args.length) {\n case 2: {\n const [array, value] = args;\n\n return create(asPositiveUint32(array.length), value);\n }\n\n case 1: {\n const [value] = args;\n\n return (array) => toFilled(array, value);\n }\n }\n}\n\n/**\n * Returns a new array with elements in the specified range replaced by the specified value.\n *\n * @example\n *\n * ```ts\n * const base = [0, 1, 2, 3, 4] as const;\n *\n * const filledMiddle = Arr.toRangeFilled(base, 9, [1, 4]);\n *\n * const filledPrefix = Arr.toRangeFilled(8, [0, 2])(base);\n *\n * assert.deepStrictEqual(filledMiddle, [0, 9, 9, 9, 4]);\n *\n * assert.deepStrictEqual(filledPrefix, [8, 8, 2, 3, 4]);\n * ```\n */\nexport function toRangeFilled<const Ar extends readonly unknown[], const V>(\n array: Ar,\n value: V,\n fillRange: readonly [\n start: ArgArrayIndexWithNegative<Ar>,\n end: ArgArrayIndexWithNegative<Ar>,\n ],\n): IsFixedLengthList<Ar> extends true\n ? FixedLengthTuple<Ar['length'], V | Ar[number]>\n : Ar extends NonEmptyArray<unknown>\n ? NonEmptyArray<V | Ar[number]>\n : readonly (V | Ar[number])[];\n\n// curried version\nexport function toRangeFilled<const V>(\n value: V,\n fillRange: readonly [\n start: SizeType.ArgArrWithNegative,\n end: SizeType.ArgArrWithNegative,\n ],\n): <const Ar extends readonly unknown[]>(\n array: Ar,\n) => IsFixedLengthList<Ar> extends true\n ? FixedLengthTuple<Ar['length'], V | Ar[number]>\n : Ar extends NonEmptyArray<unknown>\n ? NonEmptyArray<V | Ar[number]>\n : readonly (V | Ar[number])[];\n\nexport function toRangeFilled<E, const V>(\n ...args:\n | readonly [\n array: readonly E[],\n value: V,\n fillRange: readonly [\n start: SizeType.ArgArrWithNegative,\n end: SizeType.ArgArrWithNegative,\n ],\n ]\n | readonly [\n value: V,\n fillRange: readonly [\n start: SizeType.ArgArrWithNegative,\n end: SizeType.ArgArrWithNegative,\n ],\n ]\n): readonly (E | V)[] | ((array: readonly E[]) => readonly (E | V)[]) {\n switch (args.length) {\n case 3: {\n const [array, value, [start, end]] = args;\n\n const mut_cp: (E | V)[] = castMutable(copy(array));\n\n mut_cp.fill(value, start, end);\n\n return mut_cp;\n }\n\n case 2: {\n const [value, fillRange] = args;\n\n return (array) => toRangeFilled(array, value, fillRange);\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDO,SAAS,OACX,IAAA,EAGiE;AACpE,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA,EAAG;AACN,MAAA,MAAM,CAAC,KAAA,EAAO,KAAA,EAAO,QAAQ,CAAA,GAAI,IAAA;AAEjC,MAAA,OAAQ,KAAA,CAA6B,IAAA,CAAK,KAAA,EAAO,QAAQ,CAAA;AAAA,IAC3D;AAAA,IAEA,KAAK,CAAA,EAAG;AACN,MAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAI,IAAA;AAE1B,MAAA,OAAO,CAAC,KAAA,KAAU,GAAA,CAAI,KAAA,EAAO,OAAO,QAAQ,CAAA;AAAA,IAC9C;AAAA;AAEJ;AA+CO,SAAS,aACX,IAAA,EAOiE;AACpE,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA,EAAG;AACN,MAAA,MAAM,CAAC,KAAA,EAAO,KAAA,EAAO,OAAO,CAAA,GAAI,IAAA;AAGhC,MAAA,OAAQ,MAA6B,IAAA,CAAK,KAAA,EAAO,QAAQ,KAAA,CAAM,KAAK,CAAE,CAAC,CAAA;AAAA,IACzE;AAAA,IAEA,KAAK,CAAA,EAAG;AACN,MAAA,MAAM,CAAC,KAAA,EAAO,OAAO,CAAA,GAAI,IAAA;AAEzB,MAAA,OAAO,CAAC,KAAA,KAAU,SAA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CAAK,KAAK,CAAC,CAAA;AAEjD,MAAA,MAAA,CAAO,IAAA,CAAK,KAAA,EAAO,KAAA,EAAO,GAAG,CAAA;AAE7B,MAAA,OAAO,MAAA;AAAA,IACT;AAAA,IAEA,KAAK,CAAA,EAAG;AACN,MAAA,MAAM,CAAC,KAAA,EAAO,SAAS,CAAA,GAAI,IAAA;AAE3B,MAAA,OAAO,CAAC,KAAA,KAAU,aAAA,CAAc,KAAA,EAAO,OAAO,SAAS,CAAA;AAAA,IACzD;AAAA;AAEJ;;;;"}
|
|
1
|
+
{"version":3,"file":"array-utils-modification.mjs","sources":["../../../src/array/impl/array-utils-modification.mts"],"sourcesContent":["import {\n type FixedLengthTuple,\n type Increment,\n type IsFixedLengthList,\n type NonEmptyArray,\n type NonEmptyTuple,\n} from 'ts-type-forge';\nimport { asPositiveUint32 } from '../../number/index.mjs';\nimport { castMutable } from '../../others/index.mjs';\nimport {\n type ArgArrayIndex,\n type ArgArrayIndexWithNegative,\n type SizeType,\n} from '../../types.mjs';\nimport { copy, create } from './array-utils-creation.mjs';\n\n/**\n * Returns a new array with an element at the specified index replaced.\n *\n * @example\n *\n * ```ts\n * const scores: readonly number[] = [10, 20, 30] as const;\n *\n * const updated = Arr.set(scores, 1, 25);\n *\n * assert.deepStrictEqual(updated, [10, 25, 30]);\n * ```\n */\nexport function set<const Ar extends readonly unknown[], const V = Ar[number]>(\n array: Ar,\n index: ArgArrayIndex<Ar>,\n newValue: V,\n): IsFixedLengthList<Ar> extends true\n ? Readonly<{ [K in keyof Ar]: Ar[K] | V }>\n : Ar extends NonEmptyTuple<unknown>\n ? NonEmptyArray<Ar[number] | V>\n : readonly (Ar[number] | V)[];\n\n// curried version\nexport function set<const V>(\n index: SizeType.ArgArr,\n newValue: V,\n): <const Ar extends readonly unknown[]>(\n array: Ar,\n) => IsFixedLengthList<Ar> extends true\n ? Readonly<{ [K in keyof Ar]: Ar[K] | V }>\n : Ar extends NonEmptyTuple<unknown>\n ? NonEmptyArray<Ar[number] | V>\n : readonly (Ar[number] | V)[];\n\nexport function set<E, const V = E>(\n ...args:\n | readonly [array: readonly E[], index: SizeType.ArgArr, newValue: V]\n | readonly [index: SizeType.ArgArr, newValue: V]\n): readonly (E | V)[] | ((array: readonly E[]) => readonly (E | V)[]) {\n switch (args.length) {\n case 3: {\n const [array, index, newValue] = args;\n\n return (array as readonly (E | V)[]).with(index, newValue);\n }\n\n case 2: {\n const [index, newValue] = args;\n\n return (array) => set(array, index, newValue);\n }\n }\n}\n\n/**\n * Returns a new array with an element at the specified index updated by applying a function.\n *\n * @example\n *\n * ```ts\n * const temperatures: readonly number[] = [20, 21, 22] as const;\n *\n * const increased = Arr.toUpdated(temperatures, 1, (value) => value + 5);\n *\n * const incrementLast = Arr.toUpdated<number>(\n * 2,\n * (value) => value + 1,\n * )(temperatures);\n *\n * assert.deepStrictEqual(increased, [20, 26, 22]);\n *\n * assert.deepStrictEqual(incrementLast, [20, 21, 23]);\n * ```\n */\nexport function toUpdated<\n const Ar extends readonly unknown[],\n const V = Ar[number],\n>(\n array: Ar,\n index: ArgArrayIndex<Ar>,\n updater: (prev: Ar[number]) => V,\n): IsFixedLengthList<Ar> extends true\n ? Readonly<{ [K in keyof Ar]: Ar[K] | V }>\n : Ar extends NonEmptyTuple<unknown>\n ? NonEmptyArray<Ar[number] | V>\n : readonly (Ar[number] | V)[];\n\n// curried version\nexport function toUpdated<E, const V = E>(\n index: SizeType.ArgArr,\n updater: (prev: E) => V,\n): <const Ar extends readonly E[]>(\n array: Ar,\n) => IsFixedLengthList<Ar> extends true\n ? Readonly<{ [K in keyof Ar]: Ar[K] | V }>\n : Ar extends NonEmptyTuple<unknown>\n ? NonEmptyArray<Ar[number] | V>\n : readonly (Ar[number] | V)[];\n\nexport function toUpdated<E, V = E>(\n ...args:\n | readonly [\n array: readonly E[],\n index: SizeType.ArgArr,\n updater: (prev: E) => V,\n ]\n | readonly [index: SizeType.ArgArr, updater: (prev: E) => V]\n): readonly (E | V)[] | ((array: readonly E[]) => readonly (E | V)[]) {\n switch (args.length) {\n case 3: {\n const [array, index, updater] = args;\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return (array as readonly (E | V)[]).with(index, updater(array[index]!));\n }\n\n case 2: {\n const [index, updater] = args;\n\n return (array) => toUpdated(array, index, updater);\n }\n }\n}\n\n/**\n * Returns a new array with a value inserted at the specified index.\n *\n * @example\n *\n * ```ts\n * const numbers = [1, 2, 4] as const;\n *\n * const withThree = Arr.toInserted(numbers, 2, 3);\n *\n * const appendFive = Arr.toInserted(3, 5)(numbers);\n *\n * assert.deepStrictEqual(withThree, [1, 2, 3, 4]);\n *\n * assert.deepStrictEqual(appendFive, [1, 2, 4, 5]);\n * ```\n */\nexport function toInserted<\n const Ar extends readonly unknown[],\n const V = Ar[number],\n>(\n array: Ar,\n index: ArgArrayIndexWithNegative<Ar>,\n newValue: V,\n): IsFixedLengthList<Ar> extends true\n ? FixedLengthTuple<CastToNumber<Increment<Ar['length']>>, Ar[number] | V>\n : NonEmptyArray<Ar[number] | V>;\n\n// curried version\nexport function toInserted<const V>(\n index: SizeType.ArgArrWithNegative,\n newValue: V,\n): <const Ar extends readonly unknown[]>(\n array: Ar,\n) => IsFixedLengthList<Ar> extends true\n ? FixedLengthTuple<CastToNumber<Increment<Ar['length']>>, Ar[number] | V>\n : NonEmptyArray<Ar[number] | V>;\n\nexport function toInserted<E, const V = E>(\n ...args:\n | readonly [\n array: readonly E[],\n index: SizeType.ArgArrWithNegative,\n newValue: V,\n ]\n | readonly [index: SizeType.ArgArrWithNegative, newValue: V]\n): NonEmptyArray<E | V> | ((array: readonly E[]) => NonEmptyArray<E | V>) {\n switch (args.length) {\n case 3: {\n const [array, index, newValue] = args;\n\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n return (array as readonly (E | V)[]).toSpliced(\n index,\n 0,\n newValue,\n ) as unknown as NonEmptyArray<E | V>;\n }\n\n case 2: {\n const [index, newValue] = args;\n\n return (array) => toInserted(array, index, newValue);\n }\n }\n}\n\ntype CastToNumber<T> = T extends number ? T : never;\n\n/**\n * Returns a new array with the element at the specified index removed.\n *\n * @example\n *\n * ```ts\n * const letters = ['a', 'b', 'c', 'd'] as const;\n *\n * const withoutSecond = Arr.toRemoved(letters, 1);\n *\n * const withoutFirstCurried = Arr.toRemoved(0)(letters);\n *\n * assert.deepStrictEqual(withoutSecond, ['a', 'c', 'd']);\n *\n * assert.deepStrictEqual(withoutFirstCurried, ['b', 'c', 'd']);\n * ```\n */\nexport function toRemoved<const Ar extends readonly unknown[]>(\n array: Ar,\n index: ArgArrayIndexWithNegative<Ar>,\n): readonly Ar[number][];\n\nexport function toRemoved(\n index: SizeType.ArgArrWithNegative,\n): <E>(array: readonly E[]) => readonly E[];\n\nexport function toRemoved<E>(\n ...args:\n | readonly [array: readonly E[], index: SizeType.ArgArrWithNegative]\n | readonly [index: SizeType.ArgArrWithNegative]\n): readonly E[] | ((array: readonly E[]) => readonly E[]) {\n switch (args.length) {\n case 2: {\n const [array, index] = args;\n\n return array.toSpliced(index, 1);\n }\n\n case 1: {\n const [index] = args;\n\n return (array) => toRemoved(array, index);\n }\n }\n}\n\n/**\n * Returns a new array with a value appended to the end.\n *\n * @example\n *\n * ```ts\n * const base = [1, 2] as const;\n *\n * const appended = Arr.toPushed(base, 3);\n *\n * const appendedCurried = Arr.toPushed(4)(base);\n *\n * assert.deepStrictEqual(appended, [1, 2, 3]);\n *\n * assert.deepStrictEqual(appendedCurried, [1, 2, 4]);\n * ```\n */\nexport function toPushed<const Ar extends readonly unknown[], const V>(\n array: Ar,\n newValue: V,\n): readonly [...Ar, V];\n\nexport function toPushed<const V>(\n newValue: V,\n): <const Ar extends readonly unknown[]>(array: Ar) => readonly [...Ar, V];\n\nexport function toPushed<const Ar extends readonly unknown[], const V>(\n ...args: readonly [array: Ar, newValue: V] | readonly [newValue: V]\n): readonly [...Ar, V] | ((array: Ar) => readonly [...Ar, V]) {\n switch (args.length) {\n case 2: {\n const [array, newValue] = args;\n\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n return array.toSpliced(array.length, 0, newValue) as unknown as readonly [\n ...Ar,\n V,\n ];\n }\n\n case 1: {\n const [newValue] = args;\n\n return (array) => toPushed(array, newValue);\n }\n }\n}\n\n/**\n * Returns a new array with a value prepended to the beginning.\n *\n * @example\n *\n * ```ts\n * const base = [2, 3] as const;\n *\n * const prefixed = Arr.toUnshifted(base, 1);\n *\n * const prefixedCurried = Arr.toUnshifted(0)(base);\n *\n * assert.deepStrictEqual(prefixed, [1, 2, 3]);\n *\n * assert.deepStrictEqual(prefixedCurried, [0, 2, 3]);\n * ```\n */\nexport function toUnshifted<const Ar extends readonly unknown[], const V>(\n array: Ar,\n newValue: V,\n): readonly [V, ...Ar];\n\nexport function toUnshifted<const V>(\n newValue: V,\n): <const Ar extends readonly unknown[]>(array: Ar) => readonly [V, ...Ar];\n\nexport function toUnshifted<Ar extends readonly unknown[], const V>(\n ...args: readonly [array: Ar, newValue: V] | readonly [newValue: V]\n): readonly [V, ...Ar] | ((array: Ar) => readonly [V, ...Ar]) {\n switch (args.length) {\n case 2: {\n const [array, newValue] = args;\n\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n return array.toSpliced(0, 0, newValue) as unknown as readonly [V, ...Ar];\n }\n\n case 1: {\n const [newValue] = args;\n\n return (array) => toUnshifted(array, newValue);\n }\n }\n}\n\n/**\n * Returns a new array with all elements replaced by the specified value.\n *\n * @example\n *\n * ```ts\n * const base = [1, 2, 3] as const;\n *\n * const filled = Arr.toFilled(base, 0);\n *\n * const filledCurried = Arr.toFilled('x')(base);\n *\n * assert.deepStrictEqual(filled, [0, 0, 0]);\n *\n * assert.deepStrictEqual(filledCurried, ['x', 'x', 'x']);\n * ```\n */\nexport function toFilled<const Ar extends readonly unknown[], const V>(\n array: Ar,\n value: V,\n): IsFixedLengthList<Ar> extends true\n ? FixedLengthTuple<Ar['length'], V>\n : Ar extends NonEmptyTuple<unknown>\n ? NonEmptyArray<V>\n : readonly V[];\n\n// curried version\nexport function toFilled<const V>(\n value: V,\n): <const Ar extends readonly unknown[]>(\n array: Ar,\n) => IsFixedLengthList<Ar> extends true\n ? FixedLengthTuple<Ar['length'], V>\n : Ar extends NonEmptyTuple<unknown>\n ? NonEmptyArray<V>\n : readonly V[];\n\nexport function toFilled<E>(\n ...args: readonly [array: readonly E[], value: E] | readonly [value: E]\n): readonly E[] | ((array: readonly E[]) => readonly E[]) {\n switch (args.length) {\n case 2: {\n const [array, value] = args;\n\n return create(asPositiveUint32(array.length), value);\n }\n\n case 1: {\n const [value] = args;\n\n return (array) => toFilled(array, value);\n }\n }\n}\n\n/**\n * Returns a new array with elements in the specified range replaced by the specified value.\n *\n * @example\n *\n * ```ts\n * const base = [0, 1, 2, 3, 4] as const;\n *\n * const filledMiddle = Arr.toRangeFilled(base, 9, [1, 4]);\n *\n * const filledPrefix = Arr.toRangeFilled(8, [0, 2])(base);\n *\n * assert.deepStrictEqual(filledMiddle, [0, 9, 9, 9, 4]);\n *\n * assert.deepStrictEqual(filledPrefix, [8, 8, 2, 3, 4]);\n * ```\n */\nexport function toRangeFilled<const Ar extends readonly unknown[], const V>(\n array: Ar,\n value: V,\n fillRange: readonly [\n start: ArgArrayIndexWithNegative<Ar>,\n end: ArgArrayIndexWithNegative<Ar>,\n ],\n): IsFixedLengthList<Ar> extends true\n ? FixedLengthTuple<Ar['length'], V | Ar[number]>\n : Ar extends NonEmptyTuple<unknown>\n ? NonEmptyArray<V | Ar[number]>\n : readonly (V | Ar[number])[];\n\n// curried version\nexport function toRangeFilled<const V>(\n value: V,\n fillRange: readonly [\n start: SizeType.ArgArrWithNegative,\n end: SizeType.ArgArrWithNegative,\n ],\n): <const Ar extends readonly unknown[]>(\n array: Ar,\n) => IsFixedLengthList<Ar> extends true\n ? FixedLengthTuple<Ar['length'], V | Ar[number]>\n : Ar extends NonEmptyTuple<unknown>\n ? NonEmptyArray<V | Ar[number]>\n : readonly (V | Ar[number])[];\n\nexport function toRangeFilled<E, const V>(\n ...args:\n | readonly [\n array: readonly E[],\n value: V,\n fillRange: readonly [\n start: SizeType.ArgArrWithNegative,\n end: SizeType.ArgArrWithNegative,\n ],\n ]\n | readonly [\n value: V,\n fillRange: readonly [\n start: SizeType.ArgArrWithNegative,\n end: SizeType.ArgArrWithNegative,\n ],\n ]\n): readonly (E | V)[] | ((array: readonly E[]) => readonly (E | V)[]) {\n switch (args.length) {\n case 3: {\n const [array, value, [start, end]] = args;\n\n const mut_cp: (E | V)[] = castMutable(copy(array));\n\n mut_cp.fill(value, start, end);\n\n return mut_cp;\n }\n\n case 2: {\n const [value, fillRange] = args;\n\n return (array) => toRangeFilled(array, value, fillRange);\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDO,SAAS,OACX,IAAA,EAGiE;AACpE,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA,EAAG;AACN,MAAA,MAAM,CAAC,KAAA,EAAO,KAAA,EAAO,QAAQ,CAAA,GAAI,IAAA;AAEjC,MAAA,OAAQ,KAAA,CAA6B,IAAA,CAAK,KAAA,EAAO,QAAQ,CAAA;AAAA,IAC3D;AAAA,IAEA,KAAK,CAAA,EAAG;AACN,MAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAI,IAAA;AAE1B,MAAA,OAAO,CAAC,KAAA,KAAU,GAAA,CAAI,KAAA,EAAO,OAAO,QAAQ,CAAA;AAAA,IAC9C;AAAA;AAEJ;AA+CO,SAAS,aACX,IAAA,EAOiE;AACpE,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA,EAAG;AACN,MAAA,MAAM,CAAC,KAAA,EAAO,KAAA,EAAO,OAAO,CAAA,GAAI,IAAA;AAGhC,MAAA,OAAQ,MAA6B,IAAA,CAAK,KAAA,EAAO,QAAQ,KAAA,CAAM,KAAK,CAAE,CAAC,CAAA;AAAA,IACzE;AAAA,IAEA,K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,EAAO,KAAA,EAAO,CAAC,KAAA,EAAO,GAAG,CAAC,CAAA,GAAI,IAAA;AAErC,MAAA,MAAM,MAAA,GAAoB,WAAA,CAAY,IAAA,CAAK,KAAK,CAAC,CAAA;AAEjD,MAAA,MAAA,CAAO,IAAA,CAAK,KAAA,EAAO,KAAA,EAAO,GAAG,CAAA;AAE7B,MAAA,OAAO,MAAA;AAAA,IACT;AAAA,IAEA,KAAK,CAAA,EAAG;AACN,MAAA,MAAM,CAAC,KAAA,EAAO,SAAS,CAAA,GAAI,IAAA;AAE3B,MAAA,OAAO,CAAC,KAAA,KAAU,aAAA,CAAc,KAAA,EAAO,OAAO,SAAS,CAAA;AAAA,IACzD;AAAA;AAEJ;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Int, type
|
|
1
|
+
import { type Int, type NonEmptyTuple, type Uint } from 'ts-type-forge';
|
|
2
2
|
import { IMap } from '../../collections/index.mjs';
|
|
3
3
|
import { Optional, Result } from '../../functional/index.mjs';
|
|
4
4
|
import { type ArrayIndex, type MapSetKeyType, type SizeType, type Some } from '../../types.mjs';
|
|
@@ -25,8 +25,8 @@ import { type ArrayIndex, type MapSetKeyType, type SizeType, type Some } from '.
|
|
|
25
25
|
* assert.deepStrictEqual(custom, Optional.some(9));
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
|
-
export declare function min<const Ar extends readonly number[]>(array: Ar, comparator?: (x: Ar[number], y: Ar[number]) => number): Ar extends
|
|
29
|
-
export declare function min<const Ar extends readonly unknown[]>(array: Ar, comparator: (x: Ar[number], y: Ar[number]) => number): Ar extends
|
|
28
|
+
export declare function min<const Ar extends readonly number[]>(array: Ar, comparator?: (x: Ar[number], y: Ar[number]) => number): Ar extends NonEmptyTuple<unknown> ? Some<Ar[number]> : Optional<Ar[number]>;
|
|
29
|
+
export declare function min<const Ar extends readonly unknown[]>(array: Ar, comparator: (x: Ar[number], y: Ar[number]) => number): Ar extends NonEmptyTuple<unknown> ? Some<Ar[number]> : Optional<Ar[number]>;
|
|
30
30
|
/**
|
|
31
31
|
* Finds the maximum value in an array.
|
|
32
32
|
*
|
|
@@ -44,8 +44,8 @@ export declare function min<const Ar extends readonly unknown[]>(array: Ar, comp
|
|
|
44
44
|
* assert.deepStrictEqual(reversed, Optional.some(3));
|
|
45
45
|
* ```
|
|
46
46
|
*/
|
|
47
|
-
export declare function max<const Ar extends readonly number[]>(array: Ar, comparator?: (x: Ar[number], y: Ar[number]) => number): Ar extends
|
|
48
|
-
export declare function max<const Ar extends readonly unknown[]>(array: Ar, comparator: (x: Ar[number], y: Ar[number]) => number): Ar extends
|
|
47
|
+
export declare function max<const Ar extends readonly number[]>(array: Ar, comparator?: (x: Ar[number], y: Ar[number]) => number): Ar extends NonEmptyTuple<unknown> ? Some<Ar[number]> : Optional<Ar[number]>;
|
|
48
|
+
export declare function max<const Ar extends readonly unknown[]>(array: Ar, comparator: (x: Ar[number], y: Ar[number]) => number): Ar extends NonEmptyTuple<unknown> ? Some<Ar[number]> : Optional<Ar[number]>;
|
|
49
49
|
/**
|
|
50
50
|
* Finds the element with the minimum mapped value.
|
|
51
51
|
*
|
|
@@ -71,8 +71,8 @@ export declare function max<const Ar extends readonly unknown[]>(array: Ar, comp
|
|
|
71
71
|
* assert.deepStrictEqual(custom, Optional.some({ id: 1, visits: 10 }));
|
|
72
72
|
* ```
|
|
73
73
|
*/
|
|
74
|
-
export declare function minBy<const Ar extends readonly unknown[]>(array: Ar, comparatorValueMapper: (value: Ar[number]) => number): Ar extends
|
|
75
|
-
export declare function minBy<const Ar extends readonly unknown[], V>(array: Ar, comparatorValueMapper: (value: Ar[number]) => V, comparator: (x: V, y: V) => number): Ar extends
|
|
74
|
+
export declare function minBy<const Ar extends readonly unknown[]>(array: Ar, comparatorValueMapper: (value: Ar[number]) => number): Ar extends NonEmptyTuple<unknown> ? Some<Ar[number]> : Optional<Ar[number]>;
|
|
75
|
+
export declare function minBy<const Ar extends readonly unknown[], V>(array: Ar, comparatorValueMapper: (value: Ar[number]) => V, comparator: (x: V, y: V) => number): Ar extends NonEmptyTuple<unknown> ? Some<Ar[number]> : Optional<Ar[number]>;
|
|
76
76
|
/**
|
|
77
77
|
* Finds the element with the maximum mapped value.
|
|
78
78
|
*
|
|
@@ -101,8 +101,8 @@ export declare function minBy<const Ar extends readonly unknown[], V>(array: Ar,
|
|
|
101
101
|
* );
|
|
102
102
|
* ```
|
|
103
103
|
*/
|
|
104
|
-
export declare function maxBy<const Ar extends readonly unknown[]>(array: Ar, comparatorValueMapper: (value: Ar[number]) => number): Ar extends
|
|
105
|
-
export declare function maxBy<const Ar extends readonly unknown[], V>(array: Ar, comparatorValueMapper: (value: Ar[number]) => V, comparator: (x: V, y: V) => number): Ar extends
|
|
104
|
+
export declare function maxBy<const Ar extends readonly unknown[]>(array: Ar, comparatorValueMapper: (value: Ar[number]) => number): Ar extends NonEmptyTuple<unknown> ? Some<Ar[number]> : Optional<Ar[number]>;
|
|
105
|
+
export declare function maxBy<const Ar extends readonly unknown[], V>(array: Ar, comparatorValueMapper: (value: Ar[number]) => V, comparator: (x: V, y: V) => number): Ar extends NonEmptyTuple<unknown> ? Some<Ar[number]> : Optional<Ar[number]>;
|
|
106
106
|
/**
|
|
107
107
|
* Counts the number of elements that satisfy a predicate.
|
|
108
108
|
*
|