type-plus 4.3.0 → 4.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 +72 -71
- package/cjs/array/CreateTuple.d.ts +5 -4
- package/cjs/array/Some.d.ts +7 -6
- package/cjs/index.d.ts +1 -0
- package/cjs/index.js +1 -0
- package/cjs/index.js.map +1 -1
- package/cjs/math/Abs.d.ts +1 -1
- package/cjs/math/Add.d.ts +14 -10
- package/cjs/math/Digit.d.ts +7 -9
- package/cjs/math/GreaterThan.d.ts +11 -10
- package/cjs/math/Max.d.ts +10 -9
- package/cjs/math/Subtract.d.ts +11 -10
- package/cjs/math/index.d.ts +1 -0
- package/cjs/nodejs/isNodeError.d.ts +1 -2
- package/cjs/nodejs/isNodeError.js.map +1 -1
- package/cjs/object/split.d.ts +1 -1
- package/cjs/testing/index.d.ts +1 -0
- package/cjs/testing/index.js +18 -0
- package/cjs/testing/index.js.map +1 -0
- package/cjs/testing/stub.d.ts +4 -0
- package/cjs/testing/stub.js +8 -0
- package/cjs/testing/stub.js.map +1 -0
- package/cjs/utils/as.d.ts +2 -2
- package/cjs/utils/as.js +2 -2
- package/cjs/utils/as.js.map +1 -1
- package/esm/index.js +1 -0
- package/esm/index.js.map +1 -1
- package/esm/nodejs/isNodeError.js.map +1 -1
- package/esm/testing/index.js +2 -0
- package/esm/testing/index.js.map +1 -0
- package/esm/testing/stub.js +4 -0
- package/esm/testing/stub.js.map +1 -0
- package/esm/utils/as.js +2 -2
- package/esm/utils/as.js.map +1 -1
- package/package.json +8 -9
- package/ts/array/CreateTuple.ts +6 -4
- package/ts/array/Some.ts +26 -24
- package/ts/index.ts +1 -0
- package/ts/math/Abs.ts +4 -4
- package/ts/math/Add.ts +52 -49
- package/ts/math/Digit.ts +115 -115
- package/ts/math/GreaterThan.ts +38 -36
- package/ts/math/Max.ts +32 -31
- package/ts/math/Subtract.ts +43 -40
- package/ts/math/index.ts +1 -0
- package/ts/nodejs/isNodeError.ts +1 -2
- package/ts/object/run.ts +0 -0
- package/ts/object/split.ts +1 -1
- package/ts/testing/index.ts +1 -0
- package/ts/testing/stub.spec.ts +31 -0
- package/ts/testing/stub.ts +8 -0
- package/ts/utils/as.spec.ts +33 -24
- package/ts/utils/as.ts +7 -7
package/README.md
CHANGED
|
@@ -15,9 +15,10 @@ Provides additional types and type adjusted utilities for [TypeScript](https://w
|
|
|
15
15
|
|
|
16
16
|
## Feature Highlights
|
|
17
17
|
|
|
18
|
-
- [Type
|
|
19
|
-
- [Nominal Types](#nominal-type)
|
|
18
|
+
- [Type assertions](#type-assertions)
|
|
20
19
|
- [Type Utilities](#type-utilities)
|
|
20
|
+
- [Nominal Types](#nominal-types)
|
|
21
|
+
- [Functional Types](#functional-types)
|
|
21
22
|
|
|
22
23
|
## Installation
|
|
23
24
|
|
|
@@ -27,12 +28,11 @@ npm install type-plus
|
|
|
27
28
|
yarn add type-plus
|
|
28
29
|
```
|
|
29
30
|
|
|
30
|
-
## Type
|
|
31
|
+
## Type Assertions
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
`type-plus` also provides a few other ways to do type assertions.
|
|
33
|
+
Type assertion is one of the main features of `type-plus`.
|
|
34
34
|
|
|
35
|
-
There are
|
|
35
|
+
There are 5 kinds of type assertions:
|
|
36
36
|
|
|
37
37
|
- `runtime`: validates during runtime.
|
|
38
38
|
- `immediate`: validates at compile time.
|
|
@@ -264,70 +264,6 @@ assertType.isTrue(notA({ a: 1 }))
|
|
|
264
264
|
notA({ a: '' }) // TypeScript complains
|
|
265
265
|
```
|
|
266
266
|
|
|
267
|
-
## Nominal Type
|
|
268
|
-
|
|
269
|
-
The TypeScript type system is structural.
|
|
270
|
-
|
|
271
|
-
In some cases, we want to express a type with nominal behavior.
|
|
272
|
-
`type-plus` provides two kinds of nominal types: `Brand` and `Flavor`.
|
|
273
|
-
|
|
274
|
-
`Brand<B, T>`:
|
|
275
|
-
|
|
276
|
-
`brand(type, subject?)`:
|
|
277
|
-
|
|
278
|
-
Branded nominal type is the stronger nominal type of the two.
|
|
279
|
-
It disallows unbranded type assigned to it:
|
|
280
|
-
|
|
281
|
-
```ts
|
|
282
|
-
const a = brand('a', { a: 1 })
|
|
283
|
-
const b = { a: 1 }
|
|
284
|
-
a = b // error
|
|
285
|
-
```
|
|
286
|
-
|
|
287
|
-
`subject` can be any type, from primitive to strings to objects.
|
|
288
|
-
|
|
289
|
-
`brand(type)`:
|
|
290
|
-
|
|
291
|
-
If you do not provide `subject`, `brand(type)` will return a brand creator,
|
|
292
|
-
so that you can use it to create multiple branded values:
|
|
293
|
-
|
|
294
|
-
```ts
|
|
295
|
-
const nike = brand('nike')
|
|
296
|
-
const shirt = nike('shirt')
|
|
297
|
-
const socks = nike('socks')
|
|
298
|
-
```
|
|
299
|
-
|
|
300
|
-
`Flavor<F, T>`:
|
|
301
|
-
|
|
302
|
-
`flavor(type, subject?)`:
|
|
303
|
-
|
|
304
|
-
The key difference between `Flavor` and `Brand` is that
|
|
305
|
-
unflavored type can be assigned to `Flavor`:
|
|
306
|
-
|
|
307
|
-
```ts
|
|
308
|
-
let f = flavor('orange', 'soda')
|
|
309
|
-
f = 'mist' // ok
|
|
310
|
-
```
|
|
311
|
-
|
|
312
|
-
Also, `Brand` of the same name can be assigned to `Flavor`,
|
|
313
|
-
but `Flavor` of the same name cannot be assigned to `Brand`.
|
|
314
|
-
|
|
315
|
-
`nominalMatch(a, b)`:
|
|
316
|
-
|
|
317
|
-
`nominalMatch()` can be used to compare `Brand` or `Flavor`.
|
|
318
|
-
|
|
319
|
-
```ts
|
|
320
|
-
const b1 = brand('x', 1)
|
|
321
|
-
const b2 = brand('y', 1)
|
|
322
|
-
|
|
323
|
-
nominalMatch(b1, b2) // false
|
|
324
|
-
```
|
|
325
|
-
|
|
326
|
-
## Functional Types
|
|
327
|
-
|
|
328
|
-
- `ChainFn<T>: T`: chain function that returns the input type.
|
|
329
|
-
- `compose(...fns): F`: compose functions
|
|
330
|
-
|
|
331
267
|
## Type Utilities
|
|
332
268
|
|
|
333
269
|
`type-plus` also provides additional type utilities.
|
|
@@ -415,7 +351,7 @@ JSONTypes.get<string>(someJson, 'a', 'b', 1, 'c') // miku
|
|
|
415
351
|
|
|
416
352
|
- `ANotB<A, B>`: get object with properties in `A` and not in `B`, including properties with a different value type.
|
|
417
353
|
- `BNotA<A, B>`: flip of `ANotB`
|
|
418
|
-
- `as<T>(subject)`: assert `subject` as `T`. Avoid ASI issues such as `;(x as
|
|
354
|
+
- `as<T>(subject)`: assert `subject` as `T`. Avoid ASI issues such as `;(x as T).abc`
|
|
419
355
|
- `asAny(subject)`: assert `subject` as `any`. Avoid ASI issue such as `;(x as any).abc`
|
|
420
356
|
- `Except<T, K>`: Deprecated. Same as `Omit<T, K>`.
|
|
421
357
|
- `ExcludePropType<T, U>`: excludes type `U` from properties in `T`.
|
|
@@ -496,6 +432,7 @@ So you may encounter some weird behavior if your logic is complex.
|
|
|
496
432
|
- `required(...)`: merge options and removing `Partial<T>`. From [`unpartial`](https://github.com/unional/unpartial)
|
|
497
433
|
- `requiredDeep(...)`: merge options deeply and removing `Partial<T>`. From [`unpartial`](https://github.com/unional/unpartial)
|
|
498
434
|
- `split(target, ...splitters)`: split one object into multiple objects.
|
|
435
|
+
- `stub<T>(value)`: stub a particular type `T`.
|
|
499
436
|
- `typeOverrideIncompatible<T>()`: override only the incompatible portion between two types.
|
|
500
437
|
|
|
501
438
|
```ts
|
|
@@ -516,6 +453,70 @@ const source = {
|
|
|
516
453
|
overrider(source, { foo: !!source.foo })
|
|
517
454
|
```
|
|
518
455
|
|
|
456
|
+
## Nominal Types
|
|
457
|
+
|
|
458
|
+
The TypeScript type system is structural.
|
|
459
|
+
|
|
460
|
+
In some cases, we want to express a type with nominal behavior.
|
|
461
|
+
`type-plus` provides two kinds of nominal types: `Brand` and `Flavor`.
|
|
462
|
+
|
|
463
|
+
`Brand<B, T>`:
|
|
464
|
+
|
|
465
|
+
`brand(type, subject?)`:
|
|
466
|
+
|
|
467
|
+
Branded nominal type is the stronger nominal type of the two.
|
|
468
|
+
It disallows unbranded type assigned to it:
|
|
469
|
+
|
|
470
|
+
```ts
|
|
471
|
+
const a = brand('a', { a: 1 })
|
|
472
|
+
const b = { a: 1 }
|
|
473
|
+
a = b // error
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
`subject` can be any type, from primitive to strings to objects.
|
|
477
|
+
|
|
478
|
+
`brand(type)`:
|
|
479
|
+
|
|
480
|
+
If you do not provide `subject`, `brand(type)` will return a brand creator,
|
|
481
|
+
so that you can use it to create multiple branded values:
|
|
482
|
+
|
|
483
|
+
```ts
|
|
484
|
+
const nike = brand('nike')
|
|
485
|
+
const shirt = nike('shirt')
|
|
486
|
+
const socks = nike('socks')
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
`Flavor<F, T>`:
|
|
490
|
+
|
|
491
|
+
`flavor(type, subject?)`:
|
|
492
|
+
|
|
493
|
+
The key difference between `Flavor` and `Brand` is that
|
|
494
|
+
unflavored type can be assigned to `Flavor`:
|
|
495
|
+
|
|
496
|
+
```ts
|
|
497
|
+
let f = flavor('orange', 'soda')
|
|
498
|
+
f = 'mist' // ok
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
Also, `Brand` of the same name can be assigned to `Flavor`,
|
|
502
|
+
but `Flavor` of the same name cannot be assigned to `Brand`.
|
|
503
|
+
|
|
504
|
+
`nominalMatch(a, b)`:
|
|
505
|
+
|
|
506
|
+
`nominalMatch()` can be used to compare `Brand` or `Flavor`.
|
|
507
|
+
|
|
508
|
+
```ts
|
|
509
|
+
const b1 = brand('x', 1)
|
|
510
|
+
const b2 = brand('y', 1)
|
|
511
|
+
|
|
512
|
+
nominalMatch(b1, b2) // false
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
## Functional Types
|
|
516
|
+
|
|
517
|
+
- `ChainFn<T>: T`: chain function that returns the input type.
|
|
518
|
+
- `compose(...fns): F`: compose functions
|
|
519
|
+
|
|
519
520
|
## Attribution
|
|
520
521
|
|
|
521
522
|
Some of the code in this library is created by other people in the TypeScript community.
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { IsPositive } from '../math';
|
|
1
|
+
import type { IsPositive } from '../math';
|
|
2
2
|
/**
|
|
3
3
|
* Creates `Tuple<T>` with `L` number of elements.
|
|
4
4
|
*/
|
|
5
|
-
export declare type CreateTuple<L extends number, T = any> = IsPositive<L> extends true ? Device<[], L, T> : never;
|
|
6
|
-
declare
|
|
7
|
-
|
|
5
|
+
export declare type CreateTuple<L extends number, T = any> = IsPositive<L> extends true ? CreateTuple.Device<[], L, T> : never;
|
|
6
|
+
export declare namespace CreateTuple {
|
|
7
|
+
type Device<R extends any[], L extends number, T> = R['length'] extends L ? R : Device<[T, ...R], L, T>;
|
|
8
|
+
}
|
package/cjs/array/Some.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Equal } from '../predicates';
|
|
2
|
-
import { Tail } from './Tail';
|
|
3
|
-
import { UnionOfValues } from './UnionOfValues';
|
|
4
|
-
export declare type Some<A extends any[], Criteria, Mode extends 'strict' | 'loose' = 'loose', Then = true, Else = false> = Mode extends 'strict' ?
|
|
5
|
-
declare
|
|
6
|
-
|
|
1
|
+
import type { Equal } from '../predicates';
|
|
2
|
+
import type { Tail } from './Tail';
|
|
3
|
+
import type { UnionOfValues } from './UnionOfValues';
|
|
4
|
+
export declare type Some<A extends any[], Criteria, Mode extends 'strict' | 'loose' = 'loose', Then = true, Else = false> = Mode extends 'strict' ? Some.Strict<A, Criteria, Then, Else> : number extends A['length'] ? UnionOfValues<A> extends Criteria ? Then : Else : A['length'] extends 0 ? Else : A[0] extends Criteria ? Then : Some<Tail<A>, Criteria, 'loose', Then, Else>;
|
|
5
|
+
export declare namespace Some {
|
|
6
|
+
type Strict<A extends any[], Criteria, Then, Else> = number extends A['length'] ? (Equal<UnionOfValues<A>, Criteria> extends true ? Then : Else) : (A['length'] extends 0 ? Else : (Equal<A[0], Criteria> extends true ? Then : Strict<Tail<A>, Criteria, Then, Else>));
|
|
7
|
+
}
|
package/cjs/index.d.ts
CHANGED
package/cjs/index.js
CHANGED
|
@@ -31,6 +31,7 @@ __exportStar(require("./nominal-types"), exports);
|
|
|
31
31
|
__exportStar(require("./object"), exports);
|
|
32
32
|
__exportStar(require("./predicates"), exports);
|
|
33
33
|
__exportStar(require("./promise"), exports);
|
|
34
|
+
__exportStar(require("./testing"), exports);
|
|
34
35
|
__exportStar(require("./utils"), exports);
|
|
35
36
|
// export { types, types as T }
|
|
36
37
|
//# sourceMappingURL=index.js.map
|
package/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mCAAmC;AACnC,uCAAkD;AAAzC,qGAAA,QAAQ,OAAA;AAAE,yGAAA,YAAY,OAAA;AAC/B,0CAAuB;AACvB,8CAA2B;AAC3B,0CAAuB;AAEvB,6CAA0B;AAC1B,+CAA4B;AAC5B,8CAA2B;AAC3B,yCAAsB;AACtB,2CAAwB;AACxB,kDAA+B;AAC/B,2CAAwB;AACxB,+CAA4B;AAE5B,4CAAyB;AAIzB,0CAAuB;AACvB,+BAA+B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mCAAmC;AACnC,uCAAkD;AAAzC,qGAAA,QAAQ,OAAA;AAAE,yGAAA,YAAY,OAAA;AAC/B,0CAAuB;AACvB,8CAA2B;AAC3B,0CAAuB;AAEvB,6CAA0B;AAC1B,+CAA4B;AAC5B,8CAA2B;AAC3B,yCAAsB;AACtB,2CAAwB;AACxB,kDAA+B;AAC/B,2CAAwB;AACxB,+CAA4B;AAE5B,4CAAyB;AACzB,4CAAyB;AAIzB,0CAAuB;AACvB,+BAA+B"}
|
package/cjs/math/Abs.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { DigitArray } from './Digit';
|
|
1
|
+
import type { DigitArray } from './Digit';
|
|
2
2
|
export declare type Abs<N extends number, Fail = never> = number extends N ? Fail : `${N}` extends `-${infer P}` ? DigitArray.ToNumber<DigitArray.FromString<P>> : N;
|
package/cjs/math/Add.d.ts
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import { PadLeft } from '../array';
|
|
2
|
-
import { And } from '../predicates';
|
|
3
|
-
import { Digit, DigitArray } from './Digit';
|
|
4
|
-
import { IsPositive } from './IsPositive';
|
|
5
|
-
import { IsWhole } from './IsWhole';
|
|
6
|
-
import { Max } from './Max';
|
|
1
|
+
import type { PadLeft } from '../array';
|
|
2
|
+
import type { And } from '../predicates';
|
|
3
|
+
import type { Digit, DigitArray } from './Digit';
|
|
4
|
+
import type { IsPositive } from './IsPositive';
|
|
5
|
+
import type { IsWhole } from './IsWhole';
|
|
6
|
+
import type { Max } from './Max';
|
|
7
7
|
/**
|
|
8
8
|
* Add two number literals.
|
|
9
9
|
*/
|
|
10
|
-
export declare type Add<A extends number, B extends number, Fail = never> = And<And<IsPositive<A>, IsWhole<A>>, And<IsPositive<B>, IsWhole<B>>> extends false ? Fail : DigitArray.FromNumber<A> extends infer DA ? DA extends number[] ? DigitArray.FromNumber<B> extends infer DB ? DB extends number[] ? Max<DA['length'], DB['length']> extends infer M ? M extends number ? PadLeft<DA, M, 0> extends infer PDA ? PDA extends number[] ? PadLeft<DB, M, 0> extends infer PDB ? PDB extends number[] ? DigitArray.ToNumber<
|
|
11
|
-
declare
|
|
12
|
-
|
|
10
|
+
export declare type Add<A extends number, B extends number, Fail = never> = And<And<IsPositive<A>, IsWhole<A>>, And<IsPositive<B>, IsWhole<B>>> extends false ? Fail : DigitArray.FromNumber<A> extends infer DA ? DA extends number[] ? DigitArray.FromNumber<B> extends infer DB ? DB extends number[] ? Max<DA['length'], DB['length']> extends infer M ? M extends number ? PadLeft<DA, M, 0> extends infer PDA ? PDA extends number[] ? PadLeft<DB, M, 0> extends infer PDB ? PDB extends number[] ? DigitArray.ToNumber<Add.DigitArray<PDA, PDB>> : Fail : Fail : Fail : Fail : Fail : Fail : Fail : Fail : Fail : Fail;
|
|
11
|
+
export declare namespace Add {
|
|
12
|
+
type DigitArray<A extends number[], B extends number[]> = (A extends [any, ...infer ATail] ? (ATail extends number[] ? (B extends [any, ...infer BTail] ? (BTail extends number[] ? [Digit<A[0], B[0]>, ...DigitArray<ATail, BTail>] : []) : [A[0], ...DigitArray<[], ATail>]) : []) : (B extends [any, ...infer BTail] ? (BTail extends number[] ? [B[0], ...DigitArray<[], BTail>] : []) : []));
|
|
13
|
+
type Digit<A extends number, B extends number> = [
|
|
14
|
+
...Digit.ToTuple[A],
|
|
15
|
+
...Digit.ToTuple[B]
|
|
16
|
+
]['length'];
|
|
17
|
+
}
|
|
13
18
|
/**
|
|
14
19
|
* Increment `A` by 1.
|
|
15
20
|
*/
|
|
16
21
|
export declare type Increment<A extends number, Fail = never> = Add<A, 1, Fail>;
|
|
17
|
-
export {};
|
package/cjs/math/Digit.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { And } from '../predicates';
|
|
|
3
3
|
import { IsPositive } from './IsPositive';
|
|
4
4
|
import { IsWhole } from './IsWhole';
|
|
5
5
|
export declare namespace Digit {
|
|
6
|
-
|
|
6
|
+
type ToTuple = {
|
|
7
7
|
[k in number]: any[];
|
|
8
8
|
} & {
|
|
9
9
|
0: [];
|
|
@@ -30,7 +30,7 @@ export declare namespace Digit {
|
|
|
30
30
|
/**
|
|
31
31
|
* A > B for [1-9]
|
|
32
32
|
*/
|
|
33
|
-
|
|
33
|
+
type GreaterThan<A extends number, B extends number> = B extends GreaterThanMap[A] ? true : false;
|
|
34
34
|
type GreaterThanMap = {
|
|
35
35
|
[k in number]: number;
|
|
36
36
|
} & {
|
|
@@ -45,16 +45,15 @@ export declare namespace Digit {
|
|
|
45
45
|
8: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
|
|
46
46
|
9: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
|
|
47
47
|
};
|
|
48
|
-
export {};
|
|
49
48
|
}
|
|
50
49
|
export declare namespace DigitArray {
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
type ToNumber<C extends number[]> = ToTuple<[], C>['length'];
|
|
51
|
+
type ToTuple<R extends any[], S extends number[]> = S['length'] extends 0 ? R : (S['length'] extends 1 ? [...R, ...Digit.ToTuple[S[0]]] : (S extends [any, ...infer T] ? (T extends any[] ? ToTuple<Multi10<[...R, ...Digit.ToTuple[S[0]]]>, T> : never) : never));
|
|
53
52
|
type Multi10<C extends any[]> = [...C, ...C, ...C, ...C, ...C, ...C, ...C, ...C, ...C, ...C];
|
|
54
|
-
|
|
53
|
+
type FromNumber<N extends number> = FromString<NumberToString<N>>;
|
|
55
54
|
type NumberToString<N extends number> = (And<IsPositive<N>, IsWhole<N>>) extends true ? `${N}` : never;
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
type FromString<S extends string> = S extends `1${infer L}` ? [1, ...FromString<L>] : S extends `2${infer L}` ? [2, ...FromString<L>] : S extends `3${infer L}` ? [3, ...FromString<L>] : S extends `4${infer L}` ? [4, ...FromString<L>] : S extends `5${infer L}` ? [5, ...FromString<L>] : S extends `6${infer L}` ? [6, ...FromString<L>] : S extends `7${infer L}` ? [7, ...FromString<L>] : S extends `8${infer L}` ? [8, ...FromString<L>] : S extends `9${infer L}` ? [9, ...FromString<L>] : S extends `0${infer L}` ? [0, ...FromString<L>] : [];
|
|
56
|
+
type Shift10<DA extends number[]> = TrimLeadingZero<Shift10State<[], DA>>;
|
|
58
57
|
type Shift10State<R extends number[], DA extends number[]> = DA['length'] extends 0 ? R : (DA['length'] extends 1 ? [...R, ...DA] : (DA extends [any, ...infer T] ? (T extends number[] ? (DA[0] extends 0 ? Shift10State<[...R, DA[0]], T> : (T extends [any, ...infer Y] ? (Y extends number[] ? Shift10State<[...R, MinusOne[DA[0]]], [Plus10[T[0]], ...Y]> : []) : [])) : []) : []));
|
|
59
58
|
type TrimLeadingZero<A extends number[]> = A['length'] extends 0 ? A : A[0] extends 0 ? TrimLeadingZero<Tail<A>> : A;
|
|
60
59
|
type MinusOne = {
|
|
@@ -95,5 +94,4 @@ export declare namespace DigitArray {
|
|
|
95
94
|
8: 18;
|
|
96
95
|
9: 19;
|
|
97
96
|
};
|
|
98
|
-
export {};
|
|
99
97
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { Head, PadLeft, Tail } from '../array';
|
|
2
|
-
import { And, Equal } from '../predicates';
|
|
3
|
-
import { Digit, DigitArray } from './Digit';
|
|
4
|
-
import { IsPositive } from './IsPositive';
|
|
5
|
-
import { IsWhole } from './IsWhole';
|
|
6
|
-
import { Max } from './Max';
|
|
7
|
-
export declare type GreaterThan<A extends number, B extends number, Fail = never> = And<And<IsPositive<A>, IsWhole<A>>, And<IsPositive<B>, IsWhole<B>>> extends false ? Fail : number extends A ? Fail : number extends B ? Fail : Equal<A, B> extends true ? false :
|
|
8
|
-
declare
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import type { Head, PadLeft, Tail } from '../array';
|
|
2
|
+
import type { And, Equal } from '../predicates';
|
|
3
|
+
import type { Digit, DigitArray } from './Digit';
|
|
4
|
+
import type { IsPositive } from './IsPositive';
|
|
5
|
+
import type { IsWhole } from './IsWhole';
|
|
6
|
+
import type { Max } from './Max';
|
|
7
|
+
export declare type GreaterThan<A extends number, B extends number, Fail = never> = And<And<IsPositive<A>, IsWhole<A>>, And<IsPositive<B>, IsWhole<B>>> extends false ? Fail : number extends A ? Fail : number extends B ? Fail : Equal<A, B> extends true ? false : GreaterThan.OnPositiveWhole<A, B>;
|
|
8
|
+
export declare namespace GreaterThan {
|
|
9
|
+
type OnPositiveWhole<A extends number, B extends number> = (DigitArray.FromNumber<A> extends infer DA ? DA extends number[] ? DigitArray.FromNumber<B> extends infer DB ? DB extends number[] ? Max<DA['length'], DB['length']> extends infer M ? M extends number ? PadLeft<DA, M, 0> extends infer PDA ? PDA extends number[] ? PadLeft<DB, M, 0> extends infer PDB ? PDB extends number[] ? OnDigitArray<PDA, PDB> : never : never : never : never : never : never : never : never : never : never);
|
|
10
|
+
type OnDigitArray<DA extends number[], DB extends number[]> = (Equal<Head<DA>, Head<DB>> extends true ? OnDigitArray<Tail<DA>, Tail<DB>> extends Tail<DA> ? true : false : Digit.GreaterThan<Head<DA>, Head<DB>> extends true ? true : false);
|
|
11
|
+
}
|
package/cjs/math/Max.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { Head, Tail } from '../array';
|
|
2
|
-
import { And, Equal } from '../predicates';
|
|
3
|
-
import { Digit, DigitArray } from './Digit';
|
|
4
|
-
import { IsPositive } from './IsPositive';
|
|
5
|
-
import { IsWhole } from './IsWhole';
|
|
6
|
-
export declare type Max<A extends number, B extends number, Fail = never> = And<IsPositive<A>, IsWhole<A>> extends false ? Fail : And<IsPositive<B>, IsWhole<B>> extends false ? Fail : number extends A ? Fail : number extends B ? Fail : Equal<A, B> extends true ? A :
|
|
7
|
-
declare
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import type { Head, Tail } from '../array';
|
|
2
|
+
import type { And, Equal } from '../predicates';
|
|
3
|
+
import type { Digit, DigitArray } from './Digit';
|
|
4
|
+
import type { IsPositive } from './IsPositive';
|
|
5
|
+
import type { IsWhole } from './IsWhole';
|
|
6
|
+
export declare type Max<A extends number, B extends number, Fail = never> = And<IsPositive<A>, IsWhole<A>> extends false ? Fail : And<IsPositive<B>, IsWhole<B>> extends false ? Fail : number extends A ? Fail : number extends B ? Fail : Equal<A, B> extends true ? A : Max.OnPositiveWhole<A, B>;
|
|
7
|
+
export declare namespace Max {
|
|
8
|
+
type OnPositiveWhole<A extends number, B extends number> = (DigitArray.FromNumber<A> extends infer DA ? DA extends number[] ? DigitArray.FromNumber<B> extends infer DB ? DB extends number[] ? OnDigitArray<DA, DB> extends DA ? A : B : never : never : never : never);
|
|
9
|
+
type OnDigitArray<DA extends number[], DB extends number[]> = Equal<DA['length'], DB['length']> extends true ? (Equal<Head<DA>, Head<DB>> extends true ? (Tail<DA> extends infer TDA ? TDA extends number[] ? OnDigitArray<TDA, Tail<DB>> extends TDA ? DA : DB : never : never) : Digit.GreaterThan<Head<DA>, Head<DB>> extends true ? DA : DB) : OnPositiveWhole<DA['length'], DB['length']> extends DA['length'] ? DA : DB;
|
|
10
|
+
}
|
package/cjs/math/Subtract.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { PadLeft, Some, Tail } from '../array';
|
|
2
|
-
import { And } from '../predicates';
|
|
3
|
-
import { Digit, DigitArray } from './Digit';
|
|
4
|
-
import { IsPositive } from './IsPositive';
|
|
5
|
-
import { IsWhole } from './IsWhole';
|
|
6
|
-
import { Max } from './Max';
|
|
7
|
-
export declare type Subtract<A extends number, B extends number, Fail = never> = And<And<IsPositive<A>, IsWhole<A>>, And<IsPositive<B>, IsWhole<B>>> extends true ? (DigitArray.Shift10<DigitArray.FromNumber<A>> extends infer DA ? DA extends number[] ? DigitArray.FromNumber<B> extends infer DB ? DB extends number[] ? Max<DA['length'], DB['length']> extends infer M ? M extends number ? PadLeft<DA, M, 0> extends infer PDA ? PDA extends number[] ? PadLeft<DB, M, 0> extends infer PDB ? PDB extends number[] ?
|
|
8
|
-
declare
|
|
9
|
-
|
|
1
|
+
import type { PadLeft, Some, Tail } from '../array';
|
|
2
|
+
import type { And } from '../predicates';
|
|
3
|
+
import type { Digit, DigitArray } from './Digit';
|
|
4
|
+
import type { IsPositive } from './IsPositive';
|
|
5
|
+
import type { IsWhole } from './IsWhole';
|
|
6
|
+
import type { Max } from './Max';
|
|
7
|
+
export declare type Subtract<A extends number, B extends number, Fail = never> = And<And<IsPositive<A>, IsWhole<A>>, And<IsPositive<B>, IsWhole<B>>> extends true ? (DigitArray.Shift10<DigitArray.FromNumber<A>> extends infer DA ? DA extends number[] ? DigitArray.FromNumber<B> extends infer DB ? DB extends number[] ? Max<DA['length'], DB['length']> extends infer M ? M extends number ? PadLeft<DA, M, 0> extends infer PDA ? PDA extends number[] ? PadLeft<DB, M, 0> extends infer PDB ? PDB extends number[] ? Subtract.DigitArray<[], PDA, PDB> extends infer Result ? Result extends number[] ? Some<Result, never, 'strict'> extends true ? Fail : DigitArray.ToNumber<Result> : Fail : Fail : Fail : Fail : Fail : Fail : Fail : Fail : Fail : Fail : Fail : Fail) : Fail;
|
|
8
|
+
export declare namespace Subtract {
|
|
9
|
+
type DigitArray<R extends number[], A extends number[], B extends number[]> = A['length'] extends 0 ? R : DigitArray<[...R, Digit<A[0], B[0]>], Tail<A>, Tail<B>>;
|
|
10
|
+
type Digit<A extends number, B extends number> = Digit.ToTuple[A] extends [...(infer U), ...Digit.ToTuple[B]] ? U['length'] : never;
|
|
11
|
+
}
|
|
10
12
|
/**
|
|
11
13
|
* A - 1
|
|
12
14
|
*/
|
|
13
15
|
export declare type Decrement<A extends number, Fail = never> = Subtract<A, 1, Fail>;
|
|
14
|
-
export {};
|
package/cjs/math/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export type { Abs } from './Abs';
|
|
2
2
|
export type { Add, Increment } from './Add';
|
|
3
|
+
export type { Digit, DigitArray } from './Digit';
|
|
3
4
|
export type { GreaterThan } from './GreaterThan';
|
|
4
5
|
export type { IsPositive } from './IsPositive';
|
|
5
6
|
export type { IsWhole } from './IsWhole';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare type SystemErrors = {
|
|
1
|
+
export declare type SystemErrors = {
|
|
2
2
|
'EACCES': Error & {
|
|
3
3
|
code: 'EACCES';
|
|
4
4
|
};
|
|
@@ -28,4 +28,3 @@ export declare type SystemErrorCodes = keyof SystemErrors;
|
|
|
28
28
|
* Feel free to contribute.
|
|
29
29
|
*/
|
|
30
30
|
export declare function isSystemError<C extends SystemErrorCodes>(code: C, err: unknown): err is SystemErrors[C];
|
|
31
|
-
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isNodeError.js","sourceRoot":"","sources":["../../ts/nodejs/isNodeError.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"isNodeError.js","sourceRoot":"","sources":["../../ts/nodejs/isNodeError.ts"],"names":[],"mappings":";;;AAmBA;;;;GAIG;AACH,SAAgB,aAAa,CAA6B,IAAO,EAAE,GAAY;IAC7E,OAAO,CAAC,CAAC,GAAG,IAAK,GAAW,CAAC,IAAI,KAAK,IAAI,CAAA;AAC5C,CAAC;AAFD,sCAEC"}
|
package/cjs/object/split.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { AnyRecord, Omit } from '..';
|
|
|
2
2
|
declare type Splitter<T extends AnyRecord> = Partial<{
|
|
3
3
|
[k in keyof T]: T[k] | undefined;
|
|
4
4
|
}>;
|
|
5
|
-
declare type Split<T extends AnyRecord, S extends AnyRecord> = {
|
|
5
|
+
export declare type Split<T extends AnyRecord, S extends AnyRecord> = {
|
|
6
6
|
[k in keyof S]: NonNullable<T[k]> | S[k];
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './stub';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./stub"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../ts/testing/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAsB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stub.js","sourceRoot":"","sources":["../../ts/testing/stub.ts"],"names":[],"mappings":";;;AAKA,SAAgB,IAAI,CAAI,IAAa;IACnC,OAAO,IAAS,CAAA;AAClB,CAAC;AAFD,oBAEC"}
|
package/cjs/utils/as.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function as<T>(subject: unknown):
|
|
2
|
-
export declare function asAny(subject: unknown):
|
|
1
|
+
export declare function as<T>(subject: unknown): T;
|
|
2
|
+
export declare function asAny(subject: unknown): any;
|
package/cjs/utils/as.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.asAny = exports.as = void 0;
|
|
4
4
|
function as(subject) {
|
|
5
|
-
return
|
|
5
|
+
return subject;
|
|
6
6
|
}
|
|
7
7
|
exports.as = as;
|
|
8
8
|
function asAny(subject) {
|
|
9
|
-
return
|
|
9
|
+
return subject;
|
|
10
10
|
}
|
|
11
11
|
exports.asAny = asAny;
|
|
12
12
|
//# sourceMappingURL=as.js.map
|
package/cjs/utils/as.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"as.js","sourceRoot":"","sources":["../../ts/utils/as.ts"],"names":[],"mappings":";;;AAAA,SAAgB,EAAE,CAAI,OAAgB;IACpC,OAAO,
|
|
1
|
+
{"version":3,"file":"as.js","sourceRoot":"","sources":["../../ts/utils/as.ts"],"names":[],"mappings":";;;AAAA,SAAgB,EAAE,CAAI,OAAgB;IACpC,OAAO,OAAY,CAAA;AACrB,CAAC;AAFD,gBAEC;AAED,SAAgB,KAAK,CAAC,OAAgB;IACpC,OAAO,OAAO,CAAA;AAChB,CAAC;AAFD,sBAEC"}
|
package/esm/index.js
CHANGED
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAClD,cAAc,SAAS,CAAA;AACvB,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA;AAEvB,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,QAAQ,CAAA;AACtB,cAAc,UAAU,CAAA;AACxB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,UAAU,CAAA;AACxB,cAAc,cAAc,CAAA;AAE5B,cAAc,WAAW,CAAA;AAIzB,cAAc,SAAS,CAAA;AACvB,+BAA+B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAClD,cAAc,SAAS,CAAA;AACvB,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA;AAEvB,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,QAAQ,CAAA;AACtB,cAAc,UAAU,CAAA;AACxB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,UAAU,CAAA;AACxB,cAAc,cAAc,CAAA;AAE5B,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AAIzB,cAAc,SAAS,CAAA;AACvB,+BAA+B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isNodeError.js","sourceRoot":"","sources":["../../ts/nodejs/isNodeError.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"isNodeError.js","sourceRoot":"","sources":["../../ts/nodejs/isNodeError.ts"],"names":[],"mappings":"AAmBA;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAA6B,IAAO,EAAE,GAAY;IAC7E,OAAO,CAAC,CAAC,GAAG,IAAK,GAAW,CAAC,IAAI,KAAK,IAAI,CAAA;AAC5C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../ts/testing/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stub.js","sourceRoot":"","sources":["../../ts/testing/stub.ts"],"names":[],"mappings":"AAKA,MAAM,UAAU,IAAI,CAAI,IAAa;IACnC,OAAO,IAAS,CAAA;AAClB,CAAC"}
|
package/esm/utils/as.js
CHANGED
package/esm/utils/as.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"as.js","sourceRoot":"","sources":["../../ts/utils/as.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,EAAE,CAAI,OAAgB;IACpC,OAAO,
|
|
1
|
+
{"version":3,"file":"as.js","sourceRoot":"","sources":["../../ts/utils/as.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,EAAE,CAAI,OAAgB;IACpC,OAAO,OAAY,CAAA;AACrB,CAAC;AAED,MAAM,UAAU,KAAK,CAAC,OAAgB;IACpC,OAAO,OAAO,CAAA;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "type-plus",
|
|
3
|
-
"version": "4.
|
|
4
|
-
"description": "Provides additional types for
|
|
3
|
+
"version": "4.4.0",
|
|
4
|
+
"description": "Provides additional types for TypeScript.",
|
|
5
5
|
"homepage": "https://github.com/unional/type-plus",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/unional/type-plus/issues"
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"build": "run-p build:cjs build:esm",
|
|
30
30
|
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
31
31
|
"build:esm": "tsc -p tsconfig.esm.json",
|
|
32
|
+
"build:doc": "typedoc",
|
|
32
33
|
"clean": "rimraf cjs esm coverage lib libm",
|
|
33
34
|
"coverage": "jest --coverage",
|
|
34
35
|
"depcheck": "yarn dependency-check",
|
|
@@ -43,12 +44,8 @@
|
|
|
43
44
|
"test:types": "tsc",
|
|
44
45
|
"verify": "run-p verify:build lint test:types coverage",
|
|
45
46
|
"verify:build": "npm-run-all clean build --parallel dependency-check size-limit",
|
|
46
|
-
"watch": "jest --watch"
|
|
47
|
-
|
|
48
|
-
"husky": {
|
|
49
|
-
"hooks": {
|
|
50
|
-
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
|
|
51
|
-
}
|
|
47
|
+
"watch": "jest --watch",
|
|
48
|
+
"prepare": "husky install"
|
|
52
49
|
},
|
|
53
50
|
"dependencies": {
|
|
54
51
|
"tersify": "^3.8.2",
|
|
@@ -71,7 +68,7 @@
|
|
|
71
68
|
"dependency-check": "^4.1.0",
|
|
72
69
|
"eslint": "^8.11.0",
|
|
73
70
|
"eslint-plugin-harmony": "^6.0.0",
|
|
74
|
-
"husky": "^7.0.
|
|
71
|
+
"husky": "^7.0.0",
|
|
75
72
|
"jest": "^27.5.1",
|
|
76
73
|
"jest-progress-tracker": "^3.0.3",
|
|
77
74
|
"jest-validate": "^27.5.1",
|
|
@@ -83,6 +80,8 @@
|
|
|
83
80
|
"rimraf": "^3.0.2",
|
|
84
81
|
"satisfier": "^5.1.2",
|
|
85
82
|
"size-limit": "^7.0.8",
|
|
83
|
+
"typedoc": "^0.22.13",
|
|
84
|
+
"typedoc-plugin-extras": "^2.2.3",
|
|
86
85
|
"typescript": "^4.6.2"
|
|
87
86
|
},
|
|
88
87
|
"size-limit": [
|