@tempots/std 0.9.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 (132) hide show
  1. package/dist/arrays.d.ts +49 -0
  2. package/dist/arrays.js +249 -0
  3. package/dist/async-result.d.ts +37 -0
  4. package/dist/async-result.js +75 -0
  5. package/dist/bigint.d.ts +18 -0
  6. package/dist/bigint.js +110 -0
  7. package/dist/booleans.d.ts +23 -0
  8. package/dist/booleans.js +68 -0
  9. package/dist/colors/cmyk.d.ts +21 -0
  10. package/dist/colors/cmyk.js +54 -0
  11. package/dist/colors/convert.d.ts +283 -0
  12. package/dist/colors/convert.js +742 -0
  13. package/dist/colors/hsl.d.ts +24 -0
  14. package/dist/colors/hsl.js +56 -0
  15. package/dist/colors/hsla.d.ts +18 -0
  16. package/dist/colors/hsla.js +35 -0
  17. package/dist/colors/hsluv.d.ts +24 -0
  18. package/dist/colors/hsluv.js +56 -0
  19. package/dist/colors/hsv.d.ts +24 -0
  20. package/dist/colors/hsv.js +54 -0
  21. package/dist/colors/lab.d.ts +24 -0
  22. package/dist/colors/lab.js +54 -0
  23. package/dist/colors/lch.d.ts +19 -0
  24. package/dist/colors/lch.js +44 -0
  25. package/dist/colors/luv.d.ts +19 -0
  26. package/dist/colors/luv.js +45 -0
  27. package/dist/colors/rgb.d.ts +13 -0
  28. package/dist/colors/rgb.js +47 -0
  29. package/dist/colors/rgba.d.ts +12 -0
  30. package/dist/colors/rgba.js +44 -0
  31. package/dist/colors/srgb.d.ts +24 -0
  32. package/dist/colors/srgb.js +51 -0
  33. package/dist/colors/xyz.d.ts +19 -0
  34. package/dist/colors/xyz.js +41 -0
  35. package/dist/edit.d.ts +20 -0
  36. package/dist/edit.js +29 -0
  37. package/dist/equals.d.ts +3 -0
  38. package/dist/equals.js +122 -0
  39. package/dist/functions.d.ts +20 -0
  40. package/dist/functions.js +38 -0
  41. package/dist/json.d.ts +14 -0
  42. package/dist/json.js +33 -0
  43. package/dist/match.d.ts +16 -0
  44. package/dist/match.js +45 -0
  45. package/dist/maybe.d.ts +9 -0
  46. package/dist/maybe.js +25 -0
  47. package/dist/memoize.d.ts +1 -0
  48. package/dist/memoize.js +9 -0
  49. package/dist/newtype.d.ts +28 -0
  50. package/dist/newtype.js +29 -0
  51. package/dist/numbers.d.ts +104 -0
  52. package/dist/numbers.js +183 -0
  53. package/dist/objects.d.ts +9 -0
  54. package/dist/objects.js +33 -0
  55. package/dist/ord.d.ts +19 -0
  56. package/dist/ord.js +73 -0
  57. package/dist/reg-exps.d.ts +10 -0
  58. package/dist/reg-exps.js +43 -0
  59. package/dist/result.d.ts +31 -0
  60. package/dist/result.js +95 -0
  61. package/dist/strings.d.ts +314 -0
  62. package/dist/strings.js +685 -0
  63. package/dist/types/assert.d.ts +12 -0
  64. package/dist/types/assert.js +13 -0
  65. package/dist/types/differentiate.d.ts +13 -0
  66. package/dist/types/differentiate.js +14 -0
  67. package/dist/types/functions.d.ts +22 -0
  68. package/dist/types/functions.js +13 -0
  69. package/dist/types/generic.d.ts +9 -0
  70. package/dist/types/generic.js +13 -0
  71. package/dist/types/objects.d.ts +50 -0
  72. package/dist/types/objects.js +13 -0
  73. package/dist/types/tuples.d.ts +44 -0
  74. package/dist/types/tuples.js +24 -0
  75. package/dist/types/utility.d.ts +2 -0
  76. package/dist/types/utility.js +1 -0
  77. package/dist/uuid.d.ts +13 -0
  78. package/dist/uuid.js +56 -0
  79. package/dist/validation.d.ts +23 -0
  80. package/dist/validation.js +44 -0
  81. package/package.json +36 -0
  82. package/src/arrays.ts +296 -0
  83. package/src/async-result.ts +103 -0
  84. package/src/bigint.ts +111 -0
  85. package/src/booleans.ts +73 -0
  86. package/src/colors/cmyk.ts +84 -0
  87. package/src/colors/convert.ts +1093 -0
  88. package/src/colors/hsl.ts +73 -0
  89. package/src/colors/hsla.ts +45 -0
  90. package/src/colors/hsluv.ts +73 -0
  91. package/src/colors/hsv.ts +75 -0
  92. package/src/colors/lab.ts +69 -0
  93. package/src/colors/lch.ts +53 -0
  94. package/src/colors/luv.ts +56 -0
  95. package/src/colors/rgb.ts +55 -0
  96. package/src/colors/rgba.ts +53 -0
  97. package/src/colors/srgb.ts +72 -0
  98. package/src/colors/xyz.ts +52 -0
  99. package/src/edit.ts +29 -0
  100. package/src/equals.ts +116 -0
  101. package/src/functions.ts +108 -0
  102. package/src/json.ts +52 -0
  103. package/src/match.ts +88 -0
  104. package/src/maybe.ts +32 -0
  105. package/src/memoize.ts +9 -0
  106. package/src/newtype.ts +59 -0
  107. package/src/numbers.ts +222 -0
  108. package/src/objects.ts +47 -0
  109. package/src/ord.ts +79 -0
  110. package/src/reg-exps.ts +48 -0
  111. package/src/result.ts +140 -0
  112. package/src/strings.ts +768 -0
  113. package/src/types/assert.ts +96 -0
  114. package/src/types/differentiate.ts +89 -0
  115. package/src/types/functions.ts +114 -0
  116. package/src/types/generic.ts +42 -0
  117. package/src/types/objects.ts +212 -0
  118. package/src/types/tuples.ts +244 -0
  119. package/src/types/utility.ts +3 -0
  120. package/src/uuid.ts +61 -0
  121. package/src/validation.ts +69 -0
  122. package/test/arrays.spec.ts +410 -0
  123. package/test/colors.spec.ts +406 -0
  124. package/test/commmon.ts +9 -0
  125. package/test/equals.spec.ts +165 -0
  126. package/test/functions.spec.ts +9 -0
  127. package/test/index.d.ts +20 -0
  128. package/test/objects.spec.ts +22 -0
  129. package/test/reg-exps.spec.ts +33 -0
  130. package/test/strings.spec.ts +333 -0
  131. package/test/uuid.spec.ts +35 -0
  132. package/tsconfig.json +19 -0
