type-plus 4.1.0 → 4.2.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 +3 -2
- package/cjs/array/CreateTuple.d.ts +3 -0
- package/cjs/array/Last.d.ts +4 -0
- package/cjs/array/Last.js +3 -0
- package/cjs/array/Last.js.map +1 -0
- package/cjs/array/Tail.d.ts +3 -0
- package/cjs/array/index.d.ts +1 -0
- package/cjs/array/index.js.map +1 -1
- package/cjs/object/split.d.ts +4 -0
- package/cjs/object/split.js.map +1 -1
- package/esm/array/Last.js +2 -0
- package/esm/array/Last.js.map +1 -0
- package/esm/array/index.js.map +1 -1
- package/esm/object/split.js.map +1 -1
- package/package.json +1 -1
- package/ts/array/CreateTuple.ts +10 -7
- package/ts/array/Last.spec.ts +32 -0
- package/ts/array/Last.ts +4 -0
- package/ts/array/Tail.spec.ts +32 -32
- package/ts/array/Tail.ts +10 -7
- package/ts/array/index.ts +1 -0
- package/ts/object/split.ts +4 -0
package/README.md
CHANGED
|
@@ -345,7 +345,7 @@ type No = IsAny<1, 'yes', 'no'> // 'no'
|
|
|
345
345
|
|
|
346
346
|
- `CommonPropKeys<A>`: gets common keys inside the records in the array `A` (deprecate `CommonKeys`).
|
|
347
347
|
- `Concat<A, B>`: `[...A, ...B]`.
|
|
348
|
-
- `CreateTuple<L, T>`:
|
|
348
|
+
- `CreateTuple<L, T>`: Creates `Tuple<T>` with `L` number of elements.
|
|
349
349
|
- `DropFirst<A>`: drops the first value type of `A`.
|
|
350
350
|
- `DropLast<A>`: drops the last value type of `A`.
|
|
351
351
|
- `Filter<A, Criteria>`: gets the array of types satisfying `Criteria` in `A`.
|
|
@@ -354,13 +354,14 @@ type No = IsAny<1, 'yes', 'no'> // 'no'
|
|
|
354
354
|
- `Head<A>`: gets the first entry in the array.
|
|
355
355
|
- `IntersectOfProps<A, K>`: gets the intersect of `A[K]` types (deprecate `MapToProp`)
|
|
356
356
|
- `IsArray<T>`: `logical` predicate for `Array`.
|
|
357
|
+
- `Last<A>`: gets the last type of an array or tuple.
|
|
357
358
|
- `literalArray(...entries)`: return an array whose items are restricted to the provided literals.
|
|
358
359
|
- `PadLeft<A, Total, PadWith>`: pads `A` with `PadWith` if the length of `A` is less than `L`.
|
|
359
360
|
- `reduceWhile()`: `reduce()` with predicate for early termination. \
|
|
360
361
|
A simple version of the same function in the `ramda` package.
|
|
361
362
|
- `Reverse<A>`: reverses the order of `A`.
|
|
362
363
|
- `Some<A, Criteria>`: true if some elements in `A` matches `Criteria`.
|
|
363
|
-
- `Tail<A>`:
|
|
364
|
+
- `Tail<A>`: Gets the types of a tuple except the first entry.
|
|
364
365
|
- `UnionOfProps<A, K>`: gets the union of `A[K]` types (deprecate `PropUnion`).
|
|
365
366
|
- `UnionOfValues<A>`: gets the union of value types in `A` (deprecate `ArrayValue`).
|
|
366
367
|
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { IsPositive } from '../math';
|
|
2
|
+
/**
|
|
3
|
+
* Creates `Tuple<T>` with `L` number of elements.
|
|
4
|
+
*/
|
|
2
5
|
export declare type CreateTuple<L extends number, T = any> = IsPositive<L> extends true ? Device<[], L, T> : never;
|
|
3
6
|
declare type Device<R extends any[], L extends number, T> = R['length'] extends L ? R : Device<[T, ...R], L, T>;
|
|
4
7
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Last.js","sourceRoot":"","sources":["../../ts/array/Last.ts"],"names":[],"mappings":""}
|
package/cjs/array/Tail.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import { UnionOfValues } from './UnionOfValues';
|
|
2
|
+
/**
|
|
3
|
+
* Gets the types of a tuple except the first entry.
|
|
4
|
+
*/
|
|
2
5
|
export declare type Tail<T extends any[]> = T['length'] extends 0 ? never : (T extends [any, ...infer Tail] ? (Tail extends UnionOfValues<T>[] ? Tail : never) : T);
|
package/cjs/array/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export type { FindLast } from './FindLast';
|
|
|
9
9
|
export type { Head } from './Head';
|
|
10
10
|
export type { IntersectOfProps, MapToProp } from './IntersectOfProps';
|
|
11
11
|
export type { IsArray } from './IsArray';
|
|
12
|
+
export type { Last } from './Last';
|
|
12
13
|
export * from './literalArray';
|
|
13
14
|
export type { PadLeft } from './PadLeft';
|
|
14
15
|
export * from './reduceWhile';
|
package/cjs/array/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../ts/array/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../ts/array/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAYA,iDAA8B;AAE9B,gDAA6B"}
|
package/cjs/object/split.d.ts
CHANGED
|
@@ -5,6 +5,10 @@ declare type Splitter<T extends AnyRecord> = Partial<{
|
|
|
5
5
|
declare type Split<T extends AnyRecord, S extends AnyRecord> = {
|
|
6
6
|
[k in keyof S]: NonNullable<T[k]> | S[k];
|
|
7
7
|
};
|
|
8
|
+
/**
|
|
9
|
+
* Split an object into multiple objects.
|
|
10
|
+
* @returns [...entries, remaining]
|
|
11
|
+
*/
|
|
8
12
|
export declare function split<T extends AnyRecord, S1 extends Splitter<T>>(target: T, split1: S1): [
|
|
9
13
|
Split<T, S1>,
|
|
10
14
|
Omit<T, keyof S1>
|
package/cjs/object/split.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"split.js","sourceRoot":"","sources":["../../ts/object/split.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wBAAiD;
|
|
1
|
+
{"version":3,"file":"split.js","sourceRoot":"","sources":["../../ts/object/split.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wBAAiD;AA6LjD,SAAgB,KAAK,CAAC,MAAiB;IAAE,mBAAyB;SAAzB,UAAyB,EAAzB,qBAAyB,EAAzB,IAAyB;QAAzB,kCAAyB;;IAChE,IAAM,MAAM,GAAc,EAAE,CAAA;IAC5B,IAAM,CAAC,GAAG,SAAS,CAAC,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,IAAA,eAAW,EAAC,CAAC,EAAE,UAAC,CAAC,EAAE,CAAC,YAAK,OAAA,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,MAAA,MAAM,CAAC,CAAC,CAAC,mCAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA,EAAA,EAAE,EAAe,CAAC,EAA1F,CAA0F,CAAC,CAAA;IACxH,IAAM,CAAC,GAAG,IAAA,eAAW,EAAC,MAAM,EAAE,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAArC,CAAqC,EAAE,EAAe,CAAC,CAAA;IAC/F,uCAAW,CAAC,UAAE,CAAC,UAAC;AAClB,CAAC;AALD,sBAKC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Last.js","sourceRoot":"","sources":["../../ts/array/Last.ts"],"names":[],"mappings":""}
|
package/esm/array/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../ts/array/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../ts/array/index.ts"],"names":[],"mappings":"AAYA,cAAc,gBAAgB,CAAA;AAE9B,cAAc,eAAe,CAAA"}
|
package/esm/object/split.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"split.js","sourceRoot":"","sources":["../../ts/object/split.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,WAAW,EAAE,MAAM,IAAI,CAAA;
|
|
1
|
+
{"version":3,"file":"split.js","sourceRoot":"","sources":["../../ts/object/split.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,WAAW,EAAE,MAAM,IAAI,CAAA;AA6LjD,MAAM,UAAU,KAAK,CAAC,MAAiB,EAAE,GAAG,SAAsB;IAChE,MAAM,MAAM,GAAc,EAAE,CAAA;IAC5B,MAAM,CAAC,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAe,CAAC,CAAC,CAAA;IACxH,MAAM,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAe,CAAC,CAAA;IAC/F,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAA;AAClB,CAAC"}
|
package/package.json
CHANGED
package/ts/array/CreateTuple.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { IsPositive } from '../math'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
type
|
|
7
|
-
|
|
1
|
+
import { IsPositive } from '../math'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates `Tuple<T>` with `L` number of elements.
|
|
5
|
+
*/
|
|
6
|
+
export type CreateTuple<L extends number, T = any> =
|
|
7
|
+
IsPositive<L> extends true ? Device<[], L, T> : never
|
|
8
|
+
|
|
9
|
+
type Device<R extends any[], L extends number, T> =
|
|
10
|
+
R['length'] extends L ? R : Device<[T, ...R], L, T>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { AnyFunction, isType } from '..'
|
|
2
|
+
import { Last } from './Last'
|
|
3
|
+
|
|
4
|
+
test('any array', () => {
|
|
5
|
+
type A = Last<any[]>
|
|
6
|
+
isType.equal<true, any, A>()
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
test('never array', () => {
|
|
10
|
+
type A = Last<never[]>
|
|
11
|
+
isType.equal<true, never, A>()
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
test('typed array', () => {
|
|
15
|
+
type A = Last<string[]>
|
|
16
|
+
isType.equal<true, string, A>()
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
test('function array', () => {
|
|
20
|
+
type A = Last<AnyFunction[]>
|
|
21
|
+
isType.equal<true, AnyFunction, A>()
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('empty tuple gets undefined', () => {
|
|
25
|
+
type A = Last<[]>
|
|
26
|
+
isType.equal<true, undefined, A>()
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('tuple with function', () => {
|
|
30
|
+
type A = Last<[number, AnyFunction]>
|
|
31
|
+
isType.equal<true, AnyFunction, A>()
|
|
32
|
+
})
|
package/ts/array/Last.ts
ADDED
package/ts/array/Tail.spec.ts
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import { isType, Tail } from '..'
|
|
2
|
-
|
|
3
|
-
test('get tail types', () => {
|
|
4
|
-
type S = [1, 'a', 'b']
|
|
5
|
-
type A = Tail<S>
|
|
6
|
-
|
|
7
|
-
isType.equal<true, ['a', 'b'], A>()
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
test('empty tuple gets never', () => {
|
|
11
|
-
type S = []
|
|
12
|
-
type A = Tail<S>
|
|
13
|
-
|
|
14
|
-
isType.equal<true, never, A>()
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
test('array gets same type', () => {
|
|
18
|
-
type A = Tail<string[]>
|
|
19
|
-
|
|
20
|
-
isType.equal<true, string[], A>()
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
test('union array', () => {
|
|
24
|
-
type A = Tail<Array<string | boolean>>
|
|
25
|
-
|
|
26
|
-
isType.equal<true, Array<string | boolean>, A>()
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
test('tuple with rest', () => {
|
|
30
|
-
type A = Tail<[number, ...string[]]>
|
|
31
|
-
isType.equal<true, string[], A>()
|
|
32
|
-
})
|
|
1
|
+
import { isType, Tail } from '..'
|
|
2
|
+
|
|
3
|
+
test('get tail types', () => {
|
|
4
|
+
type S = [1, 'a', 'b']
|
|
5
|
+
type A = Tail<S>
|
|
6
|
+
|
|
7
|
+
isType.equal<true, ['a', 'b'], A>()
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
test('empty tuple gets never', () => {
|
|
11
|
+
type S = []
|
|
12
|
+
type A = Tail<S>
|
|
13
|
+
|
|
14
|
+
isType.equal<true, never, A>()
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
test('array gets same type', () => {
|
|
18
|
+
type A = Tail<string[]>
|
|
19
|
+
|
|
20
|
+
isType.equal<true, string[], A>()
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
test('union array', () => {
|
|
24
|
+
type A = Tail<Array<string | boolean>>
|
|
25
|
+
|
|
26
|
+
isType.equal<true, Array<string | boolean>, A>()
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('tuple with rest', () => {
|
|
30
|
+
type A = Tail<[number, ...string[]]>
|
|
31
|
+
isType.equal<true, string[], A>()
|
|
32
|
+
})
|
package/ts/array/Tail.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { UnionOfValues } from './UnionOfValues'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { UnionOfValues } from './UnionOfValues'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Gets the types of a tuple except the first entry.
|
|
5
|
+
*/
|
|
6
|
+
export type Tail<T extends any[]> = T['length'] extends 0
|
|
7
|
+
? never
|
|
8
|
+
: (T extends [any, ...infer Tail]
|
|
9
|
+
? (Tail extends UnionOfValues<T>[] ? Tail : never)
|
|
10
|
+
: T)
|
package/ts/array/index.ts
CHANGED
|
@@ -9,6 +9,7 @@ export type { FindLast } from './FindLast'
|
|
|
9
9
|
export type { Head } from './Head'
|
|
10
10
|
export type { IntersectOfProps, MapToProp } from './IntersectOfProps'
|
|
11
11
|
export type { IsArray } from './IsArray'
|
|
12
|
+
export type { Last } from './Last'
|
|
12
13
|
export * from './literalArray'
|
|
13
14
|
export type { PadLeft } from './PadLeft'
|
|
14
15
|
export * from './reduceWhile'
|
package/ts/object/split.ts
CHANGED
|
@@ -3,6 +3,10 @@ import { AnyRecord, Omit, reduceByKey } from '..'
|
|
|
3
3
|
type Splitter<T extends AnyRecord> = Partial<{ [k in keyof T]: T[k] | undefined }>
|
|
4
4
|
type Split<T extends AnyRecord, S extends AnyRecord> = { [k in keyof S]: NonNullable<T[k]> | S[k] }
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Split an object into multiple objects.
|
|
8
|
+
* @returns [...entries, remaining]
|
|
9
|
+
*/
|
|
6
10
|
export function split<
|
|
7
11
|
T extends AnyRecord,
|
|
8
12
|
S1 extends Splitter<T>
|