type-plus 7.3.1 → 7.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +130 -156
- package/cjs/any/any_type.d.ts +8 -8
- package/cjs/any/any_type.d.ts.map +1 -1
- package/cjs/array/array.at.d.ts +3 -1
- package/cjs/array/array.at.d.ts.map +1 -1
- package/cjs/array/array.find.d.ts +3 -1
- package/cjs/array/array.find.d.ts.map +1 -1
- package/cjs/array/array.find_last.d.ts +3 -1
- package/cjs/array/array.find_last.d.ts.map +1 -1
- package/cjs/array/array.some.d.ts +1 -1
- package/cjs/array/array.some.d.ts.map +1 -1
- package/cjs/array/{array.concat.d.ts → array_plus.concat.d.ts} +4 -1
- package/cjs/array/array_plus.concat.d.ts.map +1 -0
- package/cjs/array/{array.concat.js → array_plus.concat.js} +1 -1
- package/cjs/array/array_plus.concat.js.map +1 -0
- package/cjs/array/array_plus.d.ts +3 -2
- package/cjs/array/array_plus.d.ts.map +1 -1
- package/cjs/array/array_plus.filter.d.ts +2 -0
- package/cjs/array/array_plus.filter.d.ts.map +1 -0
- package/cjs/array/array_plus.filter.js +3 -0
- package/cjs/array/array_plus.filter.js.map +1 -0
- package/cjs/array/array_plus.pad_start.d.ts +5 -0
- package/cjs/array/array_plus.pad_start.d.ts.map +1 -0
- package/cjs/array/array_plus.pad_start.js +3 -0
- package/cjs/array/array_plus.pad_start.js.map +1 -0
- package/cjs/array/array_type.d.ts +30 -12
- package/cjs/array/array_type.d.ts.map +1 -1
- package/cjs/array/filter.d.ts +24 -4
- package/cjs/array/filter.d.ts.map +1 -1
- package/cjs/array/head.d.ts +18 -1
- package/cjs/array/head.d.ts.map +1 -1
- package/cjs/array/intersect_of_props.d.ts +5 -3
- package/cjs/array/intersect_of_props.d.ts.map +1 -1
- package/cjs/array/last.d.ts +16 -2
- package/cjs/array/last.d.ts.map +1 -1
- package/cjs/array/literal_array.d.ts +5 -0
- package/cjs/array/literal_array.d.ts.map +1 -1
- package/cjs/array/literal_array.js +5 -0
- package/cjs/array/literal_array.js.map +1 -1
- package/cjs/array/pad_start.d.ts +5 -5
- package/cjs/array/pad_start.d.ts.map +1 -1
- package/cjs/array/reduce_while.d.ts +6 -0
- package/cjs/array/reduce_while.d.ts.map +1 -1
- package/cjs/array/reduce_while.js +6 -0
- package/cjs/array/reduce_while.js.map +1 -1
- package/cjs/array/reverse.d.ts +5 -0
- package/cjs/array/reverse.d.ts.map +1 -1
- package/cjs/array/union_of_props.d.ts +1 -1
- package/cjs/array/union_of_props.d.ts.map +1 -1
- package/cjs/functional/compose.d.ts +2 -1
- package/cjs/functional/compose.d.ts.map +1 -1
- package/cjs/functional/compose.js.map +1 -1
- package/cjs/functional/context.d.ts.map +1 -1
- package/cjs/index.d.ts +19 -3
- package/cjs/index.d.ts.map +1 -1
- package/cjs/index.js +9 -3
- package/cjs/index.js.map +1 -1
- package/cjs/math/numeric_struct.d.ts +1 -1
- package/cjs/math/numeric_struct.d.ts.map +1 -1
- package/cjs/mix_types/any_or_never_type.d.ts +1 -1
- package/cjs/nodejs/isNodeError.d.ts.map +1 -1
- package/cjs/nominal/brand.d.ts.map +1 -1
- package/cjs/nominal/flavor.d.ts.map +1 -1
- package/cjs/testing/test_type.d.ts +44 -1
- package/cjs/testing/test_type.d.ts.map +1 -1
- package/cjs/tuple/common_prop_keys.d.ts +29 -0
- package/cjs/tuple/common_prop_keys.d.ts.map +1 -0
- package/cjs/tuple/common_prop_keys.js.map +1 -0
- package/cjs/tuple/create_tuple.d.ts.map +1 -1
- package/cjs/tuple/drop.d.ts +72 -0
- package/cjs/tuple/drop.d.ts.map +1 -0
- package/cjs/{array → tuple}/drop.js +3 -1
- package/cjs/tuple/drop.js.map +1 -0
- package/{esm/array → cjs/tuple}/tail.d.ts +1 -1
- package/cjs/{array → tuple}/tail.d.ts.map +1 -1
- package/cjs/{array → tuple}/tail.js.map +1 -1
- package/cjs/tuple/tuple_plus.d.ts +2 -1
- package/cjs/tuple/tuple_plus.d.ts.map +1 -1
- package/cjs/tuple/tuple_plus.filter.d.ts +13 -0
- package/cjs/tuple/tuple_plus.filter.d.ts.map +1 -0
- package/cjs/tuple/tuple_plus.filter.js +3 -0
- package/cjs/tuple/tuple_plus.filter.js.map +1 -0
- package/cjs/tuple/tuple_plus.js +0 -15
- package/cjs/tuple/tuple_plus.js.map +1 -1
- package/cjs/tuple/tuple_plus.pad_start.d.ts +8 -3
- package/cjs/tuple/tuple_plus.pad_start.d.ts.map +1 -1
- package/esm/any/any_type.d.ts +8 -8
- package/esm/any/any_type.d.ts.map +1 -1
- package/esm/array/array.at.d.ts +3 -1
- package/esm/array/array.at.d.ts.map +1 -1
- package/esm/array/array.find.d.ts +3 -1
- package/esm/array/array.find.d.ts.map +1 -1
- package/esm/array/array.find_last.d.ts +3 -1
- package/esm/array/array.find_last.d.ts.map +1 -1
- package/esm/array/array.some.d.ts +1 -1
- package/esm/array/array.some.d.ts.map +1 -1
- package/esm/array/{array.concat.d.ts → array_plus.concat.d.ts} +4 -1
- package/esm/array/array_plus.concat.d.ts.map +1 -0
- package/esm/array/array_plus.concat.js +2 -0
- package/esm/array/array_plus.concat.js.map +1 -0
- package/esm/array/array_plus.d.ts +3 -2
- package/esm/array/array_plus.d.ts.map +1 -1
- package/esm/array/array_plus.filter.d.ts +2 -0
- package/esm/array/array_plus.filter.d.ts.map +1 -0
- package/esm/array/array_plus.filter.js +2 -0
- package/esm/array/array_plus.filter.js.map +1 -0
- package/esm/array/array_plus.pad_start.d.ts +5 -0
- package/esm/array/array_plus.pad_start.d.ts.map +1 -0
- package/esm/array/array_plus.pad_start.js +2 -0
- package/esm/array/array_plus.pad_start.js.map +1 -0
- package/esm/array/array_type.d.ts +30 -12
- package/esm/array/array_type.d.ts.map +1 -1
- package/esm/array/filter.d.ts +24 -4
- package/esm/array/filter.d.ts.map +1 -1
- package/esm/array/head.d.ts +18 -1
- package/esm/array/head.d.ts.map +1 -1
- package/esm/array/intersect_of_props.d.ts +5 -3
- package/esm/array/intersect_of_props.d.ts.map +1 -1
- package/esm/array/last.d.ts +16 -2
- package/esm/array/last.d.ts.map +1 -1
- package/esm/array/literal_array.d.ts +5 -0
- package/esm/array/literal_array.d.ts.map +1 -1
- package/esm/array/literal_array.js +5 -0
- package/esm/array/literal_array.js.map +1 -1
- package/esm/array/pad_start.d.ts +5 -5
- package/esm/array/pad_start.d.ts.map +1 -1
- package/esm/array/reduce_while.d.ts +6 -0
- package/esm/array/reduce_while.d.ts.map +1 -1
- package/esm/array/reduce_while.js +6 -0
- package/esm/array/reduce_while.js.map +1 -1
- package/esm/array/reverse.d.ts +5 -0
- package/esm/array/reverse.d.ts.map +1 -1
- package/esm/array/union_of_props.d.ts +1 -1
- package/esm/array/union_of_props.d.ts.map +1 -1
- package/esm/functional/compose.d.ts +2 -1
- package/esm/functional/compose.d.ts.map +1 -1
- package/esm/functional/compose.js.map +1 -1
- package/esm/functional/context.d.ts.map +1 -1
- package/esm/index.d.ts +19 -3
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +4 -2
- package/esm/index.js.map +1 -1
- package/esm/math/numeric_struct.d.ts +1 -1
- package/esm/math/numeric_struct.d.ts.map +1 -1
- package/esm/mix_types/any_or_never_type.d.ts +1 -1
- package/esm/nodejs/isNodeError.d.ts.map +1 -1
- package/esm/nominal/brand.d.ts.map +1 -1
- package/esm/nominal/flavor.d.ts.map +1 -1
- package/esm/testing/test_type.d.ts +44 -1
- package/esm/testing/test_type.d.ts.map +1 -1
- package/esm/tuple/common_prop_keys.d.ts +29 -0
- package/esm/tuple/common_prop_keys.d.ts.map +1 -0
- package/esm/tuple/common_prop_keys.js.map +1 -0
- package/esm/tuple/create_tuple.d.ts.map +1 -1
- package/esm/tuple/drop.d.ts +72 -0
- package/esm/tuple/drop.d.ts.map +1 -0
- package/esm/tuple/drop.js +9 -0
- package/esm/tuple/drop.js.map +1 -0
- package/{cjs/array → esm/tuple}/tail.d.ts +1 -1
- package/esm/{array → tuple}/tail.d.ts.map +1 -1
- package/esm/{array → tuple}/tail.js.map +1 -1
- package/esm/tuple/tuple_plus.d.ts +2 -1
- package/esm/tuple/tuple_plus.d.ts.map +1 -1
- package/esm/tuple/tuple_plus.filter.d.ts +13 -0
- package/esm/tuple/tuple_plus.filter.d.ts.map +1 -0
- package/esm/tuple/tuple_plus.filter.js +2 -0
- package/esm/tuple/tuple_plus.filter.js.map +1 -0
- package/esm/tuple/tuple_plus.js +1 -1
- package/esm/tuple/tuple_plus.js.map +1 -1
- package/esm/tuple/tuple_plus.pad_start.d.ts +8 -3
- package/esm/tuple/tuple_plus.pad_start.d.ts.map +1 -1
- package/package.json +12 -9
- package/ts/any/any_type.ts +8 -9
- package/ts/any/readme.md +71 -4
- package/ts/array/array.at.ts +3 -1
- package/ts/array/array.find.ts +3 -1
- package/ts/array/array.find_last.ts +3 -1
- package/ts/array/array.some.ts +1 -1
- package/ts/array/{array.concat.ts → array_plus.concat.ts} +3 -0
- package/ts/array/array_plus.filter.ts +5 -0
- package/ts/array/array_plus.pad_start.ts +13 -0
- package/ts/array/array_plus.ts +3 -2
- package/ts/array/array_type.ts +30 -12
- package/ts/array/filter.ts +27 -22
- package/ts/array/head.ts +18 -1
- package/ts/array/intersect_of_props.ts +7 -3
- package/ts/array/last.ts +16 -2
- package/ts/array/literal_array.ts +5 -0
- package/ts/array/pad_start.ts +6 -10
- package/ts/array/readme.md +181 -16
- package/ts/array/reduce_while.ts +6 -0
- package/ts/array/reverse.ts +5 -0
- package/ts/array/union_of_props.ts +1 -1
- package/ts/assertion/readme.md +3 -3
- package/ts/functional/compose.ts +2 -1
- package/ts/functional/context.ts +1 -1
- package/ts/index.ts +22 -3
- package/ts/math/numeric_struct.ts +9 -9
- package/ts/mix_types/any_or_never_type.ts +1 -1
- package/ts/mix_types/readme.md +7 -1
- package/ts/nodejs/isNodeError.ts +13 -13
- package/ts/nominal/brand.ts +1 -1
- package/ts/nominal/flavor.ts +1 -1
- package/ts/testing/readme.md +30 -0
- package/ts/testing/test_type.ts +90 -47
- package/ts/tuple/common_prop_keys.ts +55 -0
- package/ts/tuple/create_tuple.ts +9 -9
- package/ts/tuple/drop.ts +124 -0
- package/ts/tuple/readme.md +116 -1
- package/ts/{array → tuple}/tail.ts +1 -1
- package/ts/tuple/tuple_plus.filter.ts +29 -0
- package/ts/tuple/tuple_plus.pad_start.ts +26 -13
- package/ts/tuple/tuple_plus.ts +2 -1
- package/cjs/array/array.concat.d.ts.map +0 -1
- package/cjs/array/array.concat.js.map +0 -1
- package/cjs/array/common_prop_keys.d.ts +0 -11
- package/cjs/array/common_prop_keys.d.ts.map +0 -1
- package/cjs/array/common_prop_keys.js.map +0 -1
- package/cjs/array/drop.d.ts +0 -19
- package/cjs/array/drop.d.ts.map +0 -1
- package/cjs/array/drop.js.map +0 -1
- package/cjs/array/index.d.ts +0 -17
- package/cjs/array/index.d.ts.map +0 -1
- package/cjs/array/index.js +0 -33
- package/cjs/array/index.js.map +0 -1
- package/esm/array/array.concat.d.ts.map +0 -1
- package/esm/array/array.concat.js +0 -2
- package/esm/array/array.concat.js.map +0 -1
- package/esm/array/common_prop_keys.d.ts +0 -11
- package/esm/array/common_prop_keys.d.ts.map +0 -1
- package/esm/array/common_prop_keys.js.map +0 -1
- package/esm/array/drop.d.ts +0 -19
- package/esm/array/drop.d.ts.map +0 -1
- package/esm/array/drop.js +0 -7
- package/esm/array/drop.js.map +0 -1
- package/esm/array/index.d.ts +0 -17
- package/esm/array/index.d.ts.map +0 -1
- package/esm/array/index.js +0 -17
- package/esm/array/index.js.map +0 -1
- package/ts/array/common_prop_keys.ts +0 -18
- package/ts/array/drop.ts +0 -71
- package/ts/array/index.ts +0 -16
- /package/cjs/{array → tuple}/common_prop_keys.js +0 -0
- /package/cjs/{array → tuple}/tail.js +0 -0
- /package/esm/{array → tuple}/common_prop_keys.js +0 -0
- /package/esm/{array → tuple}/tail.js +0 -0
package/ts/array/array_plus.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export type { At } from './array.at.js'
|
|
2
|
-
export type { Concat } from './
|
|
2
|
+
export type { Concat } from './array_plus.concat.js'
|
|
3
3
|
export type { Entries } from './array.entries.js'
|
|
4
4
|
export type { FindFirst as Find } from './array.find.js'
|
|
5
5
|
export type { FindLast } from './array.find_last.js'
|
|
6
6
|
export type { Reverse } from './array.reverse.js'
|
|
7
7
|
export type { Some } from './array.some.js'
|
|
8
8
|
export type { IndexAt, IsIndexOutOfBound } from './array_index.js'
|
|
9
|
+
export type { Filter } from './array_plus.filter.js'
|
|
9
10
|
export type { SplitAt } from './array_plus.split_at.js'
|
|
10
|
-
export type { PadStart } from './pad_start.js'
|
|
11
|
+
export type { PadStart } from './array_plus.pad_start.js'
|
package/ts/array/array_type.ts
CHANGED
|
@@ -2,12 +2,17 @@ import type { IsNever } from '../never/never_type.js'
|
|
|
2
2
|
import type { StrictNumberType } from '../number/strict_number_type.js'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* 🌪️ *filter*
|
|
6
6
|
*
|
|
7
|
+
* Filter `T` to ensure it is an array, excluding tuple.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
7
10
|
* ```ts
|
|
8
11
|
* type R = ArrayType<number[]> // number[]
|
|
9
12
|
*
|
|
10
13
|
* type R = ArrayType<[1]> // never
|
|
14
|
+
* type R = ArrayType<number[] | 1> // never
|
|
15
|
+
* type R = ArrayType<number[] & { a: 1 }> // never
|
|
11
16
|
* ```
|
|
12
17
|
*/
|
|
13
18
|
export type ArrayType<T, Then = T, Else = never> = IsNever<
|
|
@@ -17,32 +22,45 @@ export type ArrayType<T, Then = T, Else = never> = IsNever<
|
|
|
17
22
|
>
|
|
18
23
|
|
|
19
24
|
/**
|
|
20
|
-
*
|
|
25
|
+
* 🎭 *validate*
|
|
26
|
+
*
|
|
27
|
+
* Validate that `T` is an array, excluding tuple.
|
|
21
28
|
*
|
|
29
|
+
* @example
|
|
22
30
|
* ```ts
|
|
23
|
-
* type R =
|
|
31
|
+
* type R = IsArray<number[]> // true
|
|
24
32
|
*
|
|
25
|
-
* type R =
|
|
26
|
-
* type R =
|
|
33
|
+
* type R = IsArray<number> // false
|
|
34
|
+
* type R = IsArray<[1]> // false
|
|
27
35
|
* ```
|
|
28
36
|
*/
|
|
29
|
-
export type
|
|
37
|
+
export type IsArray<T, Then = true, Else = false> = ArrayType<T, Then, Else>
|
|
30
38
|
|
|
31
39
|
/**
|
|
32
|
-
*
|
|
40
|
+
* 🌪️ *filter*
|
|
41
|
+
*
|
|
42
|
+
* Filter `T` to ensure it is not an array, excluding tuple.
|
|
33
43
|
*
|
|
44
|
+
* i.e. *tuple* will pass through this filter.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
34
47
|
* ```ts
|
|
35
|
-
* type R =
|
|
48
|
+
* type R = NotArrayType<number[]> // never
|
|
36
49
|
*
|
|
37
|
-
* type R =
|
|
38
|
-
* type R =
|
|
50
|
+
* type R = NotArrayType<number> // number
|
|
51
|
+
* type R = NotArrayType<[1]> // [1]
|
|
39
52
|
* ```
|
|
40
53
|
*/
|
|
41
|
-
export type
|
|
54
|
+
export type NotArrayType<T, Then = T, Else = never> = ArrayType<T, Else, Then>
|
|
42
55
|
|
|
43
56
|
/**
|
|
44
|
-
*
|
|
57
|
+
* 🎭 *validate*
|
|
58
|
+
*
|
|
59
|
+
* Validate that `T` is not an array, excluding tuple.
|
|
60
|
+
*
|
|
61
|
+
* i.e. *tuple* will pass through this filter.
|
|
45
62
|
*
|
|
63
|
+
* @example
|
|
46
64
|
* ```ts
|
|
47
65
|
* type R = IsNotArray<number[]> // false
|
|
48
66
|
*
|
package/ts/array/filter.ts
CHANGED
|
@@ -1,27 +1,32 @@
|
|
|
1
|
+
import type { Filter as FilterTuple } from '../tuple/tuple_plus.filter.js'
|
|
2
|
+
import type { Filter as FilterArray } from './array_plus.filter.js'
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
|
-
*
|
|
5
|
+
* ⚗️ *transform*
|
|
6
|
+
*
|
|
7
|
+
* Filter the array or tuple `A`, keeping entries satisfying `Criteria`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* type R = Filter<[1, 2, '3'], number> // [1, 2]
|
|
12
|
+
* type R = Filter<Array<string | undefined>, string> // string[]
|
|
13
|
+
* ```
|
|
3
14
|
*/
|
|
4
|
-
export type Filter<A extends
|
|
5
|
-
?
|
|
6
|
-
|
|
7
|
-
? A
|
|
8
|
-
: Criteria extends A[0]
|
|
9
|
-
? Array<Criteria>
|
|
10
|
-
: never[]
|
|
11
|
-
: // tuple
|
|
12
|
-
A['length'] extends 0
|
|
13
|
-
? never
|
|
14
|
-
: A extends [infer Head, ...infer Tail]
|
|
15
|
-
? Tail['length'] extends 0
|
|
16
|
-
? Head extends Criteria
|
|
17
|
-
? [Head]
|
|
18
|
-
: never[]
|
|
19
|
-
: Head extends Criteria
|
|
20
|
-
? [Head, ...Filter<Tail, Criteria>]
|
|
21
|
-
: Filter<Tail, Criteria>
|
|
22
|
-
: never
|
|
15
|
+
export type Filter<A extends unknown[], Criteria> = number extends A['length']
|
|
16
|
+
? FilterArray<A, Criteria>
|
|
17
|
+
: FilterTuple<A, Criteria>
|
|
23
18
|
|
|
24
19
|
/**
|
|
25
|
-
*
|
|
20
|
+
* ⚗️ *transform*
|
|
21
|
+
* 👽 *alias*
|
|
22
|
+
*
|
|
23
|
+
* Keeps entries satisfying `Criteria` in array or tuple `A`.
|
|
24
|
+
*
|
|
25
|
+
* @alias of [Filter](./filter.ts)
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* type R = KeepMatch<[1, 2, 3], number> // [1, 2]
|
|
29
|
+
* type R = KeepMatch<Array<string|undefined>, string> // string[]
|
|
30
|
+
* ```
|
|
26
31
|
*/
|
|
27
|
-
export type KeepMatch<A extends
|
|
32
|
+
export type KeepMatch<A extends unknown[], Criteria> = Filter<A, Criteria>
|
package/ts/array/head.ts
CHANGED
|
@@ -1 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 🦴 *utilities*
|
|
3
|
+
*
|
|
4
|
+
* Gets the first entry in the tuple or the type of array.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* type R = Head<[1, 2, 3]> // 1
|
|
9
|
+
* type R = Head<string[]> // string
|
|
10
|
+
*
|
|
11
|
+
* type R = Head<[]> // never
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export type Head<T extends any[], Cases extends {
|
|
15
|
+
empty_tuple?: unknown
|
|
16
|
+
} = {
|
|
17
|
+
empty_tuple: never
|
|
18
|
+
}> = T['length'] extends 0 ? Cases['empty_tuple'] : T[0]
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import type { KeyTypes } from '../object/index.js'
|
|
2
|
-
import type { Tail } from '
|
|
2
|
+
import type { Tail } from '../tuple/tail.js'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* 🦴 *utilities*
|
|
6
|
+
*
|
|
7
|
+
* Gets the intersect of properties of the elements in `A`.
|
|
6
8
|
*/
|
|
7
|
-
export type IntersectOfProps<A extends Record<any, unknown>[], P extends KeyTypes> = A['length']
|
|
9
|
+
export type IntersectOfProps<A extends Record<any, unknown>[], P extends KeyTypes> = number extends A['length']
|
|
10
|
+
? A[0][P]
|
|
11
|
+
: A['length'] extends 0
|
|
8
12
|
? never
|
|
9
13
|
: A['length'] extends 1
|
|
10
14
|
? A[0][P]
|
package/ts/array/last.ts
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 🦴 *utilities*
|
|
3
|
+
*
|
|
4
|
+
* Gets the last entry in the tuple or the type of array.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* type R = Last<[1, 2, 3]> // 3
|
|
9
|
+
* type R = Last<string[]> // string
|
|
10
|
+
*
|
|
11
|
+
* type R = Last<[]> // never
|
|
12
|
+
* ```
|
|
3
13
|
*/
|
|
4
|
-
export type Last<T extends
|
|
14
|
+
export type Last<T extends unknown[], Cases extends {
|
|
15
|
+
empty_tuple?: unknown
|
|
16
|
+
} = {
|
|
17
|
+
empty_tuple: never
|
|
18
|
+
}> = T['length'] extends 0 ? Cases['empty_tuple'] : T extends [...unknown[], infer R] ? R : T[0]
|
package/ts/array/pad_start.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type { PadStart as TuplePadStart } from '../tuple/tuple_plus.pad_start.js'
|
|
4
|
-
import type { UnionOfValues } from './union_of_values.js'
|
|
1
|
+
import type { PadStart as PadStartTuple } from '../tuple/tuple_plus.pad_start.js'
|
|
2
|
+
import type { PadStart as PadStartArray } from './array_plus.pad_start.js'
|
|
5
3
|
|
|
6
4
|
/**
|
|
7
5
|
* Pads the start of an array or tuple with `PadWith`.
|
|
8
6
|
*
|
|
7
|
+
* ⚗️ *transform*
|
|
8
|
+
*
|
|
9
9
|
* @example
|
|
10
10
|
* ```ts
|
|
11
11
|
* // Padding array
|
|
@@ -30,12 +30,8 @@ export type PadStart<
|
|
|
30
30
|
MaxLength extends number,
|
|
31
31
|
PadWith = unknown
|
|
32
32
|
> = number extends A['length']
|
|
33
|
-
? MaxLength
|
|
34
|
-
|
|
35
|
-
: CanAssign<PadWith, UnionOfValues<A>> extends true
|
|
36
|
-
? A
|
|
37
|
-
: PadStart<[...CreateTuple<MaxLength, PadWith>, ...A], MaxLength, PadWith>
|
|
38
|
-
: TuplePadStart<A, MaxLength, PadWith>
|
|
33
|
+
? PadStartArray<A, MaxLength, PadWith>
|
|
34
|
+
: PadStartTuple<A, MaxLength, PadWith>
|
|
39
35
|
|
|
40
36
|
/**
|
|
41
37
|
* @deprecated use PadStart instead
|
package/ts/array/readme.md
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
# Array
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
In TypeScript, the type of an JavaScript array can be an [array](#array) or a [tuple](../tuple/readme.md).
|
|
4
|
+
|
|
5
|
+
`Array<T>` or `T[]` is a type that represents an array of `T`
|
|
6
|
+
|
|
7
|
+
There is no length limitation to an `Array`,
|
|
8
|
+
and each element has the same type `T`.
|
|
4
9
|
|
|
5
10
|
## Type Checking
|
|
6
11
|
|
|
@@ -9,6 +14,14 @@ The `ArrayType<T>` and friends are used to check if a type is exactly `Array<T>`
|
|
|
9
14
|
They are strict type checks, meaning they match only the type `Array<T>`,
|
|
10
15
|
and not [tuple], union, or intersection types.
|
|
11
16
|
|
|
17
|
+
### [ArrayType](./array_type.ts#18)
|
|
18
|
+
|
|
19
|
+
`ArrayType<T, Then = T, Else = never>`
|
|
20
|
+
|
|
21
|
+
🌪️ *filter*
|
|
22
|
+
|
|
23
|
+
Filter `T` to ensure it is an array, excluding tuple.
|
|
24
|
+
|
|
12
25
|
```ts
|
|
13
26
|
import type { ArrayType } from 'type-plus'
|
|
14
27
|
|
|
@@ -19,25 +32,64 @@ type R = ArrayType<number[] | 1> // never
|
|
|
19
32
|
type R = ArrayType<number[] & { a: 1 }> // never
|
|
20
33
|
```
|
|
21
34
|
|
|
22
|
-
|
|
23
|
-
- [`IsArray<T, Then = true, Else = false`](array_type.ts#L33): is `T` an array and not a tuple.
|
|
24
|
-
- [`NotArrayType<T, Then = T, Else = never>`](array_type.ts#L47): check if `T` is not an array (can be a tuple).
|
|
25
|
-
- [`IsNotArray<T, Then = true, Else = false>`](array_type.ts#L61): is `T` not an array (can be a tuple).
|
|
35
|
+
### [IsArray](./array_type.ts#37)
|
|
26
36
|
|
|
27
|
-
|
|
37
|
+
`IsArray<T, Then = true, Else = false>`
|
|
28
38
|
|
|
29
|
-
|
|
30
|
-
Whenever possible, these types and type utilities also work with *tuples*,
|
|
31
|
-
as *tuples* is a subset of array.
|
|
39
|
+
🎭 *validate*
|
|
32
40
|
|
|
33
|
-
|
|
34
|
-
please check [`TuplePlus`](../tuple/readme.md#TuplePlus).
|
|
41
|
+
Validate that `T` is an array, excluding tuple.
|
|
35
42
|
|
|
36
|
-
|
|
43
|
+
```ts
|
|
44
|
+
import type { IsArray } from 'type-plus'
|
|
45
|
+
|
|
46
|
+
type R = IsArray<number[]> // true
|
|
47
|
+
|
|
48
|
+
type R = IsArray<number> // false
|
|
49
|
+
type R = IsArray<[1]> // false
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### [NotArrayType](./array_type.ts#54)
|
|
53
|
+
|
|
54
|
+
`NotArrayType<T, Then = T, Else = never>`
|
|
55
|
+
|
|
56
|
+
🌪️ *filter*
|
|
57
|
+
|
|
58
|
+
Filter `T` to ensure it is not an array, excluding tuple.
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import type { NotArrayType } from 'type-plus'
|
|
62
|
+
|
|
63
|
+
type R = NotArrayType<number[]> // never
|
|
64
|
+
|
|
65
|
+
type R = NotArrayType<number> // number
|
|
66
|
+
type R = NotArrayType<[1]> // [1]
|
|
67
|
+
```
|
|
37
68
|
|
|
38
|
-
|
|
69
|
+
### [IsNotArrayType](./array_type.ts#71)
|
|
39
70
|
|
|
40
|
-
|
|
71
|
+
`IsNotArrayType<T, Then = true, Else = false>`
|
|
72
|
+
|
|
73
|
+
🎭 *validate*
|
|
74
|
+
|
|
75
|
+
Validate that `T` is not an array, excluding tuple.
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import type { IsNotArrayType } from 'type-plus'
|
|
79
|
+
|
|
80
|
+
type R = IsNotArrayType<number[]> // false
|
|
81
|
+
|
|
82
|
+
type R = IsNotArrayType<number> // true
|
|
83
|
+
type R = IsNotArrayType<[1]> // true
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## [At](./array.at.ts)
|
|
87
|
+
|
|
88
|
+
`At<A, N, Fail = never>`
|
|
89
|
+
|
|
90
|
+
🦴 *utilities*
|
|
91
|
+
|
|
92
|
+
Gets the type of the array or tuple at positive or negative index `N`.
|
|
41
93
|
|
|
42
94
|
For array, it will return the union of the type of the array value and `undefined`,
|
|
43
95
|
as there is no way to guarantee the array has value at `N`.
|
|
@@ -61,9 +113,12 @@ If the `N` is out of bound,
|
|
|
61
113
|
or `N` is not a valid index,
|
|
62
114
|
`ArrayPlus.At` will return the `Fail` case, which defaults to `never`.
|
|
63
115
|
|
|
64
|
-
|
|
116
|
+
## [`Concat`](./array.concat.ts#L12)
|
|
117
|
+
|
|
118
|
+
`Concat<A, B>`
|
|
65
119
|
|
|
66
|
-
|
|
120
|
+
🦴 *utilities*
|
|
121
|
+
💀 *deprecated* Will be available only as `ArrayPlus.Concat` in the next version
|
|
67
122
|
|
|
68
123
|
Concats two arrays or tuples.
|
|
69
124
|
|
|
@@ -72,6 +127,116 @@ It is added for completeness.
|
|
|
72
127
|
|
|
73
128
|
You are encouraged to use `[...A, ...B]` directly.
|
|
74
129
|
|
|
130
|
+
## [`FindFirst`](./array.find.ts)
|
|
131
|
+
|
|
132
|
+
## [`FineLast`](./array.find_last.ts)
|
|
133
|
+
|
|
134
|
+
## [`Some`](./array.some.ts)
|
|
135
|
+
|
|
136
|
+
## [`Filter`](./filter.ts#l17)
|
|
137
|
+
|
|
138
|
+
`Filter<A, Criteria>`
|
|
139
|
+
|
|
140
|
+
⚗️ *transform*
|
|
141
|
+
|
|
142
|
+
Filter the array or tuple `A`, keeping entries satisfying `Criteria`.
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
import type { Filter } from 'type-plus'
|
|
146
|
+
|
|
147
|
+
type R = Filter<[1, 2, '3'], number> // [1, 2]
|
|
148
|
+
type R = Filter<Array<string | undefined>, string> // string[]
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## [`KeepMatch`](./filter.ts)
|
|
152
|
+
|
|
153
|
+
`KeepMatch<A, Criteria>`
|
|
154
|
+
|
|
155
|
+
⚗️ *transform*
|
|
156
|
+
👽 *alias* of [`Filter`](#filter)
|
|
157
|
+
|
|
158
|
+
Keeps entries satisfying `Criteria` in array or tuple `A`.
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
import type { KeepMatch } from 'type-plus'
|
|
162
|
+
|
|
163
|
+
type R = KeepMatch<[1, 2, '3'], number> // [1, 2]
|
|
164
|
+
type R = KeepMatch<Array<string | undefined>, string> // string[]
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## [`Head`](./head.ts#l14)
|
|
168
|
+
|
|
169
|
+
`Head<T, Cases = { empty_tuple }>`
|
|
170
|
+
|
|
171
|
+
🦴 *utilities*
|
|
172
|
+
|
|
173
|
+
Gets the first entry in the tuple or the type of array.
|
|
174
|
+
|
|
175
|
+
```ts
|
|
176
|
+
import type { Head } from 'type-plus'
|
|
177
|
+
|
|
178
|
+
type R = Head<[1, 2, 3]> // 1
|
|
179
|
+
type R = Head<string[]> // string
|
|
180
|
+
|
|
181
|
+
type R = Head<[]> // never
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## [`IntersectOfProps`](./intersect_of_props.ts)
|
|
185
|
+
|
|
186
|
+
## [`MapToProp`](./intersect_of_props.ts)
|
|
187
|
+
|
|
188
|
+
## [`Last`](./last.ts)
|
|
189
|
+
|
|
190
|
+
`Last<T, Cases = { empty_tuple }>`
|
|
191
|
+
|
|
192
|
+
🦴 *utilities*
|
|
193
|
+
|
|
194
|
+
Gets the last entry in the tuple or the type of array.
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
import type { Last } from 'type-plus'
|
|
198
|
+
|
|
199
|
+
type R = Last<[1, 2, 3]> // 3
|
|
200
|
+
type R = Last<string[]> // string
|
|
201
|
+
|
|
202
|
+
type R = Last<[]> // never
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## [`literalArray`](./literal_array.ts)
|
|
206
|
+
|
|
207
|
+
## [`PadStart`](./pad_start.ts)
|
|
208
|
+
|
|
209
|
+
## [`reduceWhile`](./reduce_while.ts)
|
|
210
|
+
|
|
211
|
+
## [`Reverse`](./reverse.ts)
|
|
212
|
+
|
|
213
|
+
## [`PropUnion`](./union_of_props.ts)
|
|
214
|
+
|
|
215
|
+
## [`UnionOfProps`](./union_of_props.ts)
|
|
216
|
+
|
|
217
|
+
## [`UnionOfValues`](./union_of_values.ts)
|
|
218
|
+
|
|
219
|
+
## ArrayPlus
|
|
220
|
+
|
|
221
|
+
`ArrayPlus` contains all types and type utilities related to array.
|
|
222
|
+
Whenever possible, these types and type utilities also work with *tuples*,
|
|
223
|
+
as *tuples* is a subset of array.
|
|
224
|
+
|
|
225
|
+
For *tuple* specific types and type utilities,
|
|
226
|
+
please check [`TuplePlus`](../tuple/readme.md#TuplePlus).
|
|
227
|
+
|
|
228
|
+
### [`ArrayPlus.At`](./array.at.ts#L18)
|
|
229
|
+
|
|
230
|
+
`ArrayPlus.At<A, N, Fail = never>`
|
|
231
|
+
|
|
232
|
+
Alias of [At](#at).
|
|
233
|
+
|
|
234
|
+
### [`ArrayPlus.Concat`](./array.concat.ts#L12)
|
|
235
|
+
|
|
236
|
+
`ArrayPlus.Concat<A, B>`
|
|
237
|
+
|
|
238
|
+
Alias of [Concat](#concat).
|
|
239
|
+
|
|
75
240
|
### [`ArrayPlus.Entries`](./array.entries.ts#L14)
|
|
76
241
|
|
|
77
242
|
> `ArrayPlus.Entries<A>`
|
package/ts/array/reduce_while.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 🦴 *utilities*
|
|
3
|
+
*
|
|
4
|
+
* `reduce()` with predicate for early termination.
|
|
5
|
+
* A simple version of the same function in the `ramda` package.
|
|
6
|
+
*/
|
|
1
7
|
export function reduceWhile<T, R>(
|
|
2
8
|
predicate: (acc: R, currentValue: T) => boolean,
|
|
3
9
|
callbackfn: (previousValue: R, currentValue: T, currentIndex: number, array: T[]) => R,
|
package/ts/array/reverse.ts
CHANGED
package/ts/assertion/readme.md
CHANGED
|
@@ -9,11 +9,11 @@ They throw an error if the condition is not met, and return nothing otherwise.
|
|
|
9
9
|
These assertion functions are typically used in runtime,
|
|
10
10
|
so that that type of the value can be narrowed down.
|
|
11
11
|
|
|
12
|
-
## assertType
|
|
12
|
+
## [assertType](./assert_type.ts)
|
|
13
13
|
|
|
14
|
-
`assertType<T>(subject)
|
|
14
|
+
`assertType<T>(subject)`
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
💥 `immediate`
|
|
17
17
|
|
|
18
18
|
It ensures `subject` satisfies `T`.
|
|
19
19
|
It is similar to `const x: T = subject` without introducing an unused variable.
|
package/ts/functional/compose.ts
CHANGED
package/ts/functional/context.ts
CHANGED
|
@@ -27,7 +27,7 @@ export type ContextBuilder<Init extends ContextBaseShape, Ctx extends ContextBas
|
|
|
27
27
|
*/
|
|
28
28
|
extend<Additional extends ContextBaseShape = ContextBaseShape>(
|
|
29
29
|
extender: ContextExtender<Ctx, Additional>
|
|
30
|
-
): ContextBuilder<Init, LeftJoin<Ctx, Additional
|
|
30
|
+
): ContextBuilder<Init, LeftJoin<Ctx, Additional>>,
|
|
31
31
|
/**
|
|
32
32
|
* Build and return the context.
|
|
33
33
|
*/
|
package/ts/index.ts
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
export type { AnyType, IsAny, IsNotAny, NotAnyType } from './any/any_type.js'
|
|
2
2
|
export type { At } from './array/array.at.js'
|
|
3
|
-
export type {
|
|
3
|
+
export type { FindFirst } from './array/array.find.js'
|
|
4
|
+
export type { FindLast } from './array/array.find_last.js'
|
|
5
|
+
export type { Some } from './array/array.some.js'
|
|
6
|
+
export type { Concat } from './array/array_plus.concat.js'
|
|
4
7
|
export * as ArrayPlus from './array/array_plus.js'
|
|
5
8
|
export type { ArrayType, IsArray, IsNotArray, NotArrayType } from './array/array_type.js'
|
|
6
|
-
export
|
|
7
|
-
export
|
|
9
|
+
export type { Filter, KeepMatch } from './array/filter.js'
|
|
10
|
+
export type { Head } from './array/head.js'
|
|
11
|
+
export type { IntersectOfProps, MapToProp } from './array/intersect_of_props.js'
|
|
12
|
+
export type { Last } from './array/last.js'
|
|
13
|
+
export { literalArray } from './array/literal_array.js'
|
|
14
|
+
export type { PadStart } from './array/pad_start.js'
|
|
15
|
+
export { reduceWhile } from './array/reduce_while.js'
|
|
16
|
+
export type { Reverse } from './array/reverse.js'
|
|
17
|
+
export type { PropUnion, UnionOfProps } from './array/union_of_props.js'
|
|
18
|
+
export type { UnionOfValues } from './array/union_of_values.js'
|
|
19
|
+
export { assertType } from './assertion/assert_type.js'
|
|
8
20
|
export type { BigintType, IsBigint, IsNotBigint, NotBigintType } from './bigint/bigint_type.js'
|
|
9
21
|
export type { StringToBigint } from './bigint/cast.js'
|
|
10
22
|
export type {
|
|
@@ -82,7 +94,11 @@ export type { IsNotString, IsString, NotStringType, StringType } from './string/
|
|
|
82
94
|
export type { IsNotSymbol, IsSymbol, NotSymbolType, SymbolType } from './symbol/symbol_type.js'
|
|
83
95
|
export * from './testing/stub.js'
|
|
84
96
|
export * from './testing/test_type.js'
|
|
97
|
+
export type { CommonPropKeys } from './tuple/common_prop_keys.js'
|
|
85
98
|
export * from './tuple/create_tuple.js'
|
|
99
|
+
export { drop } from './tuple/drop.js'
|
|
100
|
+
export type { DropFirst, DropLast, DropMatch, DropNull, DropNullable, DropUndefined } from './tuple/drop.js'
|
|
101
|
+
export type { Tail } from './tuple/tail.js'
|
|
86
102
|
export * as TuplePlus from './tuple/tuple_plus.js'
|
|
87
103
|
export type { IsNotTuple, IsTuple, NotTupleType, TupleType } from './tuple/tuple_type.js'
|
|
88
104
|
export * from './type-guard/is_type.js'
|
|
@@ -100,3 +116,6 @@ export * from './unpartial.js'
|
|
|
100
116
|
export * from './utils/index.js'
|
|
101
117
|
export type { IsNotVoid, IsVoid, NotVoidType, VoidType } from './void/void_type.js'
|
|
102
118
|
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Tail } from '../
|
|
1
|
+
import type { Tail } from '../tuple/tail.js'
|
|
2
2
|
import type { PadStart } from '../tuple/tuple_plus.pad_start.js'
|
|
3
3
|
import type { Add as NumericAdd } from './add.js'
|
|
4
4
|
import type { ToNegative } from './math_plus.to_negative.js'
|
|
@@ -631,14 +631,14 @@ export namespace Digit {
|
|
|
631
631
|
][A][B]
|
|
632
632
|
|
|
633
633
|
export type Plus10 = { [k in number]: number } & {
|
|
634
|
-
'-1': 9
|
|
635
|
-
'-2': 8
|
|
636
|
-
'-3': 7
|
|
637
|
-
'-4': 6
|
|
638
|
-
'-5': 5
|
|
639
|
-
'-6': 4
|
|
640
|
-
'-7': 3
|
|
641
|
-
'-8': 2
|
|
634
|
+
'-1': 9,
|
|
635
|
+
'-2': 8,
|
|
636
|
+
'-3': 7,
|
|
637
|
+
'-4': 6,
|
|
638
|
+
'-5': 5,
|
|
639
|
+
'-6': 4,
|
|
640
|
+
'-7': 3,
|
|
641
|
+
'-8': 2,
|
|
642
642
|
'-9': 1
|
|
643
643
|
}
|
|
644
644
|
export type Multiply<A extends number, B extends number> = [
|
package/ts/mix_types/readme.md
CHANGED
|
@@ -6,7 +6,10 @@ This folder contains types and utilities that work across multiple types.
|
|
|
6
6
|
|
|
7
7
|
`AnyOrNeverType<T, Then = T, Else = never>` 🎭 🩳
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Filter `T` to ensure it is either exactly `any` or exactly `never`.
|
|
10
|
+
|
|
11
|
+
🌪️ *filter*
|
|
12
|
+
🩳 *shortcut*
|
|
10
13
|
|
|
11
14
|
```ts
|
|
12
15
|
import type { AnyOrNeverType } from 'type-plus'
|
|
@@ -24,6 +27,9 @@ type R = AnyOrNeverType<unknown, 1, 2> // 2
|
|
|
24
27
|
|
|
25
28
|
Validate if `T` is either exactly `any` or exactly `never`.
|
|
26
29
|
|
|
30
|
+
🎭 *validate*
|
|
31
|
+
🩳 *shortcut*
|
|
32
|
+
|
|
27
33
|
```ts
|
|
28
34
|
import type { IsAnyOrNever } from 'type-plus'
|
|
29
35
|
|