@@ -0,0 +1,96 @@
1
+ /*
2
+ Copyright 2019 Google LLC
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ https://www.apache.org/licenses/LICENSE-2.0
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
12
+ */
13
+
14
+ /**
15
+ *
16
+ */
17
+
18
+ import { type Pointer } from './generic'
19
+
20
+ export type Assert<A extends true> = A extends never
21
+ ? 'FAIL'
22
+ : A extends true
23
+ ? 'PASS'
24
+ : 'FAIL'
25
+ export type AssertNot<A extends false> = A extends never
26
+ ? 'FAIL'
27
+ : A extends false
28
+ ? 'PASS'
29
+ : 'FAIL'
30
+
31
+ export type Extends<A, B> = A extends B ? true : false
32
+
33
+ // do not use with `any`
34
+ export type Same<A, B> = Pointer<A> extends Pointer<B>
35
+ ? Pointer<B> extends Pointer<A>
36
+ ? true
37
+ : false
38
+ : false
39
+
40
+ export type NotSame<A, B> = Pointer<A> extends Pointer<B>
41
+ ? Pointer<B> extends Pointer<A>
42
+ ? false
43
+ : true
44
+ : true
45
+
46
+ // does not work comparing intersection types with literals. Use `Same` for that.
47
+ export type Equals<A, B> = (<T>() => T extends A ? 1 : 2) extends <
48
+ T
49
+ >() => T extends B ? 1 : 2
50
+ ? true
51
+ : false
52
+
53
+ export type NotEquals<A, B> = Equals<A, B> extends true ? false : true
54
+
55
+ export type IsNever<T> = Pointer<T> extends Pointer<never> ? true : false
56
+
57
+ // TYPE TESTS
58
+ type _primitives_are_not_equals = AssertNot<Equals<number, string>>
59
+ type _primitives_are_not_same = AssertNot<Same<number, string>>
60
+ type _literals_are_equals = Assert<Equals<1, 1>>
61
+ type _literals_are_same = Assert<Same<1, 1>>
62
+ type _literals_are_notsame = Assert<NotSame<1, 2>>
63
+ type _any_is_not_equal_to_literal = Assert<NotEquals<any, 1>>
64
+ type _any_is_equal_to_any = Assert<Equals<any, any>>
65
+ type _union_is_not_equal_to_member = Assert<NotEquals<1 | 2, 1>>
66
+ type _any_is_not_equal_to_never = Assert<NotEquals<any, never>>
67
+ type _any_is_not_same_as_never = Assert<NotEquals<any, never>>
68
+ type _same_tuple_elements_match = Assert<Equals<[number], [number]>>
69
+ type _different_tuple_elements_do_not_match = Assert<NotEquals<[any], [string]>>
70
+ type _intersection_objects_are_same_as_literal = Assert<
71
+ Same<{ x: 1 } & { y: 2 }, { x: 1, y: 2 }>
72
+ >
73
+ type _intersection_objects_not_equal_to_literal = Assert<
74
+ NotEquals<{ x: 1 } & { y: 2 }, { x: 1, y: 2 }>
75
+ >
76
+ type _string_is_not_never = AssertNot<IsNever<string>>
77
+ type _never_is_never = Assert<IsNever<never>>
78
+
79
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
80
+ type _TESTS_ =
81
+ | _primitives_are_not_equals
82
+ | _primitives_are_not_same
83
+ | _literals_are_equals
84
+ | _literals_are_same
85
+ | _literals_are_notsame
86
+ | _any_is_not_equal_to_literal
87
+ | _any_is_equal_to_any
88
+ | _union_is_not_equal_to_member
89
+ | _any_is_not_equal_to_never
90
+ | _any_is_not_same_as_never
91
+ | _same_tuple_elements_match
92
+ | _different_tuple_elements_do_not_match
93
+ | _intersection_objects_are_same_as_literal
94
+ | _intersection_objects_not_equal_to_literal
95
+ | _string_is_not_never
96
+ | _never_is_never
@@ -0,0 +1,89 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ /*
3
+ Copyright 2019 Google LLC
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+ https://www.apache.org/licenses/LICENSE-2.0
8
+ Unless required by applicable law or agreed to in writing, software
9
+ distributed under the License is distributed on an "AS IS" BASIS,
10
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ See the License for the specific language governing permissions and
12
+ limitations under the License.
13
+ */
14
+
15
+ /**
16
+ *
17
+ */
18
+
19
+ import { type AnyKey } from './utility'
20
+ import { type ObjectWithField } from './objects'
21
+ import { type Tail } from './tuples'
22
+
23
+ // TYPE TESTS
24
+ import { type Assert, type AssertNot, type Equals, type Same } from './assert'
25
+
26
+ export type Differentiate<
27
+ Field extends AnyKey,
28
+ State extends ObjectWithField<Field, any>,
29
+ ExpectedType extends State[Field]
30
+ > = State extends ObjectWithField<Field, ExpectedType> ? State : never
31
+
32
+ export type DifferentiateByKind<
33
+ State extends { kind: any },
34
+ K extends State['kind']
35
+ > = Differentiate<'kind', State, K>
36
+
37
+ export type DifferentiateAt<
38
+ Path extends AnyKey[],
39
+ State,
40
+ ExpectedType
41
+ > = Path extends []
42
+ ? State
43
+ : Path extends [infer T]
44
+ ? T extends keyof State
45
+ ? ExpectedType extends State[T]
46
+ ? Differentiate<T, State, ExpectedType>
47
+ : never
48
+ : never
49
+ : Path extends [infer K, ...any[]]
50
+ ? K extends keyof State
51
+ ? Tail<Path> extends infer Rest
52
+ ? Rest extends AnyKey[]
53
+ ? State & { [k in K]: DifferentiateAt<Rest, State[k], ExpectedType> }
54
+ : never
55
+ : never
56
+ : never
57
+ : never
58
+
59
+ interface A { kind: 'A', a: string }
60
+ interface B { kind: 'B', b: string }
61
+ type AB = A | B
62
+
63
+ // DifferentiateByKind
64
+ type T0 = Differentiate<'kind', AB, 'A'>
65
+
66
+ type _T0_should_only_include_A = Assert<Equals<T0, A>>
67
+ type _T0_should_not_include_B = AssertNot<Equals<T0, B>>
68
+
69
+ // DifferentiateByKind
70
+ type T1 = DifferentiateByKind<AB, 'A'>
71
+
72
+ type _T1_should_only_include_A = Assert<Equals<T1, A>>
73
+ type _T1_should_not_include_B = AssertNot<Equals<T1, B>>
74
+
75
+ // DifferentiateAt
76
+ interface C { ab: AB, c: string }
77
+ type T2 = DifferentiateAt<['ab', 'kind'], C, 'A'>
78
+
79
+ type _T2_should_only_include_A = Assert<
80
+ Same<T2, { ab: { kind: 'A', a: string }, c: string }>
81
+ >
82
+
83
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
84
+ type _TESTS_ =
85
+ | _T0_should_only_include_A
86
+ | _T0_should_not_include_B
87
+ | _T1_should_only_include_A
88
+ | _T1_should_not_include_B
89
+ | _T2_should_only_include_A
@@ -0,0 +1,114 @@
1
+ /*
2
+ Copyright 2019 Google LLC
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ https://www.apache.org/licenses/LICENSE-2.0
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
12
+ */
13
+
14
+ /**
15
+ *
16
+ */
17
+
18
+ // TYPE TESTS
19
+ import { type Assert, type Equals, type Extends, type AssertNot, type IsNever } from './assert'
20
+ import { type Tail } from './tuples'
21
+
22
+ export type Equality<T> = (a: T, b: T) => boolean
23
+
24
+ export type Effect<T> = (value: T) => void
25
+
26
+ export type Proc = () => void
27
+
28
+ export type Lazy<T> = () => T
29
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
+ export type Fun = (...args: any[]) => any
31
+ export type Fun1<A, T> = (a1: A) => T
32
+ export type Fun2<A, B, T> = (a1: A, a2: B) => T
33
+ export type Fun3<A, B, C, T> = (a1: A, a2: B, a3: C) => T
34
+ export type Fun4<A, B, C, D, T> = (a1: A, a2: B, a3: C, a4: D) => T
35
+ export type Fun5<A, B, C, D, E, T> = (a1: A, a2: B, a3: C, a4: D, a5: E) => T
36
+ export type Fun6<A, B, C, D, E, F, T> = (
37
+ a1: A,
38
+ a2: B,
39
+ a3: C,
40
+ a4: D,
41
+ a5: E,
42
+ a6: F
43
+ ) => T
44
+
45
+ // eslint-disable-next-line @typescript-eslint/ban-types
46
+ export type AnyFunction = Fun | Function
47
+
48
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
49
+ export type FirstArgument<F extends AnyFunction> = F extends (a: infer A) => any
50
+ ? unknown extends A
51
+ ? never
52
+ : A
53
+ : never
54
+
55
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
56
+ export type OnlyIfDoesNotReturnNever<F extends Fun> = F extends Fun1<any, never>
57
+ ? never
58
+ : F
59
+
60
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
61
+ type CheckFunctionsChain<In, Args extends Array<Fun1<any, any>>> = {
62
+ empty: (i: In) => In
63
+ one: FirstArgument<Args[0]> extends In ? Args[0] : never
64
+ n: FirstArgument<Args[0]> extends In
65
+ ? (
66
+ arg: FirstArgument<Args[0]>
67
+ ) => ReturnType<CheckFunctionsChain<ReturnType<Args[0]>, Tail<Args>>>
68
+ : never
69
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
70
+ }[Args extends [] ? 'empty' : Args extends [any] ? 'one' : 'n']
71
+
72
+ export type FunctionsChain<In, Args extends Fun[]> = OnlyIfDoesNotReturnNever<
73
+ CheckFunctionsChain<In, Args>
74
+ >
75
+ type _procedure_is_AnyFunction = Assert<Extends<() => void, AnyFunction>>
76
+ // eslint-disable-next-line @typescript-eslint/ban-types
77
+ type _Function_is_AnyFunction = Assert<Extends<Function, AnyFunction>>
78
+ type _string_is_not_AnyFunction = AssertNot<Extends<string, AnyFunction>>
79
+
80
+ type _first_argument_matches_type = Assert<
81
+ Equals<FirstArgument<(a: string) => number>, string>
82
+ >
83
+ type _first_argument_does_not_exist = Assert<
84
+ IsNever<FirstArgument<() => number>>
85
+ >
86
+
87
+ type _chain_matches_first_arg_and_last_return_type = Assert<
88
+ Equals<
89
+ FunctionsChain<
90
+ string,
91
+ [(s: string) => boolean, (b: boolean) => number, (n: number) => Date]
92
+ >,
93
+ Fun1<string, Date>
94
+ >
95
+ >
96
+
97
+ type _chain_is_never_when_does_not_check_out = Assert<
98
+ IsNever<
99
+ FunctionsChain<
100
+ string,
101
+ [(s: string) => boolean, (b: number) => number, (n: number) => Date]
102
+ >
103
+ >
104
+ >
105
+
106
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
107
+ type _TESTS_ =
108
+ | _procedure_is_AnyFunction
109
+ | _Function_is_AnyFunction
110
+ | _string_is_not_AnyFunction
111
+ | _first_argument_matches_type
112
+ | _first_argument_does_not_exist
113
+ | _chain_matches_first_arg_and_last_return_type
114
+ | _chain_is_never_when_does_not_check_out
@@ -0,0 +1,42 @@
1
+ /*
2
+ Copyright 2019 Google LLC
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ https://www.apache.org/licenses/LICENSE-2.0
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
12
+ */
13
+
14
+ /**
15
+ *
16
+ */
17
+
18
+ import { type Equals, type NotEquals, type Assert } from './assert'
19
+
20
+ export type Pointer<T> = () => T
21
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
+ export type DeRef<T extends () => any> = T extends () => infer Ret ? Ret : never
23
+
24
+ export type WhenEquals<X, Y, A = X, B = never> = Equals<X, Y> extends true
25
+ ? A
26
+ : B
27
+
28
+ export type WhenNotEquals<X, Y, A = X, B = never> = NotEquals<X, Y> extends true
29
+ ? A
30
+ : B
31
+
32
+ export type Cast<A, B> = A extends B ? A : B
33
+
34
+ type _when_true_returns_A = Assert<
35
+ Equals<WhenEquals<string, string, number, boolean>, number>
36
+ >
37
+ type _when_false_returns_B = Assert<
38
+ Equals<WhenEquals<string, number, number, boolean>, boolean>
39
+ >
40
+
41
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
42
+ type _TESTS_ = _when_true_returns_A | _when_false_returns_B
@@ -0,0 +1,212 @@
1
+ /*
2
+ Copyright 2019 Google LLC
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ https://www.apache.org/licenses/LICENSE-2.0
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
12
+ */
13
+
14
+ /**
15
+ *
16
+ */
17
+
18
+ import { type AnyKey } from './utility'
19
+ import { type Tail } from './tuples'
20
+ import { type AnyFunction } from './functions'
21
+
22
+ // TYPE TESTS
23
+ import { type Assert, type Equals, type AssertNot } from './assert'
24
+ import { type WhenEquals } from './generic'
25
+
26
+ export type ObjectWithField<F extends AnyKey, V> = { [_ in F]: V }
27
+
28
+ export type ObjectWithPath<Path extends AnyKey[], V> = Path extends []
29
+ ? // eslint-disable-next-line @typescript-eslint/ban-types
30
+ {}
31
+ : Path extends [infer T]
32
+ ? T extends AnyKey
33
+ ? { [_ in T]: V }
34
+ : never
35
+ : // eslint-disable-next-line @typescript-eslint/no-explicit-any
36
+ Path extends [infer K, ...any[]]
37
+ ? K extends AnyKey
38
+ ? Tail<Path> extends infer Rest
39
+ ? Rest extends AnyKey[]
40
+ ? { [_ in K]: ObjectWithPath<Rest, V> }
41
+ : never
42
+ : never
43
+ : never
44
+ : never
45
+
46
+ export type TypeAtPath<Path extends AnyKey[], O> = {
47
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
48
+ next: Path extends [infer K, ...any[]]
49
+ ? K extends AnyKey
50
+ ? Tail<Path> extends infer Rest
51
+ ? // eslint-disable-next-line @typescript-eslint/no-explicit-any
52
+ O extends Record<AnyKey, any>
53
+ ? Rest extends AnyKey[]
54
+ ? TypeAtPath<Rest, O[K]>
55
+ : never
56
+ : never
57
+ : never
58
+ : never
59
+ : never
60
+ empty: O
61
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
62
+ done: O extends Record<AnyKey, any>
63
+ ? Path extends [infer K]
64
+ ? K extends AnyKey
65
+ ? O[K]
66
+ : never
67
+ : never
68
+ : never
69
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
70
+ }[Path extends [] ? 'empty' : Path extends [any] ? 'done' : 'next']
71
+
72
+ export type WritableKeys<T> = {
73
+ [K in keyof T]-?: WhenEquals<
74
+ { [Q in K]: T[K] },
75
+ { -readonly [Q in K]: T[K] },
76
+ K
77
+ >
78
+ }[keyof T]
79
+
80
+ export type ReadonlyKeys<T> = {
81
+ [P in keyof T]-?: WhenEquals<
82
+ { [Q in P]: T[P] },
83
+ { -readonly [Q in P]: T[P] },
84
+ never,
85
+ P
86
+ >
87
+ }[keyof T]
88
+
89
+ // eslint-disable-next-line @typescript-eslint/ban-types
90
+ export type Id<T> = {} & { [P in keyof T]: T[P] }
91
+
92
+ export type KeysWithFieldType<T, Condition> = {
93
+ [K in keyof T]: WhenEquals<T[K], Condition, K>
94
+ }[keyof T]
95
+
96
+ export type KeysWithoutFieldType<T, Condition> = {
97
+ [K in keyof T]: WhenEquals<T[K], Condition, never, K>
98
+ }[keyof T]
99
+
100
+ export type RemoveNullableFromFields<T> = {
101
+ [K in keyof T]: NonNullable<T[K]>
102
+ }
103
+
104
+ export type WritableFields<T> = Pick<T, WritableKeys<T>>
105
+ export type ReadonlyFields<T> = Pick<T, ReadonlyKeys<T>>
106
+ export type ExcludeFunctionFields<T> = Pick<
107
+ T,
108
+ KeysWithoutFieldType<T, AnyFunction>
109
+ >
110
+
111
+ export type Merge<A, B> = Id<A & B>
112
+
113
+ type _merged_ = Merge<{ a: string, c?: number }, { b?: boolean }>
114
+ type _merge_two_object_types_ = Assert<
115
+ Equals<_merged_, { a: string, b?: boolean, c?: number }>
116
+ >
117
+
118
+ type _object_with_field_has_field = Assert<
119
+ Equals<{ a: number }, ObjectWithField<'a', number>>
120
+ >
121
+ type _object_with_field_has_no_field = AssertNot<
122
+ Equals<{ a: number }, ObjectWithField<'c', number>>
123
+ >
124
+
125
+ type _object_with_empty_path_is_empty_object = Assert<
126
+ // eslint-disable-next-line @typescript-eslint/ban-types
127
+ Equals<{}, ObjectWithPath<[], number>>
128
+ >
129
+ type _object_with_tuple_of_one_is_object = Assert<
130
+ Equals<{ a: number }, ObjectWithPath<['a'], number>>
131
+ >
132
+ type _object_with_tuple_of_two_is_object = Assert<
133
+ Equals<{ a: { b: number } }, ObjectWithPath<['a', 'b'], number>>
134
+ >
135
+ type _object_with_tuple_of_three_is_object = Assert<
136
+ Equals<{ a: { b: { c: number } } }, ObjectWithPath<['a', 'b', 'c'], number>>
137
+ >
138
+
139
+ interface _nested { a: { b: boolean[], c: number }, d: string }
140
+ type _type_at_empty_path_is_type_of_argument = Assert<
141
+ Equals<_nested, TypeAtPath<[], _nested>>
142
+ >
143
+ type _type_at_level_1 = Assert<
144
+ Equals<{ b: boolean[], c: number }, TypeAtPath<['a'], _nested>>
145
+ >
146
+ type _type_at_level_2 = Assert<
147
+ Equals<boolean[], TypeAtPath<['a', 'b'], _nested>>
148
+ >
149
+ type _type_at_level_3 = Assert<
150
+ Equals<boolean, TypeAtPath<['a', 'b', number], _nested>>
151
+ >
152
+
153
+ // eslint-disable-next-line @typescript-eslint/ban-types
154
+ type _writable_keys_of_empty_is_never = Assert<Equals<WritableKeys<{}>, never>>
155
+ type _writable_keys_of_writable_is_keys = Assert<
156
+ Equals<WritableKeys<{ a: string, b: string }>, 'a' | 'b'>
157
+ >
158
+ type _writable_keys_of_mixed_is_subset = Assert<
159
+ Equals<WritableKeys<{ a: string, b: string, readonly c: number }>, 'a' | 'b'>
160
+ >
161
+
162
+ // eslint-disable-next-line @typescript-eslint/ban-types
163
+ type _readonly_keys_of_empty_is_never = Assert<Equals<ReadonlyKeys<{}>, never>>
164
+ type _readonly_keys_of_readonly_is_keys = Assert<
165
+ Equals<ReadonlyKeys<{ readonly a: string, readonly b: string }>, 'a' | 'b'>
166
+ >
167
+ type _readonly_keys_of_mixed_is_subset = Assert<
168
+ Equals<
169
+ ReadonlyKeys<{ readonly a: string, readonly b: string, c: number }>,
170
+ 'a' | 'b'
171
+ >
172
+ >
173
+
174
+ type _KeysWithFieldType_matches = Assert<
175
+ Equals<KeysWithFieldType<{ a: string, b: number }, string>, 'a'>
176
+ >
177
+ type _KeysWithoutFieldType_matches = Assert<
178
+ Equals<KeysWithoutFieldType<{ a: string, b: number }, number>, 'a'>
179
+ >
180
+ type _RemoveNullableFromFields_matches = Assert<
181
+ Equals<
182
+ RemoveNullableFromFields<{
183
+ a: string | null | undefined
184
+ b: number | null
185
+ c: boolean
186
+ }>,
187
+ { a: string, b: number, c: boolean }
188
+ >
189
+ >
190
+
191
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
192
+ type _TESTS_ =
193
+ | _merge_two_object_types_
194
+ | _object_with_field_has_field
195
+ | _object_with_field_has_no_field
196
+ | _object_with_empty_path_is_empty_object
197
+ | _object_with_tuple_of_one_is_object
198
+ | _object_with_tuple_of_two_is_object
199
+ | _object_with_tuple_of_three_is_object
200
+ | _type_at_empty_path_is_type_of_argument
201
+ | _type_at_level_1
202
+ | _type_at_level_2
203
+ | _type_at_level_3
204
+ | _writable_keys_of_empty_is_never
205
+ | _writable_keys_of_writable_is_keys
206
+ | _writable_keys_of_mixed_is_subset
207
+ | _readonly_keys_of_empty_is_never
208
+ | _readonly_keys_of_readonly_is_keys
209
+ | _readonly_keys_of_mixed_is_subset
210
+ | _KeysWithFieldType_matches
211
+ | _KeysWithoutFieldType_matches
212
+ | _RemoveNullableFromFields_matches