Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

typescript-tuple

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typescript-tuple - npm Package Compare versions

Comparing version 3.1.0-rc.0 to 4.0.0-rc.0

.vscode/settings.json

11

index.js
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./lib"), exports);

68

lib/index.d.ts

@@ -11,7 +11,2 @@ import * as utils from './utils';

/**
* Split an infinite tuple into a finite tuple and an array
* @example SplitInfiniteTuple<[0, 1, 2, ...number[]]> → [[0, 1, 2], number[]]
*/
export declare type SplitInfiniteTuple<Tuple extends any[]> = utils.SplitInfiniteTuple<Tuple>;
/**
* Get type of first element

@@ -32,59 +27,2 @@ * @example First<[0, 1, 2]> → 0

/**
* Find index of a type in tuple
* @example FirstIndexEqual<'x', ['a', 'b', 'c', 'x', 'd']> → 3
* @example FirstIndexEqual<'x', ['a', 'b', 'c']> → never
* @example FirstIndexEqual<'x', ['a', 'b', 'c'], 'NotFound'> → 'NotFound'
*/
export declare type FirstIndexEqual<Type, Tuple extends any[], NotFound = never> = utils.FirstIndexEqual<Type, Tuple, NotFound>;
/**
* Find index of the first element in tuple that satifies a type
* @example FirstIndexSubset<string, [true, false, 'x', 3]> → 2
* @example FirstIndexSubset<string, [true, false, 0, 1]> → never
* @example FirstIndexSubset<string, [true, false, 0, 1], 'NotFound'> → 'NotFound'
*/
export declare type FirstIndexSubset<Type, Tuple extends any[], NotFound = never> = utils.FirstIndexSubset<Type, Tuple, NotFound>;
/**
* Find index of the first element in tuple that satifies a type
* @example FirstIndexSuperset<5, [boolean, string, number, object]> → 2
* @example FirstIndexSuperset<5, [boolean, string, object]> → never
* @example FirstIndexSuperset<5, [boolean, string, object], 'NotFound'> → 'NotFound'
*/
export declare type FirstIndexSuperset<Type, Tuple extends any[], NotFound = never> = utils.FirstIndexSuperset<Type, Tuple, NotFound>;
/**
* Find index of a type in tuple
* @example LastIndexEqual<'x', ['a', 'b', 'c', 'x', 'd']> → 3
* @example LastIndexEqual<'x', ['a', 'b', 'c']> → never
* @example LastIndexEqual<'x', ['a', 'b', 'c'], 'NotFound'> → 'NotFound'
*/
export declare type LastIndexEqual<Type, Tuple extends any[], NotFound = never> = utils.LastIndexEqual<Type, Tuple, NotFound>;
/**
* Find index of the first element in tuple that satifies a type
* @example LastIndexSubset<string, [true, false, 'x', 3]> → 2
* @example LastIndexSubset<string, [true, false, 0, 1]> → never
* @example LastIndexSubset<string, [true, false, 0, 1], 'NotFound'> → 'NotFound'
*/
export declare type LastIndexSubset<Type, Tuple extends any[], NotFound = never> = utils.LastIndexSubset<Type, Tuple, NotFound>;
/**
* Find index of the first element in tuple that satifies a type
* @example LastIndexSuperset<5, [boolean, string, number, object]> → 2
* @example LastIndexSuperset<5, [boolean, string, object]> → never
* @example LastIndexSuperset<5, [boolean, string, object], 'NotFound'> → 'NotFound'
*/
export declare type LastIndexSuperset<Type, Tuple extends any[], NotFound = never> = utils.LastIndexSuperset<Type, Tuple, NotFound>;
/**
* Find all indexes of a type in tuple
* @example AllIndexesEqual<'x', ['a', 'b', 'x', 'c', 'x', 'x']> → [2, 4, 5]
*/
export declare type AllIndexesEqual<Type, Tuple extends any[]> = utils._IndexesNormalize<utils._AllIndexesEqual<Type, Tuple>>;
/**
* Find all indexes of a type in tuple
* @example AllIndexesSubset<string, [0, false, 'a', 1, 'b', 'c']> → [2, 4, 5]
*/
export declare type AllIndexesSubset<Type, Tuple extends any[]> = utils._IndexesNormalize<utils._AllIndexesSubset<Type, Tuple>>;
/**
* Find all indexes of a type in tuple
* @example AllIndexesSuperset<'x', [number, boolean, string, 0, 'x', 'a' | 'b']> → [2, 4, 5]
*/
export declare type AllIndexesSuperset<Type, Tuple extends any[]> = utils._IndexesNormalize<utils._AllIndexesSuperset<Type, Tuple>>;
/**
* Add an element to the end of a tuple

@@ -134,8 +72,2 @@ * @example Append<[0, 1, 2], 'new'> → [0, 1, 2, 'new']

/**
* Create a set of tuple of single element
* @example SingleTupleSet<[0, 1, 2]> → [[0], [1], [2]]
* @example SingleTupleSet<[0, 1, 2, ...number[]]> → [[0], [1], [2], ...[number][]]
*/
export declare type SingleTupleSet<Types extends any[]> = utils.SingleTupleSet<Types>;
/**
* Fill a tuple of types

@@ -142,0 +74,0 @@ * @example FillTuple<[0, 1, 2], 'x'> → ['x', 'x', 'x']

54

lib/utils.d.ts

@@ -1,2 +0,1 @@

import { Extends, Equal } from 'typescript-compare';
export declare type IsFinite<Tuple extends any[], Finite, Infinite> = {

@@ -7,3 +6,2 @@ empty: Finite;

}[Tuple extends [] ? 'empty' : Tuple extends (infer Element)[] ? Element[] extends Tuple ? 'infinite' : 'nonEmpty' : never];
export declare type SplitInfiniteTuple<Tuple extends any[]> = _SplitInfiniteTuple<Tuple> extends [infer Finite, infer Infinite] ? Finite extends any[] ? [Reverse<Finite>, Infinite] : never : never;
export declare type _SplitInfiniteTuple<Tuple extends any[], Holder extends any[] = []> = {

@@ -22,38 +20,3 @@ matched: [Holder, Tuple];

export declare type Tail<Tuple extends any[]> = ((...args: Tuple) => any) extends ((_: any, ..._1: infer Rest) => any) ? Rest : never;
export declare type FirstIndexEqual<Type, Tuple extends any[], NotFound = never, Count extends any[] = []> = {
empty: NotFound;
nonEmpty: ((..._: Tuple) => any) extends ((_: infer First, ..._1: infer Rest) => any) ? Equal<First, Type> extends true ? Count['length'] : FirstIndexEqual<Type, Rest, NotFound, Prepend<Count, any>> : never;
infinite: SplitInfiniteTuple<Tuple> extends [infer Finite, infer Infinite] ? Finite extends any[] ? FirstIndexEqual<Type, Finite, Infinite extends Type[] ? Type[] extends Infinite ? Finite['length'] : NotFound : NotFound> : never : never;
}[Tuple extends [] ? 'empty' : IsFinite<Tuple, 'nonEmpty', 'infinite'>];
export declare type FirstIndexSubset<Type, Tuple extends any[], NotFound = never, Count extends any[] = []> = {
empty: NotFound;
nonEmpty: ((..._: Tuple) => any) extends ((_: infer First, ..._1: infer Rest) => any) ? Extends<First, Type> extends true ? Count['length'] : FirstIndexSubset<Type, Rest, NotFound, Prepend<Count, any>> : never;
infinite: SplitInfiniteTuple<Tuple> extends [infer Finite, infer Infinite] ? Finite extends any[] ? FirstIndexSubset<Type, Finite, Infinite extends Type[] ? Finite['length'] : NotFound> : never : never;
}[Tuple extends [] ? 'empty' : IsFinite<Tuple, 'nonEmpty', 'infinite'>];
export declare type FirstIndexSuperset<Type, Tuple extends any[], NotFound = never, Count extends any[] = []> = {
empty: NotFound;
nonEmpty: ((..._: Tuple) => any) extends ((_: infer First, ..._1: infer Rest) => any) ? Extends<Type, First> extends true ? Count['length'] : FirstIndexSuperset<Type, Rest, NotFound, Prepend<Count, any>> : never;
infinite: SplitInfiniteTuple<Tuple> extends [infer Finite, infer Infinite] ? Finite extends any[] ? FirstIndexSuperset<Type, Finite, Extends<Type[], Infinite> extends true ? Finite['length'] : NotFound> : never : never;
}[Tuple extends [] ? 'empty' : IsFinite<Tuple, 'nonEmpty', 'infinite'>];
export declare type LastIndexEqual<Type, Tuple extends any[], NotFound = never> = _LastIndexFirst<_AllIndexesEqual<Type, Tuple>, NotFound>;
export declare type LastIndexSubset<Type, Tuple extends any[], NotFound = never> = _LastIndexFirst<_AllIndexesSubset<Type, Tuple>, NotFound>;
export declare type LastIndexSuperset<Type, Tuple extends any[], NotFound = never> = _LastIndexFirst<_AllIndexesSuperset<Type, Tuple>, NotFound>;
export declare type _LastIndexFirst<Tuple extends any[], NotFound> = IsFinite<Tuple, First<Tuple, NotFound>, SplitInfiniteTuple<Tuple> extends [any, infer Infinite] ? Infinite extends (infer X) ? X : never : never>;
export declare type _IndexesNormalize<Indexes extends any[]> = IsFinite<Indexes, Indexes extends any[] ? Reverse<Indexes> : never, SplitInfiniteTuple<Indexes> extends [infer Finite, infer Infinite] ? Finite extends any[] ? ((..._: Finite) => any) extends ((..._: infer Alt) => any) ? Infinite extends any[] ? Concat<Reverse<Alt>, Infinite> : never : never : never : never>;
export declare type _AllIndexesEqual<Type, Tuple extends any[], Holder extends any[] = [], Count extends any[] = []> = {
empty: Holder;
nonEmpty: ((..._: Tuple) => any) extends ((_: infer First, ..._1: infer Rest) => any) ? Rest extends any[] ? _AllIndexesEqual<Type, Rest, Equal<First, Type> extends true ? Prepend<Holder, Count['length']> : Holder, Prepend<Count, any>> : never : never;
infinite: SplitInfiniteTuple<Tuple> extends [infer Finite, infer Infinite] ? Finite extends any[] ? Infinite extends (infer Last)[] ? _AllIndexesEqual<Type, Finite, Equal<Last, Type> extends true ? Finite['length'][] : []> : never : never : never;
}[Tuple extends [] ? 'empty' : IsFinite<Tuple, 'nonEmpty', 'infinite'>];
export declare type _AllIndexesSubset<Type, Tuple extends any[], Holder extends any[] = [], Count extends any[] = []> = {
empty: Holder;
nonEmpty: ((..._: Tuple) => any) extends ((_: infer First, ..._1: infer Rest) => any) ? Rest extends any[] ? _AllIndexesSubset<Type, Rest, Extends<First, Type> extends true ? Prepend<Holder, Count['length']> : Holder, Prepend<Count, any>> : never : never;
infinite: SplitInfiniteTuple<Tuple> extends [infer Finite, infer Infinite] ? Finite extends any[] ? Infinite extends (infer Last)[] ? _AllIndexesSubset<Type, Finite, Extends<Last, Type> extends true ? Finite['length'][] : []> : never : never : never;
}[Tuple extends [] ? 'empty' : IsFinite<Tuple, 'nonEmpty', 'infinite'>];
export declare type _AllIndexesSuperset<Type, Tuple extends any[], Holder extends any[] = [], Count extends any[] = []> = {
empty: Holder;
nonEmpty: ((..._: Tuple) => any) extends ((_: infer First, ..._1: infer Rest) => any) ? Rest extends any[] ? _AllIndexesSuperset<Type, Rest, Type extends First ? Prepend<Holder, Count['length']> : Holder, Prepend<Count, any>> : never : never;
infinite: SplitInfiniteTuple<Tuple> extends [infer Finite, infer Infinite] ? Finite extends any[] ? Infinite extends (infer Last)[] ? _AllIndexesSuperset<Type, Finite, Type extends Last ? Finite['length'][] : []> : never : never : never;
}[Tuple extends [] ? 'empty' : IsFinite<Tuple, 'nonEmpty', 'infinite'>];
export declare type Prepend<Tuple extends any[], Addend> = ((_: Addend, ..._1: Tuple) => any) extends ((..._: infer Result) => any) ? Result : never;
export declare type Prepend<Tuple extends any[], Addend> = [Addend, ...Tuple];
export declare type Reverse<Tuple extends any[], Prefix extends any[] = []> = {

@@ -67,11 +30,3 @@ empty: Prefix;

}[Tuple extends [any, ...any[]] ? IsFinite<Tuple, 'nonEmpty', 'infinite'> : 'empty'];
export declare 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;
infiniteLeft: {
ERROR: 'Left is not finite';
CODENAME: 'InfiniteLeft' & 'Infinite';
};
}[Left extends [] ? 'emptyLeft' : Left extends [any] ? 'singleLeft' : IsFinite<Left, 'multiLeft', 'infiniteLeft'>];
export declare type Concat<Left extends any[], Right extends any[]> = [...Left, ...Right];
export declare type Repeat<Type, Count extends number, Holder extends any[] = []> = Count extends never ? never : number extends Count ? Type[] : {

@@ -99,7 +54,2 @@ fit: Holder;

}[Tuple extends [] ? 'end' : Quantity extends Holder['length'] ? 'end' : Start extends Count['length'] ? 'start' : 'before'];
export declare type SingleTupleSet<Types extends any[], Holder extends [any][] = []> = {
empty: Holder;
nonEmpty: ((..._: Reverse<Types>) => any) extends ((_: infer Last, ..._1: infer ReversedRest) => any) ? SingleTupleSet<Reverse<ReversedRest>, Prepend<Holder, [Last]>> : never;
infinite: SplitInfiniteTuple<Types> extends [infer Finite, infer Infinite] ? Finite extends any[] ? Infinite extends Array<infer RepeatedElement> ? SingleTupleSet<Finite, [RepeatedElement][]> : never : never : never;
}[Types extends [] ? 'empty' : IsFinite<Types, 'nonEmpty', 'infinite'>];
export declare type FillTuple<Tuple extends any[], Replacement, Holder extends any[] = []> = {

@@ -106,0 +56,0 @@ empty: Holder;

{
"name": "typescript-tuple",
"version": "3.1.0-rc.0",
"version": "4.0.0-rc.0",
"description": "Generics to work with tuples in TypeScript",

@@ -35,9 +35,9 @@ "main": "index.js",

"devDependencies": {
"typescript": "~3.1.1",
"tslint": "^5.11.0",
"tslint-config-standard": "^8.0.1",
"static-type-assert": "^3.0.0",
"toolcheck": "^0.0.5",
"clean-typescript-build": "^0.1.0"
"typescript": "~4.0.2",
"tslint": "^6.1.3",
"tslint-config-standard": "^9.0.0",
"static-type-assert": "^4.0.0",
"toolcheck": "^0.1.4",
"clean-typescript-build": "^0.1.5"
}
}

@@ -26,14 +26,2 @@ # TypeScript Tuple

### `SplitInfiniteTuple`
```typescript
import { SplitInfiniteTuple } from 'typescript-tuple'
type Foo = SplitInfiniteTuple<[0, 1, 2, ...number[]]> // Expect: [[0, 1, 2], number[]]
type FinitePart = Foo[0] // Expect: [0, 1, 2]
type InfinitePart = Foo[1] // Expect: number[]
const foo: Foo = [[0, 1, 2], Array<number>()]
const finitePart: FinitePart = [0, 1, 2]
const infinitePart: InfinitePart = Array<number>()
```
### `First`

@@ -63,122 +51,2 @@

### `FirstIndexEqual`
```typescript
import { FirstIndexEqual } from 'typescript-tuple'
type Foo = FirstIndexEqual<'x', ['a', 'x', 'b', 'x']> // Expect: 1
const foo: Foo = 1
type Bar = FirstIndexEqual<'x', ['a', 'b']> // Expect: never
type Baz = FirstIndexEqual<'x', ['a', 'b'], 'not found'> // Expect: 'not found'
const baz: Baz = 'not found'
```
### `FirstIndexSubset`
```typescript
import { FirstIndexSubset } from 'typescript-tuple'
type Foo = FirstIndexSubset<string, [0, 'a', 1, 'b']> // Expect: 1
const foo: Foo = 1
type Bar = FirstIndexSubset<string, [0, 1]> // Expect: never
type Baz = FirstIndexSubset<string, [0, 1], 'not found'> // Expect: 'not found'
const baz: Baz = 'not found'
```
### `FirstIndexSuperset`
```typescript
import { FirstIndexSuperset } from 'typescript-tuple'
type Foo = FirstIndexSuperset<'x', [number, string, 0 | 1, 'x' | 'y']> // Expect: 1
const foo: Foo = 1
type Bar = FirstIndexSuperset<'x', [number, 0 | 1]> // Expect: never
type Baz = FirstIndexSuperset<'x', [number, 0 | 1], 'not found'> // Expect: 'not found'
const baz: Baz = 'not found'
```
### `LastIndexEqual`
```typescript
import { LastIndexEqual } from 'typescript-tuple'
type Foo = LastIndexEqual<'x', ['a', 'x', 'b', 'x']> // Expect: 3
const foo: Foo = 3
type Bar = LastIndexEqual<'x', ['a', 'b']> // Expect: never
type Baz = LastIndexEqual<'x', ['a', 'b'], 'not found'> // Expect: 'not found'
const baz: Baz = 'not found'
```
### `LastIndexSubset`
```typescript
import { LastIndexSubset } from 'typescript-tuple'
type Foo = LastIndexSubset<string, [0, 'a', 1, 'b']> // Expect: 3
const foo: Foo = 3
type Bar = LastIndexSubset<string, [0, 1]> // Expect: never
type Baz = LastIndexSubset<string, [0, 1], 'not found'> // Expect: 'not found'
const baz: Baz = 'not found'
```
### `LastIndexSuperset`
```typescript
import { LastIndexSuperset } from 'typescript-tuple'
type Foo = LastIndexSuperset<'x', [number, string, 0 | 1, 'x' | 'y']> // Expect: 3
const foo: Foo = 3
type Bar = LastIndexSuperset<'x', [number, 0 | 1]> // Expect: never
type Baz = LastIndexSuperset<'x', [number, 0 | 1], 'not found'> // Expect: 'not found'
const baz: Baz = 'not found'
```
### `AllIndexesEqual`
```typescript
import { AllIndexesEqual } from 'typescript-tuple'
type Foo = AllIndexesEqual<'x', ['a', 'x', 'b', 'x']> // Expect: [1, 3]
const foo: Foo = [1, 3]
type Bar = AllIndexesEqual<'x', ['a', 'x', 'b', ...'x'[]]> // Expect: [1, ...3[]]
const bar: Bar = [1, 3, 3, 3, 3]
```
### `AllIndexesSubset`
```typescript
import { AllIndexesSubset } from 'typescript-tuple'
type Foo = AllIndexesSubset<string, [0, 'a', 1, 'b']> // Expect: [1, 3]
const foo: Foo = [1, 3]
type Bar = AllIndexesSubset<string, [0, 'a', 1, ...'b'[]]> // Expect: [1, ...3[]]
const bar: Bar = [1, 3, 3, 3, 3]
```
### `AllIndexesSuper`
```typescript
import { AllIndexesSuper } from 'typescript-tuple'
type Foo = AllIndexesSuper<'x', [number, string, 0 | 1, 'x' | 'y']> // Expect: [1, 3]
const foo: Foo = [1, 3]
type Bar = AllIndexesSuper<'x', [number, string, 0 | 1, ...'x'[]]> // Expect: [1, ...3[]]
const bar: Bar = [1, 3, 3, 3, 3]
```
### `Append`

@@ -274,14 +142,2 @@

### `SingleTupleSet`
```typescript
import { SingleTupleSet } from 'typescript-tuple'
type Foo = SingleTupleSet<[0, 1, 2]> // Expect [[0], [1], [2]]
const foo: Foo = [[0], [1], [2]]
type Bar = SingleTupleSet<'x'[]> // Expect ['x'][]
const bar: Bar = Array<['x']>()
```
### `FillTuple`

@@ -288,0 +144,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc