type-plus 4.0.0 → 4.1.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.
Files changed (92) hide show
  1. package/README.md +3 -2
  2. package/cjs/array/index.d.ts +17 -17
  3. package/cjs/array/index.js +5 -18
  4. package/cjs/array/index.js.map +1 -1
  5. package/cjs/assertion/index.js +5 -1
  6. package/cjs/assertion/index.js.map +1 -1
  7. package/cjs/class/index.d.ts +1 -1
  8. package/cjs/class/index.js +5 -2
  9. package/cjs/class/index.js.map +1 -1
  10. package/cjs/function/index.d.ts +1 -1
  11. package/cjs/function/index.js +0 -11
  12. package/cjs/function/index.js.map +1 -1
  13. package/cjs/functional/index.d.ts +1 -1
  14. package/cjs/functional/index.js +0 -12
  15. package/cjs/functional/index.js.map +1 -1
  16. package/cjs/index.d.ts +3 -3
  17. package/cjs/index.js +5 -6
  18. package/cjs/index.js.map +1 -1
  19. package/cjs/math/index.d.ts +7 -7
  20. package/cjs/math/index.js +0 -17
  21. package/cjs/math/index.js.map +1 -1
  22. package/cjs/nodejs/index.js +5 -1
  23. package/cjs/nodejs/index.js.map +1 -1
  24. package/cjs/nominal-types/index.js +5 -1
  25. package/cjs/nominal-types/index.js.map +1 -1
  26. package/cjs/object/index.d.ts +19 -18
  27. package/cjs/object/index.js +6 -19
  28. package/cjs/object/index.js.map +1 -1
  29. package/cjs/object/split.d.ts +80 -0
  30. package/cjs/object/split.js +25 -0
  31. package/cjs/object/split.js.map +1 -0
  32. package/cjs/predicates/CanAssign.d.ts +1 -1
  33. package/cjs/predicates/{isEmptyObject.d.ts → IsEmptyObject.d.ts} +0 -0
  34. package/cjs/predicates/{isEmptyObject.js → IsEmptyObject.js} +1 -1
  35. package/cjs/predicates/IsEmptyObject.js.map +1 -0
  36. package/cjs/predicates/index.d.ts +5 -5
  37. package/cjs/predicates/index.js +5 -6
  38. package/cjs/predicates/index.js.map +1 -1
  39. package/cjs/promise/index.d.ts +2 -2
  40. package/cjs/promise/index.js +5 -3
  41. package/cjs/promise/index.js.map +1 -1
  42. package/cjs/utils/index.d.ts +1 -1
  43. package/cjs/utils/index.js +5 -2
  44. package/cjs/utils/index.js.map +1 -1
  45. package/esm/array/index.js +0 -17
  46. package/esm/array/index.js.map +1 -1
  47. package/esm/class/index.js +0 -1
  48. package/esm/class/index.js.map +1 -1
  49. package/esm/function/index.js +1 -1
  50. package/esm/function/index.js.map +1 -1
  51. package/esm/functional/index.js +1 -2
  52. package/esm/functional/index.js.map +1 -1
  53. package/esm/index.js +0 -5
  54. package/esm/index.js.map +1 -1
  55. package/esm/math/index.js +1 -7
  56. package/esm/math/index.js.map +1 -1
  57. package/esm/object/index.js +1 -18
  58. package/esm/object/index.js.map +1 -1
  59. package/esm/object/split.js +8 -0
  60. package/esm/object/split.js.map +1 -0
  61. package/esm/predicates/IsEmptyObject.js +2 -0
  62. package/esm/predicates/IsEmptyObject.js.map +1 -0
  63. package/esm/predicates/index.js +0 -5
  64. package/esm/predicates/index.js.map +1 -1
  65. package/esm/promise/index.js +0 -2
  66. package/esm/promise/index.js.map +1 -1
  67. package/esm/utils/index.js +0 -1
  68. package/esm/utils/index.js.map +1 -1
  69. package/package.json +20 -18
  70. package/ts/array/index.ts +19 -19
  71. package/ts/binary/_binary.ts +1 -1
  72. package/ts/class/index.ts +1 -1
  73. package/ts/function/index.ts +1 -1
  74. package/ts/functional/ChainFn.ts +6 -6
  75. package/ts/functional/index.ts +2 -2
  76. package/ts/index.spec.ts +6 -4
  77. package/ts/index.ts +3 -3
  78. package/ts/math/index.ts +7 -7
  79. package/ts/object/Partial.spec.ts +49 -49
  80. package/ts/object/index.ts +35 -35
  81. package/ts/object/split.spec.ts +54 -0
  82. package/ts/object/split.ts +191 -0
  83. package/ts/predicates/CanAssign.ts +1 -1
  84. package/ts/predicates/{isEmptyObject.spec.ts → IsEmptyObject.spec.ts} +0 -0
  85. package/ts/predicates/{isEmptyObject.ts → IsEmptyObject.ts} +0 -0
  86. package/ts/predicates/index.ts +17 -17
  87. package/ts/promise/index.ts +2 -2
  88. package/ts/types/index.ts +28 -28
  89. package/ts/utils/index.ts +2 -2
  90. package/cjs/predicates/isEmptyObject.js.map +0 -1
  91. package/esm/predicates/isEmptyObject.js +0 -2
  92. package/esm/predicates/isEmptyObject.js.map +0 -1
