typescript-tuple
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -26,13 +26,19 @@ /** | ||
export declare type Reverse<Tuple extends any[]> = utils.Reverse<Tuple>; | ||
export declare type Concat<Left extends any[], Right extends any[]> = utils.Concat<Left, Right>; | ||
export declare namespace utils { | ||
type Last<Tuple extends any[], Default = never> = { | ||
0: Default; | ||
1: Tuple extends [infer SoleElement] ? SoleElement : never; | ||
2: ((..._: Tuple) => any) extends ((_: any, ..._1: infer Next) => any) ? Last<Next> : Default; | ||
}[Tuple extends [] ? 0 : Tuple extends [any] ? 1 : 2]; | ||
empty: Default; | ||
single: Tuple extends [infer SoleElement] ? SoleElement : never; | ||
multi: ((..._: Tuple) => any) extends ((_: any, ..._1: infer Next) => any) ? Last<Next> : Default; | ||
}[Tuple extends [] ? 'empty' : Tuple extends [any] ? 'single' : 'multi']; | ||
type Prepend<Tuple extends any[], Addend> = ((_: Addend, ..._1: Tuple) => any) extends ((..._: infer Result) => any) ? Result : never; | ||
type Reverse<Tuple extends any[], Prefix extends any[] = []> = { | ||
0: Prefix; | ||
1: ((..._: Tuple) => any) extends ((_: infer First, ..._1: infer Next) => any) ? Reverse<Next, Prepend<Prefix, First>> : never; | ||
}[Tuple extends [any, ...any[]] ? 1 : 0]; | ||
empty: Prefix; | ||
nonEmpty: ((..._: Tuple) => any) extends ((_: infer First, ..._1: infer Next) => any) ? Reverse<Next, Prepend<Prefix, First>> : never; | ||
}[Tuple extends [any, ...any[]] ? 'nonEmpty' : 'empty']; | ||
type Concat<Left extends any[], Right extends any[]> = { | ||
emptyLeft: Right; | ||
singleLeft: Left extends [infer SoleElement] ? Prepend<Right, SoleElement> : never; | ||
multiLeft: ((..._: Reverse<Left>) => any) extends ((_: infer LeftLast, ..._1: infer ReversedLeftRest) => any) ? Concat<Reverse<ReversedLeftRest>, Prepend<Right, LeftLast>> : never; | ||
}[Left extends [] ? 'emptyLeft' : Left extends [any] ? 'singleLeft' : 'multiLeft']; | ||
} |
{ | ||
"name": "typescript-tuple", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Generics to work with tuples in TypeScript", | ||
@@ -27,3 +27,3 @@ "main": "index.js", | ||
"typescript": "^3.0.3", | ||
"static-type-assert": "^0.0.1" | ||
"static-type-assert": "^1.0.0" | ||
}, | ||
@@ -30,0 +30,0 @@ "peerDependencies": { |
@@ -47,8 +47,16 @@ # TypeScript Tuple | ||
import { Reverse } from 'typescript-tuple' | ||
type Foo = Reverse<['a', 'b', 'c'] // Expect: ['c', 'b', 'a'] | ||
type Foo = Reverse<['a', 'b', 'c']> // Expect: ['c', 'b', 'a'] | ||
const foo: Foo = ['c', 'b', 'a'] | ||
``` | ||
### `Concat` | ||
```typescript | ||
import { Concat } from 'typescript-tuple' | ||
type Foo = Concat<['a', 'b', 'c'], [0, 1, 2]> // Expect ['a', 'b', 'c', 0, 1, 2] | ||
const foo: Foo = ['a', 'b', 'c', 0, 1, 2] | ||
``` | ||
## License | ||
[MIT](https://git.io/fA2d9) @ [Hoàng Văn Khải](https://github.com/KSXGitHub) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5389
45
62