type-plus 4.2.0 → 4.3.2

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.
Files changed (46) hide show
  1. package/README.md +71 -70
  2. package/cjs/array/CreateTuple.d.ts +5 -4
  3. package/cjs/array/Some.d.ts +7 -6
  4. package/cjs/functional/compose.d.ts +6 -0
  5. package/cjs/functional/compose.js +21 -0
  6. package/cjs/functional/compose.js.map +1 -0
  7. package/cjs/functional/index.d.ts +1 -0
  8. package/cjs/functional/index.js +15 -0
  9. package/cjs/functional/index.js.map +1 -1
  10. package/cjs/math/Abs.d.ts +1 -1
  11. package/cjs/math/Add.d.ts +14 -10
  12. package/cjs/math/Digit.d.ts +7 -9
  13. package/cjs/math/GreaterThan.d.ts +11 -10
  14. package/cjs/math/Max.d.ts +10 -9
  15. package/cjs/math/Subtract.d.ts +11 -10
  16. package/cjs/math/index.d.ts +1 -0
  17. package/cjs/nodejs/isNodeError.d.ts +1 -2
  18. package/cjs/nodejs/isNodeError.js.map +1 -1
  19. package/cjs/object/split.d.ts +1 -1
  20. package/cjs/utils/as.d.ts +2 -2
  21. package/cjs/utils/as.js +2 -2
  22. package/cjs/utils/as.js.map +1 -1
  23. package/esm/functional/compose.js +7 -0
  24. package/esm/functional/compose.js.map +1 -0
  25. package/esm/functional/index.js +1 -1
  26. package/esm/functional/index.js.map +1 -1
  27. package/esm/nodejs/isNodeError.js.map +1 -1
  28. package/esm/utils/as.js +2 -2
  29. package/esm/utils/as.js.map +1 -1
  30. package/package.json +8 -9
  31. package/ts/array/CreateTuple.ts +6 -4
  32. package/ts/array/Some.ts +26 -24
  33. package/ts/functional/compose.spec.ts +32 -0
  34. package/ts/functional/compose.ts +9 -0
  35. package/ts/functional/index.ts +1 -0
  36. package/ts/math/Abs.ts +4 -4
  37. package/ts/math/Add.ts +52 -49
  38. package/ts/math/Digit.ts +115 -115
  39. package/ts/math/GreaterThan.ts +38 -36
  40. package/ts/math/Max.ts +32 -31
  41. package/ts/math/Subtract.ts +43 -40
  42. package/ts/math/index.ts +1 -0
  43. package/ts/nodejs/isNodeError.ts +1 -2
  44. package/ts/object/split.ts +1 -1
  45. package/ts/utils/as.spec.ts +33 -24
  46. package/ts/utils/as.ts +7 -7