@@ -1,35 +1,35 @@
1
- export * from '../object/IsDisjoint'
2
- export * from './ANotB'
3
- export * from './AnyRecord'
4
- export * from './everyKey'
5
- export * from './ExcludePropType'
6
- export * from './facade'
7
- export * from './filterKey'
8
- export * from './findKey'
9
- export * from './forEachKey'
10
- export * from './getField'
11
- export * from './hasKey'
12
- export * from './hasProperty'
13
- export * from './IsRecord'
14
- export * from './KeyofOptional'
15
- export * from './KeysWithDiffType'
16
- export * from './KeyTypes'
17
- export * from './KnownKeys'
18
- export * from './mapKey'
19
- export * from './mapProperties'
20
- export * from './omit'
21
- export * from './OptionalKeys'
22
- export * from './Partial'
23
- export * from './pick'
24
- export * from './RecursiveIntersect'
25
- export * from './RecursivePartial'
26
- export * from './RecursiveRequired'
27
- export * from './reduceKey'
28
- export * from './replaceProperty'
29
- export * from './Required'
30
- export * from './RequiredKeys'
31
- export * from './someKey'
32
- export * from './SpreadRecord'
33
- export * from './typeOverrideIncompatible'
34
- export * from './ValueOf'
35
-
1
+ export type { ANotB, BNotA, LeftJoin } from './ANotB'
2
+ export type { AnyRecord } from './AnyRecord'
3
+ export * from './everyKey'
4
+ export type { ExcludePropType } from './ExcludePropType'
5
+ export * from './facade'
6
+ export * from './filterKey'
7
+ export * from './findKey'
8
+ export * from './forEachKey'
9
+ export * from './getField'
10
+ export * from './hasKey'
11
+ export * from './hasProperty'
12
+ export type { IsDisjoint } from './IsDisjoint'
13
+ export type { IsRecord } from './IsRecord'
14
+ export type { KeysOfOptional } from './KeyofOptional'
15
+ export type { KeysWithDiffType } from './KeysWithDiffType'
16
+ export type { KeyTypes } from './KeyTypes'
17
+ export type { KnownKeys } from './KnownKeys'
18
+ export * from './mapKey'
19
+ export * from './mapProperties'
20
+ export * from './omit'
21
+ export type { OptionalKeys } from './OptionalKeys'
22
+ export type { PartialExcept, PartialOmit, PartialPick } from './Partial'
23
+ export * from './pick'
24
+ export type { RecursiveIntersect } from './RecursiveIntersect'
25
+ export type { RecursivePartial } from './RecursivePartial'
26
+ export type { RecursiveRequired } from './RecursiveRequired'
27
+ export * from './reduceKey'
28
+ export * from './replaceProperty'
29
+ export type { RequiredExcept, RequiredPick } from './Required'
30
+ export type { RequiredKeys } from './RequiredKeys'
31
+ export * from './someKey'
32
+ export * from './split'
33
+ export type { SpreadRecord } from './SpreadRecord'
34
+ export * from './typeOverrideIncompatible'
35
+ export type { ValueOf } from './ValueOf'
@@ -0,0 +1,54 @@
1
+ import { isType, split } from '..'
2
+
3
+ const target = { a: 0, b: '', c: false }
4
+ test('can use undefined as default', () => {
5
+ const [{ a }] = split(target, { a: undefined })
6
+
7
+ isType.equal<true, typeof a, number | undefined>()
8
+ expect(a).toBe(0)
9
+ })
10
+
11
+ test('can specify default with the same type', () => {
12
+ const [{ a }] = split(target, { a: 2 })
13
+
14
+ isType.equal<true, typeof a, number>()
15
+ expect(a).toBe(0)
16
+ })
17
+
18
+ test('can specify default as one of the intersect types', () => {
19
+ const [a] = split({ a: undefined as number | string | undefined }, { a: '2' })
20
+
21
+ isType.equal<true, typeof a, { a: number | string }>()
22
+ expect(a).toEqual({ a: '2' })
23
+ })
24
+
25
+ test('get remaining props in the last entry', () => {
26
+ const [, r] = split(target, { a: undefined })
27
+
28
+ isType.equal<true, typeof r, { b: string, c: boolean }>()
29
+ expect(r).toEqual({ b: '', c: false })
30
+ })
31
+
32
+ test('work with simple Record', () => {
33
+ const [a] = split({} as Record<string, string>, { a: 'a' })
34
+
35
+ isType.equal<true, typeof a, { a: string }>()
36
+ expect(a).toEqual({ a: 'a' })
37
+ })
38
+
39
+ test('can specify multiple splitters', () => {
40
+ const t = { r: 'r' } as { a?: string, b?: string, c?: string, r?: string }
41
+ const [a, b, c, r] = split(t,
42
+ { a: 'a' },
43
+ { b: 'b' },
44
+ { c: 'c' }
45
+ )
46
+ isType.equal<true, typeof a, { a: string }>()
47
+ isType.equal<true, typeof b, { b: string }>()
48
+ isType.equal<true, typeof c, { c: string }>()
49
+ isType.equal<true, typeof r, { r?: string | undefined }>()
50
+ expect(a).toEqual({ a: 'a' })
51
+ expect(b).toEqual({ b: 'b' })
52
+ expect(c).toEqual({ c: 'c' })
53
+ expect(r).toEqual({ r: 'r' })
54
+ })
@@ -0,0 +1,191 @@
1
+ import { AnyRecord, Omit, reduceByKey } from '..'
2
+
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] }
5
+
6
+ export function split<
7
+ T extends AnyRecord,
8
+ S1 extends Splitter<T>
9
+ >(target: T, split1: S1): [
10
+ Split<T, S1>,
11
+ Omit<T, keyof S1>
12
+ ]
13
+ export function split<
14
+ T extends AnyRecord,
15
+ S1 extends Splitter<T>,
16
+ S2 extends Splitter<T>,
17
+ >(target: T, split1: S1, split2: S2): [
18
+ Split<T, S1>,
19
+ Split<T, S2>,
20
+ Omit<T, keyof S1 | keyof S2>
21
+ ]
22
+ export function split<
23
+ T extends AnyRecord,
24
+ S1 extends Splitter<T>,
25
+ S2 extends Splitter<T>,
26
+ S3 extends Splitter<T>,
27
+ >(target: T, splitter1: S1, splitter2: S2, splitter3: S3): [
28
+ Split<T, S1>,
29
+ Split<T, S2>,
30
+ Split<T, S3>,
31
+ Omit<T, keyof S1 | keyof S2 | keyof S3>
32
+ ]
33
+ export function split<
34
+ T extends AnyRecord,
35
+ S1 extends Splitter<T>,
36
+ S2 extends Splitter<T>,
37
+ S3 extends Splitter<T>,
38
+ S4 extends Splitter<T>,
39
+ >(target: T,
40
+ splitter1: S1,
41
+ splitter2: S2,
42
+ splitter3: S3,
43
+ splitter4: S4,
44
+ ): [
45
+ Split<T, S1>,
46
+ Split<T, S2>,
47
+ Split<T, S3>,
48
+ Split<T, S4>,
49
+ Omit<T, keyof S1 | keyof S2 | keyof S3 | keyof S4>
50
+ ]
51
+ export function split<
52
+ T extends AnyRecord,
53
+ S1 extends Splitter<T>,
54
+ S2 extends Splitter<T>,
55
+ S3 extends Splitter<T>,
56
+ S4 extends Splitter<T>,
57
+ S5 extends Splitter<T>,
58
+ >(target: T,
59
+ splitter1: S1,
60
+ splitter2: S2,
61
+ splitter3: S3,
62
+ splitter4: S4,
63
+ splitter5: S5,
64
+ ): [
65
+ Split<T, S1>,
66
+ Split<T, S2>,
67
+ Split<T, S3>,
68
+ Split<T, S4>,
69
+ Split<T, S5>,
70
+ Omit<T, keyof S1 | keyof S2 | keyof S3 | keyof S4 | keyof S5>
71
+ ]
72
+ export function split<
73
+ T extends AnyRecord,
74
+ S1 extends Splitter<T>,
75
+ S2 extends Splitter<T>,
76
+ S3 extends Splitter<T>,
77
+ S4 extends Splitter<T>,
78
+ S5 extends Splitter<T>,
79
+ S6 extends Splitter<T>,
80
+ >(target: T,
81
+ splitter1: S1,
82
+ splitter2: S2,
83
+ splitter3: S3,
84
+ splitter4: S4,
85
+ splitter5: S5,
86
+ splitter6: S6,
87
+ ): [
88
+ Split<T, S1>,
89
+ Split<T, S2>,
90
+ Split<T, S3>,
91
+ Split<T, S4>,
92
+ Split<T, S5>,
93
+ Split<T, S6>,
94
+ Omit<T, keyof S1 | keyof S2 | keyof S3 | keyof S4 | keyof S5 | keyof S6>
95
+ ]
96
+ export function split<
97
+ T extends AnyRecord,
98
+ S1 extends Splitter<T>,
99
+ S2 extends Splitter<T>,
100
+ S3 extends Splitter<T>,
101
+ S4 extends Splitter<T>,
102
+ S5 extends Splitter<T>,
103
+ S6 extends Splitter<T>,
104
+ S7 extends Splitter<T>,
105
+ >(target: T,
106
+ splitter1: S1,
107
+ splitter2: S2,
108
+ splitter3: S3,
109
+ splitter4: S4,
110
+ splitter5: S5,
111
+ splitter6: S6,
112
+ splitter7: S7,
113
+ ): [
114
+ Split<T, S1>,
115
+ Split<T, S2>,
116
+ Split<T, S3>,
117
+ Split<T, S4>,
118
+ Split<T, S5>,
119
+ Split<T, S6>,
120
+ Split<T, S7>,
121
+ Omit<T, keyof S1 | keyof S2 | keyof S3 | keyof S4 | keyof S5 | keyof S6 | keyof S7>
122
+ ]
123
+ export function split<
124
+ T extends AnyRecord,
125
+ S1 extends Splitter<T>,
126
+ S2 extends Splitter<T>,
127
+ S3 extends Splitter<T>,
128
+ S4 extends Splitter<T>,
129
+ S5 extends Splitter<T>,
130
+ S6 extends Splitter<T>,
131
+ S7 extends Splitter<T>,
132
+ S8 extends Splitter<T>,
133
+ >(target: T,
134
+ splitter1: S1,
135
+ splitter2: S2,
136
+ splitter3: S3,
137
+ splitter4: S4,
138
+ splitter5: S5,
139
+ splitter6: S6,
140
+ splitter7: S7,
141
+ splitter8: S8,
142
+ ): [
143
+ Split<T, S1>,
144
+ Split<T, S2>,
145
+ Split<T, S3>,
146
+ Split<T, S4>,
147
+ Split<T, S5>,
148
+ Split<T, S6>,
149
+ Split<T, S7>,
150
+ Split<T, S8>,
151
+ Omit<T, keyof S1 | keyof S2 | keyof S3 | keyof S4 | keyof S5 | keyof S6 | keyof S7 | keyof S8>
152
+ ]
153
+ export function split<
154
+ T extends AnyRecord,
155
+ S1 extends Splitter<T>,
156
+ S2 extends Splitter<T>,
157
+ S3 extends Splitter<T>,
158
+ S4 extends Splitter<T>,
159
+ S5 extends Splitter<T>,
160
+ S6 extends Splitter<T>,
161
+ S7 extends Splitter<T>,
162
+ S8 extends Splitter<T>,
163
+ S9 extends Splitter<T>,
164
+ >(target: T,
165
+ splitter1: S1,
166
+ splitter2: S2,
167
+ splitter3: S3,
168
+ splitter4: S4,
169
+ splitter5: S5,
170
+ splitter6: S6,
171
+ splitter7: S7,
172
+ splitter8: S8,
173
+ splitter9: S9,
174
+ ): [
175
+ Split<T, S1>,
176
+ Split<T, S2>,
177
+ Split<T, S3>,
178
+ Split<T, S4>,
179
+ Split<T, S5>,
180
+ Split<T, S6>,
181
+ Split<T, S7>,
182
+ Split<T, S8>,
183
+ Split<T, S9>,
184
+ Omit<T, keyof S1 | keyof S2 | keyof S3 | keyof S4 | keyof S5 | keyof S6 | keyof S7 | keyof S8 | keyof S9>
185
+ ]
186
+ export function split(target: AnyRecord, ...splitters: AnyRecord[]): AnyRecord[] {
187
+ const keyMap: AnyRecord = {}
188
+ const s = splitters.map(s => reduceByKey(s, (p, k) => (keyMap[k] = true, p[k] = target[k] ?? s[k], p), {} as AnyRecord))
189
+ const r = reduceByKey(target, (p, k) => keyMap[k] ? p : (p[k] = target[k], p), {} as AnyRecord)
190
+ return [...s, r]
191
+ }
@@ -1,5 +1,5 @@
1
1
  import { NotExtendable } from './Extends'
