UNPKG

4.73 kBTypeScriptView Raw
1import * as utils from './utils';
2/**
3 * Choose type base on whether or not a tuple is finite
4 * @example IsFinite<[0, 1, 2]> → true
5 * @example IsFinite<[0, 1, 2, ...number[]]> → false
6 * @example IsFinite<[0], 'Finite', 'Infinite'> → 'Finite'
7 * @example IsFinite<[0, ...number[]], 'Finite', 'Infinite'> → Infinite
8 */
9export declare type IsFinite<Tuple extends any[], Finite = true, Infinite = false> = utils.IsFinite<Tuple, Finite, Infinite>;
10/**
11 * Get type of first element
12 * @example First<[0, 1, 2]> → 0
13 */
14export declare type First<Tuple extends [any, ...any[]]> = Tuple[0];
15/**
16 * Get type of last element
17 * @example Last<[0, 1, 2]> → 2
18 */
19export declare type Last<Tuple extends any[]> = utils.Last<Tuple>;
20/**
21 * Drop the first element
22 * @example Tail<[0, 1, 2, 3]> → [1, 2, 3]
23 */
24export declare type Tail<Tuple extends any[]> = utils.Tail<Tuple>;
25/**
26 * Add an element to the end of a tuple
27 * @example Append<[0, 1, 2], 'new'> → [0, 1, 2, 'new']
28 */
29export declare type Append<Tuple extends any[], Addend> = Reverse<Prepend<Reverse<Tuple>, Addend>>;
30/**
31 * Add an element to the beginning of a tuple
32 * @example Prepend<[0, 1, 2], 'new'> → ['new', 0, 1, 2]
33 */
34export declare type Prepend<Tuple extends any[], Addend> = utils.Prepend<Tuple, Addend>;
35/**
36 * Reverse a tuple
37 * @example Reverse<[0, 1, 2]> → [2, 1, 0]
38 */
39export declare type Reverse<Tuple extends any[]> = utils.Reverse<Tuple>;
40/**
41 * Concat two tuple into one
42 * @example Concat<[0, 1, 2], ['a', 'b', 'c']> → [0, 1, 2, 'a', 'b', 'c']
43 */
44export declare type Concat<Left extends any[], Right extends any[]> = utils.Concat<Left, Right>;
45/**
46 * Repeat a certain type into a tuple
47 * @example Repeat<'foo', 4> → ['foo', 'foo', 'foo', 'foo']
48 * @warning To avoid potential infinite loop, Count must be an integer greater than or equal to 0
49 */
50export declare type Repeat<Type, Count extends number> = utils.Repeat<Type, Count, []>;
51/**
52 * Concat multiple tuples
53 * @example ConcatMultiple<[], [0], [1, 2], [3, 4, 5]> → [0, 1, 2, 3, 4, 5]
54 */
55export declare type ConcatMultiple<TupleSet extends any[][]> = utils.ConcatMultiple<TupleSet>;
56/**
57 * Drop `Quantity` first elements of a tuple
58 * @example Drop<['a', 'b', 'c', 'd', 'e'], 2> → ['c', 'd', 'e']
59 * @example Drop<['a', 'b', 'c', 'd', 'e', ...string[]], 2> → ['c', 'd', 'e', ...string[]]
60 * @example Drop<['a', 'b', 'c', 'd', 'e', ...string[]], 10> → string[]
61 */
62export declare type Drop<Tuple extends any[], Quantity extends number> = utils.Drop<Tuple, Quantity>;
63/**
64 * Slice a tuple
65 * @example SliceStartQuantity<[0, 1, 2, 3, 4, 5, 6], 2, 3> → [2, 3, 4]
66 * @example SliceStartQuantity<[0, 1, 2, 3, 4, 5, 6], 2, 9> → [2, 3, 4, 5, 6]
67 */
68export declare type SliceStartQuantity<Tuple extends any[], Start extends number, Quantity extends number> = utils.SliceStartQuantity<Tuple, Start, Quantity>;
69/**
70 * Fill a tuple of types
71 * @example FillTuple<[0, 1, 2], 'x'> → ['x', 'x', 'x']
72 * @example FillTuple<any[], 'x'> → 'x'[]
73 */
74export declare type FillTuple<Tuple extends any[], Replacement> = utils.FillTuple<Tuple, Replacement>;
75/**
76 * Compare length of two tuple
77 * @example CompareLength<[0, 1, 2], ['a', 'b', 'c']> → 'equal'
78 * @example CompareLength<[0, 1], ['a', 'b', 'c']> → 'shorterLeft'
79 * @example CompareLength<[0, 1, 2], ['a', 'b']> → 'shorterRight'
80 */
81export declare type CompareLength<Left extends any[], Right extends any[]> = utils.CompareLength<Left, Right>;
82/**
83 * Sort two tuples in order of [shorter, longer]
84 * @example SortTwoTuple<[0, 1, 2, 3], ['a', 'b']> → [['a', 'b'], [0, 1, 2, 3]]
85 * @example SortTwoTuple<[0, 1], ['a', 'b', 'c', 'd']> → [[0, 1], ['a', 'b', 'c', 'd']]
86 * @example SortTwoTuple<[0, 1, 2], ['a', 'b', 'c']> → [[0, 1, 2], ['a', 'b', 'c']]
87 * @example SortTwoTuple<[0, 1, 2], ['a', 'b', 'c'], 'EQUAL'> → 'EQUAL'
88 */
89export declare type SortTwoTuple<Left extends any[], Right extends any[], WhenEqual = [Left, Right]> = utils.SortTwoTuple<Left, Right, WhenEqual>;
90/**
91 * Find shortest tuple in a set of tuples
92 * @example ShortestTuple<[[0, 1, 2], [true, false], ['a', 'b', 'c', 'd']]> → [true, false]
93 */
94export declare type ShortestTuple<TupleSet extends [any[], ...any[][]]> = utils.ShortestTuple<TupleSet>;
95/**
96 * Find shortest tuple in a set of tuples
97 * @example LongestTuple<[[0, 1, 2], [true, false], ['a', 'b', 'c', 'd']]> → ['a', 'b', 'c', 'd']
98 */
99export declare type LongestTuple<TupleSet extends [any[], ...any[][]]> = utils.LongestTuple<TupleSet>;
100/**
101 * Filter tuple elements thats match the mask
102 * @example FilterTuple<[1, 2, true, '3'], string | number> → [1, 2, "3"]
103 */
104export declare type FilterTuple<TupleSet extends any[], Mask> = utils.FilterTuple<TupleSet, Mask>;