@sohanemon/utils 5.1.4 → 5.1.6

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.
@@ -0,0 +1,133 @@
1
+ import { Without } from './utilities';
2
+ export type BUFFER<T> = T;
3
+ export type IMPLIES<T, U> = T extends U ? true : false;
4
+ export type XOR_Binary<T, U> = T | U extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;
5
+ export type XNOR_Binary<T, U> = (T & U) | (Without<T, U> & Without<U, T>);
6
+ /**
7
+ * Computes a type-level AND for a tuple of types.
8
+ *
9
+ * Truth table for 3 arguments:
10
+ *
11
+ * A B C = AND
12
+ * 1 1 1 = 1
13
+ * 1 1 0 = 0
14
+ * 1 0 1 = 0
15
+ * 1 0 0 = 0
16
+ * 0 1 1 = 0
17
+ * 0 1 0 = 0
18
+ * 0 0 1 = 0
19
+ * 0 0 0 = 0
20
+ *
21
+ * @template T - Tuple of boolean-like types (1/0)
22
+ */
23
+ export type AND<T extends any[]> = T extends [infer F, ...infer R] ? R extends any[] ? F & AND<R> : F : unknown;
24
+ /**
25
+ * Computes a type-level OR for a tuple of types.
26
+ *
27
+ * Truth table for 3 arguments:
28
+ *
29
+ * A B C = OR
30
+ * 1 1 1 = 1
31
+ * 1 1 0 = 1
32
+ * 1 0 1 = 1
33
+ * 1 0 0 = 1
34
+ * 0 1 1 = 1
35
+ * 0 1 0 = 1
36
+ * 0 0 1 = 1
37
+ * 0 0 0 = 0
38
+ *
39
+ * @template T - Tuple of boolean-like types (1/0)
40
+ */
41
+ export type OR<T extends any[]> = T extends [infer F, ...infer R] ? R extends any[] ? F | OR<R> : F : never;
42
+ /**
43
+ * Computes a type-level XOR for a tuple of types.
44
+ *
45
+ * Truth table for 3 arguments:
46
+ *
47
+ * A B C = XOR
48
+ * 1 1 1 = 1
49
+ * 1 1 0 = 0
50
+ * 1 0 1 = 0
51
+ * 1 0 0 = 1
52
+ * 0 1 1 = 0
53
+ * 0 1 0 = 1
54
+ * 0 0 1 = 1
55
+ * 0 0 0 = 0
56
+ *
57
+ * @template T - Tuple of boolean-like types (1/0)
58
+ */
59
+ export type XOR<T extends any[]> = T extends [infer F, ...infer R] ? R extends [infer S, ...infer Rest] ? XOR<[XOR_Binary<F, S>, ...Rest]> : F : never;
60
+ /**
61
+ * Computes a type-level XNOR for a tuple of types.
62
+ *
63
+ * Truth table for 3 arguments:
64
+ *
65
+ * A B C = XNOR
66
+ * 1 1 1 = 0
67
+ * 1 1 0 = 1
68
+ * 1 0 1 = 1
69
+ * 1 0 0 = 0
70
+ * 0 1 1 = 1
71
+ * 0 1 0 = 0
72
+ * 0 0 1 = 0
73
+ * 0 0 0 = 1
74
+ *
75
+ * @template T - Tuple of boolean-like types (1/0)
76
+ */
77
+ export type XNOR<T extends any[]> = T extends [infer F, ...infer R] ? R extends [infer S, ...infer Rest] ? XNOR<[XNOR_Binary<F, S>, ...Rest]> : F : never;
78
+ /**
79
+ * Computes a type-level NOT for a tuple of types.
80
+ *
81
+ * Truth table for 3 arguments:
82
+ *
83
+ * A B C = NOT
84
+ * 1 1 1 = 0
85
+ * 1 1 0 = 0
86
+ * 1 0 1 = 0
87
+ * 1 0 0 = 0
88
+ * 0 1 1 = 0
89
+ * 0 1 0 = 0
90
+ * 0 0 1 = 0
91
+ * 0 0 0 = 1
92
+ *
93
+ * @template T - Tuple of boolean-like types (1/0)
94
+ */
95
+ export type NOT<T> = {
96
+ [P in keyof T]?: never;
97
+ };
98
+ /**
99
+ * Computes a type-level NAND for a tuple of types.
100
+ *
101
+ * Truth table for 3 arguments:
102
+ *
103
+ * A B C = NAND
104
+ * 1 1 1 = 0
105
+ * 1 1 0 = 1
106
+ * 1 0 1 = 1
107
+ * 1 0 0 = 1
108
+ * 0 1 1 = 1
109
+ * 0 1 0 = 1
110
+ * 0 0 1 = 1
111
+ * 0 0 0 = 1
112
+ *
113
+ * @template T - Tuple of boolean-like types (1/0)
114
+ */
115
+ export type NAND<T extends any[]> = NOT<AND<T>>;
116
+ /**
117
+ * Computes a type-level NOR for a tuple of types.
118
+ *
119
+ * Truth table for 3 arguments:
120
+ *
121
+ * A B C = NOR
122
+ * 1 1 1 = 0
123
+ * 1 1 0 = 0
124
+ * 1 0 1 = 0
125
+ * 1 0 0 = 0
126
+ * 0 1 1 = 0
127
+ * 0 1 0 = 0
128
+ * 0 0 1 = 0
129
+ * 0 0 0 = 1
130
+ *
131
+ * @template T - Tuple of boolean-like types (1/0)
132
+ */
133
+ export type NOR<T extends any[]> = NOT<OR<T>>;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,2 +1,3 @@
1
+ export * from './gates';
1
2
  export * from './guards';
2
3
  export * from './utilities';
@@ -1,2 +1,3 @@
1
+ export * from './gates';
1
2
  export * from './guards';
2
3
  export * from './utilities';
@@ -56,3 +56,6 @@ export type Prettify<T> = {
56
56
  export type NestedKeyOf<ObjectType extends object, IgnoreKeys extends string = never> = {
57
57
  [Key in keyof ObjectType & string]: Key extends IgnoreKeys ? never : ObjectType[Key] extends object ? ObjectType[Key] extends Array<any> ? Key : `${Key}` | `${Key}.${NestedKeyOf<ObjectType[Key], IgnoreKeys>}` : `${Key}`;
58
58
  }[keyof ObjectType & string];
59
+ export type Without<T, U> = {
60
+ [P in Exclude<keyof T, keyof U>]?: never;
61
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sohanemon/utils",
3
- "version": "5.1.4",
3
+ "version": "5.1.6",
4
4
  "author": "Sohan Emon <sohanemon@outlook.com>",
5
5
  "description": "",
6
6
  "type": "module",