2
- import { IsEmptyObject } from './isEmptyObject'
2
+ import { IsEmptyObject } from './IsEmptyObject'
3
3
 
4
4
  /**
5
5
  * Can `A` assign to `B`
@@ -1,17 +1,17 @@
1
- export * from './CanAssign'
2
- export * from './Equal'
3
- export * from './Extends'
4
- export * from './If'
5
- export * from './isType'
6
- export * from './logical'
7
- export * from './isEmptyObject'
8
-
9
- import { IsExtend } from './Extends'
10
-
11
- export type IsLiteral<T extends number | string, Then = true, Else = false> = number extends T ?
12
- Else :
13
- string extends T ? Else : Then
14
-
15
- export type IsBoolean<T, Then = true, Else = false> = boolean extends T ? Then : Else
16
-
17
- export type IsAny<T, Then = true, Else = false> = boolean extends IsExtend<T, string> ? Then : Else
1
+ export * from './CanAssign'
2
+ export type { Equal, IsEqual, IsNotEqual, NotEqual } from './Equal'
3
+ export type { Extendable, IsExtend, IsNotExtend, NotExtendable } from './Extends'
4
+ export type { If } from './If'
5
+ export * from './isType'
6
+ export type { And, Not, Or, Xor } from './logical'
7
+ export type { IsEmptyObject } from './IsEmptyObject'
8
+
9
+ import { IsExtend } from './Extends'
10
+
11
+ export type IsLiteral<T extends number | string, Then = true, Else = false> = number extends T ?
12
+ Else :
13
+ string extends T ? Else : Then
14
+
15
+ export type IsBoolean<T, Then = true, Else = false> = boolean extends T ? Then : Else
16
+
17
+ export type IsAny<T, Then = true, Else = false> = boolean extends IsExtend<T, string> ? Then : Else
@@ -1,4 +1,4 @@
1
1
  export * from './isPromise'
2
- export * from './PromiseValue'
3
- export * from './PromiseValueMerge'
2
+ export type { PromiseValue } from './PromiseValue'
3
+ export type { PromiseValueMerge } from './PromiseValueMerge'
4
4
  export * from './mapSeries'
package/ts/types/index.ts CHANGED
@@ -1,28 +1,28 @@
1
- /**
2
- * A turing complete solution inspired by many.
3
- * The types is in Pascal Cases
4
- * because lower case type names (e.g. true) is a reserved keyword.
5
- * https://github.com/microsoft/TypeScript/issues/14833
6
- * https://github.com/tycho01/typical
7
- */
8
-
9
- // export * from './BigInt'
10
- export * from './AllType'
11
- export * from './Any'
12
- export * from './Array'
13
- export * from './Boolean'
14
- export * from './check'
15
- export * from './conform'
16
- export * from './Generate'
17
- export { nil as null, Null } from './Null'
18
- export * from './Number'
19
- export { keys, object, ObjectType as Object } from './Object'
20
- export * from './Record'
21
- export * from './satisfy'
22
- export * from './String'
23
- export * from './Symbol'
24
- export * from './Tuple'
25
- export * from './types'
26
- export { undef as undefined, Undefined } from './Undefined'
27
- export * from './Union'
28
- export * from './Unknown'
1
+ /**
2
+ * A turing complete solution inspired by many.
3
+ * The types is in Pascal Cases
4
+ * because lower case type names (e.g. true) is a reserved keyword.
5
+ * https://github.com/microsoft/TypeScript/issues/14833
6
+ * https://github.com/tycho01/typical
7
+ */
8
+
9
+ // export * from './BigInt'
10
+ export type { AllType } from './AllType'
11
+ export * from './Any'
12
+ export * from './Array'
13
+ export * from './Boolean'
14
+ export * from './check'
15
+ export * from './conform'
16
+ export type { Generate } from './Generate'
17
+ export { nil as null, Null } from './Null'
18
+ export * from './Number'
19
+ export { keys, object, ObjectType as Object } from './Object'
20
+ export * from './Record'
21
+ export * from './satisfy'
22
+ export * from './String'
23
+ export * from './Symbol'
24
+ export * from './Tuple'
25
+ export * from './types'
26
+ export { undef as undefined, Undefined } from './Undefined'
27
+ export * from './Union'
28
+ export * from './Unknown'
package/ts/utils/index.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from './as'
2
- export * from './Widen'
1
+ export * from './as'
2
+ export type { Widen } from './Widen'
@@ -1 +0,0 @@
1
- {"version":3,"file":"isEmptyObject.js","sourceRoot":"","sources":["../../ts/predicates/isEmptyObject.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=isEmptyObject.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isEmptyObject.js","sourceRoot":"","sources":["../../ts/predicates/isEmptyObject.ts"],"names":[],"mappings":""}