decoders 1.25.5 → 2.0.0-beta2
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 +23 -3
- package/_esm/_guard.js +15 -0
- package/_esm/_guard.js.flow +20 -0
- package/_esm/_types.js +0 -0
- package/_esm/_types.js.flow +20 -0
- package/_esm/_utils.js +93 -0
- package/_esm/_utils.js.flow +97 -0
- package/_esm/annotate.js +144 -0
- package/_esm/annotate.js.flow +218 -0
- package/_esm/core/array.js +91 -0
- package/{array.js.flow → _esm/core/array.js.flow} +22 -25
- package/_esm/core/boolean.js +28 -0
- package/{boolean.js.flow → _esm/core/boolean.js.flow} +8 -7
- package/_esm/core/composition.js +42 -0
- package/{utils.js.flow → _esm/core/composition.js.flow} +7 -22
- package/_esm/core/constants.js +46 -0
- package/{constants.js.flow → _esm/core/constants.js.flow} +13 -12
- package/_esm/core/date.js +28 -0
- package/{date.js.flow → _esm/core/date.js.flow} +9 -7
- package/{describe.js → _esm/core/describe.js} +5 -11
- package/{describe.js.flow → _esm/core/describe.js.flow} +4 -4
- package/{dispatch.js → _esm/core/dispatch.js} +8 -15
- package/{dispatch.js.flow → _esm/core/dispatch.js.flow} +6 -5
- package/_esm/core/either.js +90 -0
- package/{either.js.flow → _esm/core/either.js.flow} +55 -35
- package/_esm/core/fail.js +11 -0
- package/_esm/core/fail.js.flow +12 -0
- package/_esm/core/instanceOf.js +8 -0
- package/{instanceOf.js.flow → _esm/core/instanceOf.js.flow} +7 -8
- package/_esm/core/json.js +15 -0
- package/{json.js.flow → _esm/core/json.js.flow} +4 -4
- package/_esm/core/lazy.js +11 -0
- package/{lazy.js.flow → _esm/core/lazy.js.flow} +1 -1
- package/_esm/core/mapping.js +54 -0
- package/_esm/core/mapping.js.flow +54 -0
- package/_esm/core/number.js +25 -0
- package/{number.js.flow → _esm/core/number.js.flow} +10 -11
- package/_esm/core/object.js +175 -0
- package/{object.js.flow → _esm/core/object.js.flow} +44 -52
- package/_esm/core/optional.js +38 -0
- package/{optional.js.flow → _esm/core/optional.js.flow} +6 -7
- package/{string.js → _esm/core/string.js} +18 -35
- package/{string.js.flow → _esm/core/string.js.flow} +13 -12
- package/_esm/core/tuple.js +155 -0
- package/{tuple.js.flow → _esm/core/tuple.js.flow} +62 -63
- package/_esm/format/index.js +2 -0
- package/_esm/format/index.js.flow +4 -0
- package/_esm/format/inline.js +137 -0
- package/_esm/format/inline.js.flow +122 -0
- package/_esm/format/short.js +4 -0
- package/_esm/format/short.js.flow +8 -0
- package/_esm/index.js +37 -0
- package/_esm/index.js.flow +56 -0
- package/_esm/result.js +139 -0
- package/_esm/result.js.flow +166 -0
- package/_guard.js +26 -0
- package/_guard.js.flow +20 -0
- package/_types.js +1 -0
- package/_types.js.flow +20 -0
- package/_utils.js +108 -0
- package/_utils.js.flow +97 -0
- package/annotate.js +161 -0
- package/annotate.js.flow +218 -0
- package/core/array.js +108 -0
- package/core/array.js.flow +103 -0
- package/core/boolean.js +44 -0
- package/core/boolean.js.flow +29 -0
- package/core/composition.js +56 -0
- package/core/composition.js.flow +43 -0
- package/core/constants.js +69 -0
- package/core/constants.js.flow +46 -0
- package/core/date.js +46 -0
- package/core/date.js.flow +40 -0
- package/core/describe.js +26 -0
- package/core/describe.js.flow +17 -0
- package/core/dispatch.js +62 -0
- package/core/dispatch.js.flow +58 -0
- package/core/either.js +117 -0
- package/core/either.js.flow +151 -0
- package/core/fail.js +21 -0
- package/core/fail.js.flow +12 -0
- package/core/instanceOf.js +19 -0
- package/core/instanceOf.js.flow +20 -0
- package/{json.js → core/json.js} +3 -5
- package/core/json.js.flow +28 -0
- package/{lazy.js → core/lazy.js} +1 -3
- package/core/lazy.js.flow +15 -0
- package/core/mapping.js +67 -0
- package/core/mapping.js.flow +54 -0
- package/core/number.js +40 -0
- package/core/number.js.flow +34 -0
- package/core/object.js +194 -0
- package/core/object.js.flow +203 -0
- package/core/optional.js +54 -0
- package/core/optional.js.flow +41 -0
- package/core/string.js +98 -0
- package/core/string.js.flow +82 -0
- package/core/tuple.js +173 -0
- package/core/tuple.js.flow +220 -0
- package/format/index.js +12 -0
- package/format/index.js.flow +4 -0
- package/format/inline.js +146 -0
- package/format/inline.js.flow +122 -0
- package/format/short.js +10 -0
- package/format/short.js.flow +8 -0
- package/index.js +118 -395
- package/index.js.flow +24 -24
- package/package.json +2 -6
- package/result.js +172 -0
- package/result.js.flow +166 -0
- package/array.d.ts +0 -5
- package/array.js +0 -133
- package/boolean.d.ts +0 -5
- package/boolean.js +0 -42
- package/constants.d.ts +0 -11
- package/constants.js +0 -67
- package/date.d.ts +0 -4
- package/date.js +0 -42
- package/describe.d.ts +0 -3
- package/dispatch.d.ts +0 -8
- package/either.d.ts +0 -61
- package/either.js +0 -85
- package/fail.d.ts +0 -3
- package/fail.js +0 -19
- package/fail.js.flow +0 -13
- package/guard.d.ts +0 -7
- package/guard.js +0 -30
- package/guard.js.flow +0 -36
- package/helpers.d.ts +0 -79
- package/index.d.ts +0 -38
- package/instanceOf.d.ts +0 -3
- package/instanceOf.js +0 -17
- package/json.d.ts +0 -11
- package/lazy.d.ts +0 -3
- package/mapping.d.ts +0 -4
- package/mapping.js +0 -113
- package/mapping.js.flow +0 -71
- package/number.d.ts +0 -6
- package/number.js +0 -38
- package/object.d.ts +0 -33
- package/object.js +0 -254
- package/optional.d.ts +0 -5
- package/optional.js +0 -52
- package/string.d.ts +0 -7
- package/tuple.d.ts +0 -30
- package/tuple.js +0 -199
- package/types.d.ts +0 -18
- package/types.js +0 -5
- package/types.js.flow +0 -26
- package/utils.d.ts +0 -13
- package/utils.js +0 -70
package/utils.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.compose = compose;
|
|
7
|
-
exports.isDate = void 0;
|
|
8
|
-
exports.map = map;
|
|
9
|
-
exports.predicate = predicate;
|
|
10
|
-
|
|
11
|
-
var _debrief = require("debrief");
|
|
12
|
-
|
|
13
|
-
var _Result = require("lemons/Result");
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* `x instanceof Date` checks are unreliable across stack frames (that information
|
|
17
|
-
* might get lost by the JS runtime), so we'll have to reside to more runtime
|
|
18
|
-
* inspection checks.
|
|
19
|
-
*
|
|
20
|
-
* Taken from https://stackoverflow.com/a/44198641
|
|
21
|
-
*/
|
|
22
|
-
var isDate = function isDate(value) {
|
|
23
|
-
return value !== undefined && value !== null && // $FlowFixMe[method-unbinding]
|
|
24
|
-
Object.prototype.toString.call(value) === '[object Date]' && !isNaN(value);
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Given a decoder T and a mapping function from T's to V's, returns a decoder
|
|
28
|
-
* for V's. This is useful to change the original input data.
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
exports.isDate = isDate;
|
|
33
|
-
|
|
34
|
-
function map(decoder, mapper) {
|
|
35
|
-
return compose(decoder, function (x) {
|
|
36
|
-
try {
|
|
37
|
-
return (0, _Result.Ok)(mapper(x));
|
|
38
|
-
} catch (e) {
|
|
39
|
-
return (0, _Result.Err)((0, _debrief.annotate)(x, e instanceof Error ? e.message : String(e)));
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Compose two decoders by passing the result of the first into the second.
|
|
45
|
-
* The second decoder may assume as its input type the output type of the first
|
|
46
|
-
* decoder (so it's not necessary to accept the typical "mixed"). This is
|
|
47
|
-
* useful for "narrowing down" the checks. For example, if you want to write
|
|
48
|
-
* a decoder for positive numbers, you can compose it from an existing decoder
|
|
49
|
-
* for any number, and a decoder that, assuming a number, checks if it's
|
|
50
|
-
* positive. Very often combined with the predicate() helper as the second
|
|
51
|
-
* argument.
|
|
52
|
-
*/
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
function compose(decoder, next) {
|
|
56
|
-
return function (blob) {
|
|
57
|
-
return decoder(blob).andThen(next);
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Factory function returning a Decoder<T>, given a predicate function that
|
|
62
|
-
* accepts/rejects the input of type T.
|
|
63
|
-
*/
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
function predicate(predicate, msg) {
|
|
67
|
-
return function (value) {
|
|
68
|
-
return predicate(value) ? (0, _Result.Ok)(value) : (0, _Result.Err)((0, _debrief.annotate)(value, msg));
|
|
69
|
-
};
|
|
70
|
-
}
|