decoders 2.0.0-beta1 → 2.0.0-beta13
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.
- package/CHANGELOG.md +53 -5
- package/Decoder.d.ts +94 -0
- package/Decoder.js +222 -0
- package/Decoder.js.flow +286 -0
- package/Decoder.mjs +215 -0
- package/NotSupportedTSVersion.d.ts +1 -0
- package/README.md +124 -961
- package/_utils.d.ts +9 -0
- package/{cjs/_utils.js → _utils.js} +12 -18
- package/{cjs/_utils.js.flow → _utils.js.flow} +15 -19
- package/{es/_utils.js → _utils.mjs} +11 -15
- package/{ts/annotate.d.ts → annotate.d.ts} +25 -21
- package/{cjs/annotate.js → annotate.js} +0 -0
- package/{cjs/annotate.js.flow → annotate.js.flow} +0 -0
- package/{es/annotate.js → annotate.mjs} +0 -0
- package/format.d.ts +6 -0
- package/{cjs/format/inline.js → format.js} +7 -2
- package/{cjs/format/inline.js.flow → format.js.flow} +9 -3
- package/{es/format/inline.js → format.mjs} +5 -2
- package/index.d.ts +40 -0
- package/index.js +89 -0
- package/index.js.flow +44 -0
- package/index.mjs +11 -0
- package/{ts → lib}/_helpers.d.ts +0 -0
- package/lib/arrays.d.ts +59 -0
- package/lib/arrays.js +139 -0
- package/lib/arrays.js.flow +138 -0
- package/lib/arrays.mjs +124 -0
- package/lib/basics.d.ts +93 -0
- package/lib/basics.js +144 -0
- package/lib/basics.js.flow +124 -0
- package/lib/basics.mjs +120 -0
- package/lib/booleans.d.ts +16 -0
- package/lib/booleans.js +35 -0
- package/lib/booleans.js.flow +22 -0
- package/lib/booleans.mjs +25 -0
- package/lib/dates.d.ts +15 -0
- package/lib/dates.js +44 -0
- package/lib/dates.js.flow +40 -0
- package/lib/dates.mjs +34 -0
- package/lib/json.d.ts +35 -0
- package/lib/json.js +55 -0
- package/lib/json.js.flow +50 -0
- package/lib/json.mjs +40 -0
- package/lib/numbers.d.ts +31 -0
- package/lib/numbers.js +51 -0
- package/lib/numbers.js.flow +48 -0
- package/lib/numbers.mjs +41 -0
- package/lib/objects.d.ts +75 -0
- package/lib/objects.js +240 -0
- package/lib/objects.js.flow +246 -0
- package/lib/objects.mjs +223 -0
- package/lib/strings.d.ts +56 -0
- package/lib/strings.js +101 -0
- package/lib/strings.js.flow +90 -0
- package/lib/strings.mjs +82 -0
- package/lib/unions.d.ts +55 -0
- package/lib/unions.js +160 -0
- package/lib/unions.js.flow +155 -0
- package/lib/unions.mjs +146 -0
- package/lib/utilities.d.ts +34 -0
- package/lib/utilities.js +75 -0
- package/lib/utilities.js.flow +65 -0
- package/lib/utilities.mjs +60 -0
- package/package.json +79 -29
- package/result.d.ts +16 -0
- package/result.js +34 -0
- package/result.js.flow +26 -0
- package/result.mjs +27 -0
- package/cjs/_guard.js +0 -26
- package/cjs/_guard.js.flow +0 -20
- package/cjs/_types.js +0 -1
- package/cjs/_types.js.flow +0 -20
- package/cjs/format/index.js +0 -12
- package/cjs/format/index.js.flow +0 -4
- package/cjs/format/short.js +0 -10
- package/cjs/format/short.js.flow +0 -8
- package/cjs/index.js +0 -120
- package/cjs/index.js.flow +0 -63
- package/cjs/result.js +0 -172
- package/cjs/result.js.flow +0 -166
- package/cjs/stdlib/array.js +0 -108
- package/cjs/stdlib/array.js.flow +0 -103
- package/cjs/stdlib/boolean.js +0 -44
- package/cjs/stdlib/boolean.js.flow +0 -29
- package/cjs/stdlib/composition.js +0 -56
- package/cjs/stdlib/composition.js.flow +0 -43
- package/cjs/stdlib/constants.js +0 -69
- package/cjs/stdlib/constants.js.flow +0 -46
- package/cjs/stdlib/date.js +0 -46
- package/cjs/stdlib/date.js.flow +0 -40
- package/cjs/stdlib/describe.js +0 -26
- package/cjs/stdlib/describe.js.flow +0 -17
- package/cjs/stdlib/dispatch.js +0 -62
- package/cjs/stdlib/dispatch.js.flow +0 -58
- package/cjs/stdlib/either.js +0 -117
- package/cjs/stdlib/either.js.flow +0 -151
- package/cjs/stdlib/fail.js +0 -21
- package/cjs/stdlib/fail.js.flow +0 -12
- package/cjs/stdlib/instanceOf.js +0 -19
- package/cjs/stdlib/instanceOf.js.flow +0 -20
- package/cjs/stdlib/json.js +0 -31
- package/cjs/stdlib/json.js.flow +0 -28
- package/cjs/stdlib/lazy.js +0 -16
- package/cjs/stdlib/lazy.js.flow +0 -15
- package/cjs/stdlib/mapping.js +0 -67
- package/cjs/stdlib/mapping.js.flow +0 -54
- package/cjs/stdlib/number.js +0 -40
- package/cjs/stdlib/number.js.flow +0 -34
- package/cjs/stdlib/object.js +0 -194
- package/cjs/stdlib/object.js.flow +0 -203
- package/cjs/stdlib/optional.js +0 -54
- package/cjs/stdlib/optional.js.flow +0 -41
- package/cjs/stdlib/string.js +0 -98
- package/cjs/stdlib/string.js.flow +0 -82
- package/cjs/stdlib/tuple.js +0 -173
- package/cjs/stdlib/tuple.js.flow +0 -220
- package/es/_guard.js +0 -15
- package/es/_types.js +0 -0
- package/es/format/index.js +0 -2
- package/es/format/short.js +0 -4
- package/es/index.js +0 -37
- package/es/result.js +0 -139
- package/es/stdlib/array.js +0 -91
- package/es/stdlib/boolean.js +0 -28
- package/es/stdlib/composition.js +0 -42
- package/es/stdlib/constants.js +0 -46
- package/es/stdlib/date.js +0 -28
- package/es/stdlib/describe.js +0 -16
- package/es/stdlib/dispatch.js +0 -51
- package/es/stdlib/either.js +0 -90
- package/es/stdlib/fail.js +0 -11
- package/es/stdlib/instanceOf.js +0 -8
- package/es/stdlib/json.js +0 -15
- package/es/stdlib/lazy.js +0 -11
- package/es/stdlib/mapping.js +0 -54
- package/es/stdlib/number.js +0 -25
- package/es/stdlib/object.js +0 -175
- package/es/stdlib/optional.js +0 -38
- package/es/stdlib/string.js +0 -76
- package/es/stdlib/tuple.js +0 -155
- package/ts/_guard.d.ts +0 -7
- package/ts/_types.d.ts +0 -16
- package/ts/_utils.d.ts +0 -13
- package/ts/array.d.ts +0 -5
- package/ts/boolean.d.ts +0 -5
- package/ts/constants.d.ts +0 -11
- package/ts/date.d.ts +0 -4
- package/ts/describe.d.ts +0 -3
- package/ts/dispatch.d.ts +0 -8
- package/ts/either.d.ts +0 -61
- package/ts/fail.d.ts +0 -3
- package/ts/index.d.ts +0 -42
- package/ts/inline.d.ts +0 -3
- package/ts/instanceOf.d.ts +0 -3
- package/ts/json.d.ts +0 -11
- package/ts/lazy.d.ts +0 -3
- package/ts/mapping.d.ts +0 -4
- package/ts/number.d.ts +0 -6
- package/ts/object.d.ts +0 -33
- package/ts/optional.d.ts +0 -5
- package/ts/result.d.ts +0 -39
- package/ts/short.d.ts +0 -3
- package/ts/string.d.ts +0 -7
- package/ts/tuple.d.ts +0 -30
package/es/stdlib/string.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import * as Result from '../result';
|
|
2
|
-
import { annotate } from '../annotate';
|
|
3
|
-
import { compose, predicate } from './composition';
|
|
4
|
-
|
|
5
|
-
/** Match groups in this regex:
|
|
6
|
-
* \1 - the scheme
|
|
7
|
-
* \2 - the username/password (optional)
|
|
8
|
-
* \3 - the host
|
|
9
|
-
* \4 - the port (optional)
|
|
10
|
-
* \5 - the path (optional)
|
|
11
|
-
*/
|
|
12
|
-
var url_re = /^([A-Za-z]{3,9}(?:[+][A-Za-z]{3,9})?):\/\/(?:([-;:&=+$,\w]+)@)?(?:([A-Za-z0-9.-]+)(?::([0-9]{2,5}))?)(\/(?:[-+~%/.,\w]*)?(?:\?[-+=&;%@.,\w]*)?(?:#[.,!/\w]*)?)?$/; // The URL schemes the url() decoder accepts by default
|
|
13
|
-
|
|
14
|
-
var DEFAULT_SCHEMES = ['https'];
|
|
15
|
-
/**
|
|
16
|
-
* Decoder that only returns Ok for string inputs. Err otherwise.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
export var string = function string(blob) {
|
|
20
|
-
return typeof blob === 'string' ? Result.ok(blob) : Result.err(annotate(blob, 'Must be string'));
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* Decoder that only returns Ok for non-empty string inputs. Err otherwise.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
export var nonEmptyString = regex(/\S/, 'Must be non-empty string');
|
|
27
|
-
/**
|
|
28
|
-
* Decoder that only returns Ok for string inputs that match the regular
|
|
29
|
-
* expression. Err otherwise. Will always validate that the input is a string
|
|
30
|
-
* before testing the regex.
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
export function regex(regex, msg) {
|
|
34
|
-
return compose(string, predicate(function (s) {
|
|
35
|
-
return regex.test(s);
|
|
36
|
-
}, msg));
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Decoder that only returns Ok for string inputs that match the almost perfect
|
|
40
|
-
* email regex, taken from http://emailregex.com. Err otherwise.
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
export var email = regex(/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/, 'Must be email');
|
|
44
|
-
/**
|
|
45
|
-
* Decoder that only returns Ok for string inputs that match URLs of the
|
|
46
|
-
* expected scheme. Defaults to only accept HTTPS URLs. Err otherwise.
|
|
47
|
-
*
|
|
48
|
-
* Variants that can be used:
|
|
49
|
-
*
|
|
50
|
-
* - url() accepts only https:// URLs
|
|
51
|
-
* - url([]) accepts any URL scheme
|
|
52
|
-
* - url(['http']) accepts only HTTP
|
|
53
|
-
* - url(['https', 'git+ssh']) accepts both https:// and git+ssh:// URLs
|
|
54
|
-
*/
|
|
55
|
-
|
|
56
|
-
export var url = function url(schemes) {
|
|
57
|
-
if (schemes === void 0) {
|
|
58
|
-
schemes = DEFAULT_SCHEMES;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return compose(string, function (value) {
|
|
62
|
-
var matches = value.match(url_re);
|
|
63
|
-
|
|
64
|
-
if (!matches) {
|
|
65
|
-
return Result.err(annotate(value, 'Must be URL'));
|
|
66
|
-
} else {
|
|
67
|
-
var scheme = matches[1];
|
|
68
|
-
|
|
69
|
-
if (schemes.length === 0 || schemes.includes(scheme.toLowerCase())) {
|
|
70
|
-
return Result.ok(value);
|
|
71
|
-
} else {
|
|
72
|
-
return Result.err(annotate(value, "URL scheme must be any of: " + schemes.join(', ')));
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
};
|
package/es/stdlib/tuple.js
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import { annotate } from '../annotate';
|
|
2
|
-
import { compose, predicate } from './composition';
|
|
3
|
-
import { err, errValue, isErr, ok, unwrap, value } from '../result';
|
|
4
|
-
import { poja } from './array';
|
|
5
|
-
|
|
6
|
-
var ntuple = function ntuple(n) {
|
|
7
|
-
return compose(poja, predicate(function (arr) {
|
|
8
|
-
return arr.length === n;
|
|
9
|
-
}, "Must be a " + n + "-tuple"));
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Builds a Decoder that returns Ok for 1-tuple of [T], given a Decoder for T.
|
|
13
|
-
* Err otherwise.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export function tuple1(decoder1) {
|
|
18
|
-
return compose(ntuple(1), function (blobs) {
|
|
19
|
-
var blob1 = blobs[0];
|
|
20
|
-
var result1 = decoder1(blob1);
|
|
21
|
-
|
|
22
|
-
try {
|
|
23
|
-
return ok([unwrap(result1)]);
|
|
24
|
-
} catch (e) {
|
|
25
|
-
// If a decoder error has happened while unwrapping all the
|
|
26
|
-
// results, try to construct a good error message
|
|
27
|
-
return err(annotate(errValue(result1)));
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Builds a Decoder that returns Ok for 2-tuples of [T1, T2], given Decoders
|
|
33
|
-
* for T1 and T2. Err otherwise.
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
export function tuple2(decoder1, decoder2) {
|
|
37
|
-
return compose(ntuple(2), function (blobs) {
|
|
38
|
-
var blob1 = blobs[0],
|
|
39
|
-
blob2 = blobs[1];
|
|
40
|
-
var result1 = decoder1(blob1);
|
|
41
|
-
var result2 = decoder2(blob2);
|
|
42
|
-
|
|
43
|
-
try {
|
|
44
|
-
return ok([unwrap(result1), unwrap(result2)]);
|
|
45
|
-
} catch (e) {
|
|
46
|
-
// If a decoder error has happened while unwrapping all the
|
|
47
|
-
// results, try to construct a good error message
|
|
48
|
-
return err(annotate([isErr(result1) ? errValue(result1) : value(result1), isErr(result2) ? errValue(result2) : value(result2)]));
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Builds a Decoder that returns Ok for 3-tuples of [T1, T2, T3], given
|
|
54
|
-
* Decoders for T1, T2, and T3. Err otherwise.
|
|
55
|
-
*/
|
|
56
|
-
|
|
57
|
-
export function tuple3(decoder1, decoder2, decoder3) {
|
|
58
|
-
return compose(ntuple(3), function (blobs) {
|
|
59
|
-
var blob1 = blobs[0],
|
|
60
|
-
blob2 = blobs[1],
|
|
61
|
-
blob3 = blobs[2];
|
|
62
|
-
var result1 = decoder1(blob1);
|
|
63
|
-
var result2 = decoder2(blob2);
|
|
64
|
-
var result3 = decoder3(blob3);
|
|
65
|
-
|
|
66
|
-
try {
|
|
67
|
-
return ok([unwrap(result1), unwrap(result2), unwrap(result3)]);
|
|
68
|
-
} catch (e) {
|
|
69
|
-
// If a decoder error has happened while unwrapping all the
|
|
70
|
-
// results, try to construct a good error message
|
|
71
|
-
return err(annotate([isErr(result1) ? errValue(result1) : value(result1), isErr(result2) ? errValue(result2) : value(result2), isErr(result3) ? errValue(result3) : value(result3)]));
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Builds a Decoder that returns Ok for 4-tuples of [T1, T2, T3, T4], given
|
|
77
|
-
* Decoders for T1, T2, T3, and T4. Err otherwise.
|
|
78
|
-
*/
|
|
79
|
-
|
|
80
|
-
export function tuple4(decoder1, decoder2, decoder3, decoder4) {
|
|
81
|
-
return compose(ntuple(4), function (blobs) {
|
|
82
|
-
var blob1 = blobs[0],
|
|
83
|
-
blob2 = blobs[1],
|
|
84
|
-
blob3 = blobs[2],
|
|
85
|
-
blob4 = blobs[3];
|
|
86
|
-
var result1 = decoder1(blob1);
|
|
87
|
-
var result2 = decoder2(blob2);
|
|
88
|
-
var result3 = decoder3(blob3);
|
|
89
|
-
var result4 = decoder4(blob4);
|
|
90
|
-
|
|
91
|
-
try {
|
|
92
|
-
return ok([unwrap(result1), unwrap(result2), unwrap(result3), unwrap(result4)]);
|
|
93
|
-
} catch (e) {
|
|
94
|
-
// If a decoder error has happened while unwrapping all the
|
|
95
|
-
// results, try to construct a good error message
|
|
96
|
-
return err(annotate([isErr(result1) ? errValue(result1) : value(result1), isErr(result2) ? errValue(result2) : value(result2), isErr(result3) ? errValue(result3) : value(result3), isErr(result4) ? errValue(result4) : value(result4)]));
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Builds a Decoder that returns Ok for 5-tuples of [T1, T2, T3, T4, T5], given
|
|
102
|
-
* Decoders for T1, T2, T3, T4, and T5. Err otherwise.
|
|
103
|
-
*/
|
|
104
|
-
|
|
105
|
-
export function tuple5(decoder1, decoder2, decoder3, decoder4, decoder5) {
|
|
106
|
-
return compose(ntuple(5), function (blobs) {
|
|
107
|
-
var blob1 = blobs[0],
|
|
108
|
-
blob2 = blobs[1],
|
|
109
|
-
blob3 = blobs[2],
|
|
110
|
-
blob4 = blobs[3],
|
|
111
|
-
blob5 = blobs[4];
|
|
112
|
-
var result1 = decoder1(blob1);
|
|
113
|
-
var result2 = decoder2(blob2);
|
|
114
|
-
var result3 = decoder3(blob3);
|
|
115
|
-
var result4 = decoder4(blob4);
|
|
116
|
-
var result5 = decoder5(blob5);
|
|
117
|
-
|
|
118
|
-
try {
|
|
119
|
-
return ok([unwrap(result1), unwrap(result2), unwrap(result3), unwrap(result4), unwrap(result5)]);
|
|
120
|
-
} catch (e) {
|
|
121
|
-
// If a decoder error has happened while unwrapping all the
|
|
122
|
-
// results, try to construct a good error message
|
|
123
|
-
return err(annotate([isErr(result1) ? errValue(result1) : value(result1), isErr(result2) ? errValue(result2) : value(result2), isErr(result3) ? errValue(result3) : value(result3), isErr(result4) ? errValue(result4) : value(result4), isErr(result5) ? errValue(result5) : value(result5)]));
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Builds a Decoder that returns Ok for 5-tuples of [T1, T2, T3, T4, T5], given
|
|
129
|
-
* Decoders for T1, T2, T3, T4, T5, and T6. Err otherwise.
|
|
130
|
-
*/
|
|
131
|
-
|
|
132
|
-
export function tuple6(decoder1, decoder2, decoder3, decoder4, decoder5, decoder6) {
|
|
133
|
-
return compose(ntuple(6), function (blobs) {
|
|
134
|
-
var blob1 = blobs[0],
|
|
135
|
-
blob2 = blobs[1],
|
|
136
|
-
blob3 = blobs[2],
|
|
137
|
-
blob4 = blobs[3],
|
|
138
|
-
blob5 = blobs[4],
|
|
139
|
-
blob6 = blobs[5];
|
|
140
|
-
var result1 = decoder1(blob1);
|
|
141
|
-
var result2 = decoder2(blob2);
|
|
142
|
-
var result3 = decoder3(blob3);
|
|
143
|
-
var result4 = decoder4(blob4);
|
|
144
|
-
var result5 = decoder5(blob5);
|
|
145
|
-
var result6 = decoder6(blob6);
|
|
146
|
-
|
|
147
|
-
try {
|
|
148
|
-
return ok([unwrap(result1), unwrap(result2), unwrap(result3), unwrap(result4), unwrap(result5), unwrap(result6)]);
|
|
149
|
-
} catch (e) {
|
|
150
|
-
// If a decoder error has happened while unwrapping all the
|
|
151
|
-
// results, try to construct a good error message
|
|
152
|
-
return err(annotate([isErr(result1) ? errValue(result1) : value(result1), isErr(result2) ? errValue(result2) : value(result2), isErr(result3) ? errValue(result3) : value(result3), isErr(result4) ? errValue(result4) : value(result4), isErr(result5) ? errValue(result5) : value(result5), isErr(result6) ? errValue(result6) : value(result6)]));
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
}
|
package/ts/_guard.d.ts
DELETED
package/ts/_types.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Annotation } from './annotate';
|
|
2
|
-
import { Result } from './result';
|
|
3
|
-
|
|
4
|
-
export type Scalar = string | number | boolean | symbol | undefined | null;
|
|
5
|
-
|
|
6
|
-
export interface Guard<T> {
|
|
7
|
-
(blob: unknown): T;
|
|
8
|
-
}
|
|
9
|
-
export type Predicate<T> = (value: T) => boolean;
|
|
10
|
-
export type DecodeResult<T> = Result<T, Annotation>;
|
|
11
|
-
export interface Decoder<T, F = unknown> {
|
|
12
|
-
(blob: F): DecodeResult<T>;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export type DecoderType<T> = T extends Decoder<infer V> ? V : never;
|
|
16
|
-
export type GuardType<T> = T extends Guard<infer V> ? V : never;
|
package/ts/_utils.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Decoder } from './_types';
|
|
2
|
-
|
|
3
|
-
export function isDate(value: unknown): boolean;
|
|
4
|
-
export function map<T, V>(decoder: Decoder<T>, mapper: (value: T) => V): Decoder<V>;
|
|
5
|
-
export function compose<T, V>(decoder: Decoder<T>, next: Decoder<V, T>): Decoder<V>;
|
|
6
|
-
export function predicate<T extends F, F = unknown>(
|
|
7
|
-
predicate: (value: F) => value is T,
|
|
8
|
-
msg: string,
|
|
9
|
-
): Decoder<T, F>;
|
|
10
|
-
export function predicate<T>(
|
|
11
|
-
predicate: (value: T) => boolean,
|
|
12
|
-
msg: string,
|
|
13
|
-
): Decoder<T, T>;
|
package/ts/array.d.ts
DELETED
package/ts/boolean.d.ts
DELETED
package/ts/constants.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Decoder, Scalar } from '../_types';
|
|
2
|
-
|
|
3
|
-
// Constants
|
|
4
|
-
|
|
5
|
-
export const null_: Decoder<null>;
|
|
6
|
-
export const undefined_: Decoder<undefined>;
|
|
7
|
-
export function constant<T extends Scalar>(value: T): Decoder<T>;
|
|
8
|
-
export function hardcoded<T extends Scalar>(value: T): Decoder<T>;
|
|
9
|
-
export function hardcoded<T>(value: T): Decoder<T>;
|
|
10
|
-
export const mixed: Decoder<unknown>;
|
|
11
|
-
export const unknown: Decoder<unknown>;
|
package/ts/date.d.ts
DELETED
package/ts/describe.d.ts
DELETED
package/ts/dispatch.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Decoder, DecoderType } from '../_types';
|
|
2
|
-
|
|
3
|
-
export type $Values<T extends object> = T[keyof T];
|
|
4
|
-
|
|
5
|
-
export function dispatch<O extends { [key: string]: Decoder<any> }>(
|
|
6
|
-
field: string,
|
|
7
|
-
mapping: O,
|
|
8
|
-
): Decoder<$Values<{ [key in keyof O]: DecoderType<O[key]> }>>;
|
package/ts/either.d.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { Decoder, Scalar } from '../_types';
|
|
2
|
-
|
|
3
|
-
export function either<T1, T2>(d1: Decoder<T1>, d2: Decoder<T2>): Decoder<T1 | T2>;
|
|
4
|
-
export function either2<T1, T2>(d1: Decoder<T1>, d2: Decoder<T2>): Decoder<T1 | T2>;
|
|
5
|
-
export function either3<T1, T2, T3>(
|
|
6
|
-
d1: Decoder<T1>,
|
|
7
|
-
d2: Decoder<T2>,
|
|
8
|
-
d3: Decoder<T3>,
|
|
9
|
-
): Decoder<T1 | T2 | T3>;
|
|
10
|
-
export function either4<T1, T2, T3, T4>(
|
|
11
|
-
d1: Decoder<T1>,
|
|
12
|
-
d2: Decoder<T2>,
|
|
13
|
-
d3: Decoder<T3>,
|
|
14
|
-
d4: Decoder<T4>,
|
|
15
|
-
): Decoder<T1 | T2 | T3 | T4>;
|
|
16
|
-
export function either5<T1, T2, T3, T4, T5>(
|
|
17
|
-
d1: Decoder<T1>,
|
|
18
|
-
d2: Decoder<T2>,
|
|
19
|
-
d3: Decoder<T3>,
|
|
20
|
-
d4: Decoder<T4>,
|
|
21
|
-
d5: Decoder<T5>,
|
|
22
|
-
): Decoder<T1 | T2 | T3 | T4 | T5>;
|
|
23
|
-
export function either6<T1, T2, T3, T4, T5, T6>(
|
|
24
|
-
d1: Decoder<T1>,
|
|
25
|
-
d2: Decoder<T2>,
|
|
26
|
-
d3: Decoder<T3>,
|
|
27
|
-
d4: Decoder<T4>,
|
|
28
|
-
d5: Decoder<T5>,
|
|
29
|
-
d6: Decoder<T6>,
|
|
30
|
-
): Decoder<T1 | T2 | T3 | T4 | T5 | T6>;
|
|
31
|
-
export function either7<T1, T2, T3, T4, T5, T6, T7>(
|
|
32
|
-
d1: Decoder<T1>,
|
|
33
|
-
d2: Decoder<T2>,
|
|
34
|
-
d3: Decoder<T3>,
|
|
35
|
-
d4: Decoder<T4>,
|
|
36
|
-
d5: Decoder<T5>,
|
|
37
|
-
d6: Decoder<T6>,
|
|
38
|
-
d7: Decoder<T7>,
|
|
39
|
-
): Decoder<T1 | T2 | T3 | T4 | T5 | T6 | T7>;
|
|
40
|
-
export function either8<T1, T2, T3, T4, T5, T6, T7, T8>(
|
|
41
|
-
d1: Decoder<T1>,
|
|
42
|
-
d2: Decoder<T2>,
|
|
43
|
-
d3: Decoder<T3>,
|
|
44
|
-
d4: Decoder<T4>,
|
|
45
|
-
d5: Decoder<T5>,
|
|
46
|
-
d6: Decoder<T6>,
|
|
47
|
-
d7: Decoder<T7>,
|
|
48
|
-
d8: Decoder<T8>,
|
|
49
|
-
): Decoder<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8>;
|
|
50
|
-
export function either9<T1, T2, T3, T4, T5, T6, T7, T8, T9>(
|
|
51
|
-
d1: Decoder<T1>,
|
|
52
|
-
d2: Decoder<T2>,
|
|
53
|
-
d3: Decoder<T3>,
|
|
54
|
-
d4: Decoder<T4>,
|
|
55
|
-
d5: Decoder<T5>,
|
|
56
|
-
d6: Decoder<T6>,
|
|
57
|
-
d7: Decoder<T7>,
|
|
58
|
-
d8: Decoder<T8>,
|
|
59
|
-
d9: Decoder<T9>,
|
|
60
|
-
): Decoder<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9>;
|
|
61
|
-
export function oneOf<T extends Scalar>(constants: readonly T[]): Decoder<T>;
|
package/ts/fail.d.ts
DELETED
package/ts/index.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
export { Decoder, Guard } from './_types';
|
|
2
|
-
export { DecoderType, GuardType } from './_types';
|
|
3
|
-
|
|
4
|
-
export { guard } from './_guard';
|
|
5
|
-
export { compose, map, predicate } from './_utils';
|
|
6
|
-
|
|
7
|
-
export { JSONArray, JSONObject, JSONValue } from './stdlib/json';
|
|
8
|
-
|
|
9
|
-
export { array, nonEmptyArray, poja } from './stdlib/array';
|
|
10
|
-
export { boolean, numericBoolean, truthy } from './stdlib/boolean';
|
|
11
|
-
export {
|
|
12
|
-
constant,
|
|
13
|
-
hardcoded,
|
|
14
|
-
mixed,
|
|
15
|
-
null_,
|
|
16
|
-
undefined_,
|
|
17
|
-
unknown,
|
|
18
|
-
} from './stdlib/constants';
|
|
19
|
-
export { date, iso8601 } from './stdlib/date';
|
|
20
|
-
export { describe } from './stdlib/describe';
|
|
21
|
-
export { dispatch } from './stdlib/dispatch';
|
|
22
|
-
export {
|
|
23
|
-
either,
|
|
24
|
-
either3,
|
|
25
|
-
either4,
|
|
26
|
-
either5,
|
|
27
|
-
either6,
|
|
28
|
-
either7,
|
|
29
|
-
either8,
|
|
30
|
-
either9,
|
|
31
|
-
oneOf,
|
|
32
|
-
} from './stdlib/either';
|
|
33
|
-
export { fail } from './stdlib/fail';
|
|
34
|
-
export { instanceOf } from './stdlib/instanceOf';
|
|
35
|
-
export { json, jsonArray, jsonObject } from './stdlib/json';
|
|
36
|
-
export { lazy } from './stdlib/lazy';
|
|
37
|
-
export { mapping, dict } from './stdlib/mapping';
|
|
38
|
-
export { integer, number, positiveInteger, positiveNumber } from './stdlib/number';
|
|
39
|
-
export { exact, inexact, object, pojo } from './stdlib/object';
|
|
40
|
-
export { maybe, nullable, optional } from './stdlib/optional';
|
|
41
|
-
export { email, nonEmptyString, regex, string, url } from './stdlib/string';
|
|
42
|
-
export { tuple1, tuple2, tuple3, tuple4, tuple5, tuple6 } from './stdlib/tuple';
|
package/ts/inline.d.ts
DELETED
package/ts/instanceOf.d.ts
DELETED
package/ts/json.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Decoder } from '../_types';
|
|
2
|
-
|
|
3
|
-
export type JSONValue = null | string | number | boolean | JSONObject | JSONArray;
|
|
4
|
-
export interface JSONObject {
|
|
5
|
-
[key: string]: JSONValue;
|
|
6
|
-
}
|
|
7
|
-
export type JSONArray = JSONValue[];
|
|
8
|
-
|
|
9
|
-
export const json: Decoder<JSONValue>;
|
|
10
|
-
export const jsonArray: Decoder<JSONArray>;
|
|
11
|
-
export const jsonObject: Decoder<JSONObject>;
|
package/ts/lazy.d.ts
DELETED
package/ts/mapping.d.ts
DELETED
package/ts/number.d.ts
DELETED
package/ts/object.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { Decoder, DecoderType } from '../_types';
|
|
2
|
-
import { AllowImplicit } from './_helpers';
|
|
3
|
-
|
|
4
|
-
export type ObjectDecoderType<T> = AllowImplicit<{
|
|
5
|
-
[key in keyof T]: DecoderType<T[key]>;
|
|
6
|
-
}>;
|
|
7
|
-
|
|
8
|
-
export const pojo: Decoder<{ [key: string]: unknown }>;
|
|
9
|
-
|
|
10
|
-
export function object<O extends { [key: string]: Decoder<any> }>(
|
|
11
|
-
mapping: O,
|
|
12
|
-
): Decoder<{ [K in keyof ObjectDecoderType<O>]: ObjectDecoderType<O>[K] }>;
|
|
13
|
-
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
14
|
-
// This is basically just equivalent to:
|
|
15
|
-
// ObjectDecoderType<O>
|
|
16
|
-
//
|
|
17
|
-
// But by "resolving" this with a mapped type, we remove the helper
|
|
18
|
-
// type names from the inferred type here, making this much easier to
|
|
19
|
-
// work with while developing.
|
|
20
|
-
|
|
21
|
-
export function exact<O extends { [key: string]: Decoder<any> }>(
|
|
22
|
-
mapping: O,
|
|
23
|
-
): Decoder<{ [K in keyof ObjectDecoderType<O>]: ObjectDecoderType<O>[K] }>;
|
|
24
|
-
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
25
|
-
// Ditto (see above)
|
|
26
|
-
|
|
27
|
-
export function inexact<O extends { [key: string]: Decoder<any> }>(
|
|
28
|
-
mapping: O,
|
|
29
|
-
): Decoder<
|
|
30
|
-
{ [K in keyof ObjectDecoderType<O>]: ObjectDecoderType<O>[K] } & {
|
|
31
|
-
[extra: string]: unknown;
|
|
32
|
-
}
|
|
33
|
-
>;
|
package/ts/optional.d.ts
DELETED
package/ts/result.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
export interface Ok<T> {
|
|
2
|
-
readonly type: 'ok';
|
|
3
|
-
readonly value: T;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export interface Err<E> {
|
|
7
|
-
readonly type: 'err';
|
|
8
|
-
readonly error: E;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export type Result<T, E> = Ok<T> | Err<E>;
|
|
12
|
-
|
|
13
|
-
export function ok<T>(value: T): Ok<T>;
|
|
14
|
-
export function err<E>(error: E): Err<E>;
|
|
15
|
-
export function toString(result: Result<unknown, unknown>): string;
|
|
16
|
-
export function isOk(result: Result<unknown, unknown>): boolean;
|
|
17
|
-
export function isErr(result: Result<unknown, unknown>): boolean;
|
|
18
|
-
export function withDefault<T>(result: Result<T, unknown>, defaultValue: T): T;
|
|
19
|
-
export function value<T>(result: Result<T, unknown>): void | T;
|
|
20
|
-
export function errValue<E>(result: Result<unknown, E>): void | E;
|
|
21
|
-
export function unwrap<T>(result: Result<T, unknown>): T;
|
|
22
|
-
export function expect<T>(result: Result<T, unknown>, message: string | Error): T;
|
|
23
|
-
export function dispatch<T, E, O>(
|
|
24
|
-
result: Result<T, E>,
|
|
25
|
-
okCallback: (value: T) => O,
|
|
26
|
-
errCallback: (error: E) => O,
|
|
27
|
-
): O;
|
|
28
|
-
export function andThen<T, E, V>(
|
|
29
|
-
result: Result<T, E>,
|
|
30
|
-
callback: (value: T) => Result<V, E>,
|
|
31
|
-
): Result<V, E>;
|
|
32
|
-
export function map<T, E, T2>(
|
|
33
|
-
result: Result<T, E>,
|
|
34
|
-
mapper: (value: T) => T2,
|
|
35
|
-
): Result<T2, E>;
|
|
36
|
-
export function mapError<T, E, E2>(
|
|
37
|
-
result: Result<T, E>,
|
|
38
|
-
mapper: (error: E) => E2,
|
|
39
|
-
): Result<T, E2>;
|
package/ts/short.d.ts
DELETED
package/ts/string.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Decoder } from '../_types';
|
|
2
|
-
|
|
3
|
-
export const string: Decoder<string>;
|
|
4
|
-
export const nonEmptyString: Decoder<string>;
|
|
5
|
-
export function regex(regex: RegExp, msg: string): Decoder<string>;
|
|
6
|
-
export const email: Decoder<string>;
|
|
7
|
-
export function url(schemes?: readonly string[]): Decoder<string>;
|
package/ts/tuple.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Decoder } from '../_types';
|
|
2
|
-
|
|
3
|
-
export function tuple1<T1>(d1: Decoder<T1>): Decoder<[T1]>;
|
|
4
|
-
export function tuple2<T1, T2>(d1: Decoder<T1>, d2: Decoder<T2>): Decoder<[T1, T2]>;
|
|
5
|
-
export function tuple3<T1, T2, T3>(
|
|
6
|
-
d1: Decoder<T1>,
|
|
7
|
-
d2: Decoder<T2>,
|
|
8
|
-
d3: Decoder<T3>,
|
|
9
|
-
): Decoder<[T1, T2, T3]>;
|
|
10
|
-
export function tuple4<T1, T2, T3, T4>(
|
|
11
|
-
d1: Decoder<T1>,
|
|
12
|
-
d2: Decoder<T2>,
|
|
13
|
-
d3: Decoder<T3>,
|
|
14
|
-
d4: Decoder<T4>,
|
|
15
|
-
): Decoder<[T1, T2, T3, T4]>;
|
|
16
|
-
export function tuple5<T1, T2, T3, T4, T5>(
|
|
17
|
-
d1: Decoder<T1>,
|
|
18
|
-
d2: Decoder<T2>,
|
|
19
|
-
d3: Decoder<T3>,
|
|
20
|
-
d4: Decoder<T4>,
|
|
21
|
-
d5: Decoder<T5>,
|
|
22
|
-
): Decoder<[T1, T2, T3, T4, T5]>;
|
|
23
|
-
export function tuple6<T1, T2, T3, T4, T5, T6>(
|
|
24
|
-
d1: Decoder<T1>,
|
|
25
|
-
d2: Decoder<T2>,
|
|
26
|
-
d3: Decoder<T3>,
|
|
27
|
-
d4: Decoder<T4>,
|
|
28
|
-
d5: Decoder<T5>,
|
|
29
|
-
d6: Decoder<T6>,
|
|
30
|
-
): Decoder<[T1, T2, T3, T4, T5, T6]>;
|