-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
77 lines (67 loc) · 1.47 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import {
If,
Not,
And,
Or
} from 'typescript-logic'
export type Extends<A, B> = Or<
Any<B>,
If<Any<A>,
Any<B>,
prv.Extends<A, B>
>
>
export type Compare<A, B, Options extends Compare.Options = Compare.Options.Default> =
If<Extends<A, B>,
If<Extends<B, A>,
Options['equal' | 'broaderRight' | 'broaderLeft'],
Options['broaderRight']
>,
If<Extends<B, A>,
Options['broaderLeft'],
Options['mismatch']
>
>
export namespace Compare {
export type Strict<A, B, Options extends Compare.Options = Compare.Options.Default> =
If<Extends<A, B>,
If<Extends<B, A>,
Options['equal'],
Options['broaderRight']
>,
If<Extends<B, A>,
Options['broaderLeft'],
Options['mismatch']
>
>
export interface Options {
broaderLeft: any
broaderRight: any
equal: any,
mismatch: any
}
export namespace Options {
export interface Default extends Compare.Options {
broaderLeft: 'broaderLeft'
broaderRight: 'broaderRight'
equal: 'equal',
mismatch: 'mismatch'
}
}
}
export type Equal<A, B> = Or<
And<Any<A>, Any<B>>,
And<
And<NotAny<A>, NotAny<B>>,
And<Extends<A, B>, Extends<B, A>>
>
>
export type NotEqual<A, B> = Not<Equal<A, B>>
export type Any<Type> = And<
prv.Extends<Type, 0>,
prv.Extends<Type, 1>
>
export type NotAny<Type> = Not<Any<Type>>
namespace prv {
export type Extends<A, B> = [A] extends [B] ? true : false
}