@@ -1,40 +1,43 @@
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
-
8
- export type Subtract<A extends number, B extends number, Fail = never> =
9
- And<
10
- And<IsPositive<A>, IsWhole<A>>,
11
- And<IsPositive<B>, IsWhole<B>>
12
- > extends true
13
- ? (DigitArray.Shift10<DigitArray.FromNumber<A>> extends infer DA ? DA extends number[] ?
14
- DigitArray.FromNumber<B> extends infer DB ? DB extends number[] ?
15
- Max<DA['length'], DB['length']> extends infer M ? M extends number ?
16
- PadLeft<DA, M, 0> extends infer PDA ? PDA extends number[] ?
17
- PadLeft<DB, M, 0> extends infer PDB ? PDB extends number[] ?
18
- SubtractDigitArray<[], PDA, PDB> extends infer Result ? Result extends number[] ?
19
- Some<Result, never, 'strict'> extends true ? Fail :
20
- DigitArray.ToNumber<Result>
21
- : Fail : Fail
22
- : Fail : Fail
23
- : Fail : Fail
24
- : Fail : Fail
25
- : Fail : Fail
26
- : Fail : Fail)
27
- : Fail
28
-
29
- type SubtractDigitArray<R extends number[], A extends number[], B extends number[]> =
30
- A['length'] extends 0 ? R :
31
- SubtractDigitArray<[...R, SubtractDigit<A[0], B[0]>], Tail<A>, Tail<B>>
32
-
33
-
34
- type SubtractDigit<A extends number, B extends number> =
35
- Digit.ToTuple[A] extends [...(infer U), ...Digit.ToTuple[B]] ? U['length'] : never
36
-
37
- /**
38
- * A - 1
39
- */
40
- export type Decrement<A extends number, Fail = never> = Subtract<A, 1, Fail>
1
+ import type { PadLeft, Some, Tail } from '../array'
2
+ import type { And } from '../predicates'
3
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
4
+ import type { Digit, DigitArray } from './Digit'
5
+ import type { IsPositive } from './IsPositive'
6
+ import type { IsWhole } from './IsWhole'
7
+ import type { Max } from './Max'
8
+
9
+ export type Subtract<A extends number, B extends number, Fail = never> =
10
+ And<
11
+ And<IsPositive<A>, IsWhole<A>>,
12
+ And<IsPositive<B>, IsWhole<B>>
13
+ > extends true
14
+ ? (DigitArray.Shift10<DigitArray.FromNumber<A>> extends infer DA ? DA extends number[] ?
15
+ DigitArray.FromNumber<B> extends infer DB ? DB extends number[] ?
16
+ Max<DA['length'], DB['length']> extends infer M ? M extends number ?
17
+ PadLeft<DA, M, 0> extends infer PDA ? PDA extends number[] ?
18
+ PadLeft<DB, M, 0> extends infer PDB ? PDB extends number[] ?
19
+ Subtract.DigitArray<[], PDA, PDB> extends infer Result ? Result extends number[] ?
20
+ Some<Result, never, 'strict'> extends true ? Fail :
21
+ DigitArray.ToNumber<Result>
22
+ : Fail : Fail
23
+ : Fail : Fail
24
+ : Fail : Fail
25
+ : Fail : Fail
26
+ : Fail : Fail
27
+ : Fail : Fail)
28
+ : Fail
29
+
30
+ export namespace Subtract {
31
+ export type DigitArray<R extends number[], A extends number[], B extends number[]> =
32
+ A['length'] extends 0 ? R :
33
+ DigitArray<[...R, Digit<A[0], B[0]>], Tail<A>, Tail<B>>
34
+
35
+
36
+ export type Digit<A extends number, B extends number> =
37
+ Digit.ToTuple[A] extends [...(infer U), ...Digit.ToTuple[B]] ? U['length'] : never
38
+ }
39
+
40
+ /**
41
+ * A - 1
42
+ */
43
+ export type Decrement<A extends number, Fail = never> = Subtract<A, 1, Fail>
package/ts/math/index.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,5 +1,4 @@
1
-
2
- type SystemErrors = {
1
+ export type SystemErrors = {
3
2
  'EACCES': Error & { code: 'EACCES' },
4
3
  'EADDRINUSE': Error & { code: 'EADDRINUSE' },
5
4
  'ECONNREFUSED': Error,
@@ -1,7 +1,7 @@
1
1
  import { AnyRecord, Omit, reduceByKey } from '..'
2
2
 
3
3
  type Splitter<T extends AnyRecord> = Partial<{ [k in keyof T]: T[k] | undefined }>
4
- type Split<T extends AnyRecord, S extends AnyRecord> = { [k in keyof S]: NonNullable<T[k]> | S[k] }
4
+ export type Split<T extends AnyRecord, S extends AnyRecord> = { [k in keyof S]: NonNullable<T[k]> | S[k] }
5
5
 
6
6
  /**
7
7
  * Split an object into multiple objects.
@@ -1,24 +1,33 @@
1
- import { as, asAny, isType } from '..'
2
-
3
- describe('as<T>()', () => {
4
- test('defaults subject type to unknown', () => {
5
- const s: any = {}
6
- if (as(s)) isType.equal<true, unknown, typeof s>()
7
- })
8
-
9
- test('cast type to T', () => {
10
- const s: any = {}
11
- if (as<number>(s)) isType.equal<true, number, typeof s>()
12
- if (as<string>(s)) isType.equal<true, string, typeof s>()
13
- if (as<{ a: number }>(s)) isType.equal<true, { a: number }, typeof s>()
14
- if (as<any>(s)) isType.equal<true, any, typeof s>()
15
- })
16
- })
17
-
18
- describe('asAny()', () => {
19
- test('cast type to any', () => {
20
- const s: unknown = {}
21
- if (asAny(s)) isType.equal<true, any, typeof s>()
22
- })
23
- })
24
-
1
+ import { as, asAny, isType } from '..'
2
+
3
+ describe('as<T>()', () => {
4
+ test('defaults subject type to unknown', () => {
5
+ const s: any = {}
6
+ const a = as(s)
7
+ isType.equal<true, unknown, typeof a>()
8
+ })
9
+
10
+ test('cast type to T', () => {
11
+ const s: any = {}
12
+ const n = as<number>(s)
13
+ isType.equal<true, number, typeof n>()
14
+
15
+ const str = as<string>(s)
16
+ isType.equal<true, string, typeof str>()
17
+
18
+ const o = as<{ a: number }>(s)
19
+ isType.equal<true, { a: number }, typeof o>()
20
+
21
+ const any = as<any>(s)
22
+ isType.equal<true, any, typeof any>()
23
+ })
24
+ })
25
+
26
+ describe('asAny()', () => {
27
+ test('cast type to any', () => {
28
+ const s: unknown = {}
29
+ const a = asAny(s)
30
+ isType.equal<true, any, typeof a>()
31
+ })
32
+ })
33
+
package/ts/utils/as.ts CHANGED
@@ -1,7 +1,7 @@
1
- export function as<T>(subject: unknown): subject is T {
2
- return true
3
- }
4
-
5
- export function asAny(subject: unknown): subject is any {
6
- return true
7
- }
1
+ export function as<T>(subject: unknown): T {
2
+ return subject as T
3
+ }
4
+
5
+ export function asAny(subject: unknown): any {
6
+ return subject
7
+ }