decoders 1.25.2 → 1.26.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 +20 -0
- package/{array.js → cjs/array.js} +5 -5
- package/{array.js.flow → cjs/array.js.flow} +1 -1
- package/{boolean.js → cjs/boolean.js} +4 -4
- package/{boolean.js.flow → cjs/boolean.js.flow} +1 -1
- package/{constants.js → cjs/constants.js} +7 -7
- package/{constants.js.flow → cjs/constants.js.flow} +3 -3
- package/{date.js → cjs/date.js} +2 -2
- package/{date.js.flow → cjs/date.js.flow} +1 -1
- package/{describe.js → cjs/describe.js} +0 -0
- package/{describe.js.flow → cjs/describe.js.flow} +0 -0
- package/{dispatch.js → cjs/dispatch.js} +0 -0
- package/{dispatch.js.flow → cjs/dispatch.js.flow} +0 -0
- package/{either.js → cjs/either.js} +6 -6
- package/{either.js.flow → cjs/either.js.flow} +2 -4
- package/{fail.js → cjs/fail.js} +2 -2
- package/{fail.js.flow → cjs/fail.js.flow} +1 -1
- package/{guard.js → cjs/guard.js} +0 -0
- package/{guard.js.flow → cjs/guard.js.flow} +0 -0
- package/{index.js → cjs/index.js} +110 -110
- package/{index.js.flow → cjs/index.js.flow} +0 -0
- package/{instanceOf.js → cjs/instanceOf.js} +2 -2
- package/{instanceOf.js.flow → cjs/instanceOf.js.flow} +1 -1
- package/{json.js → cjs/json.js} +1 -1
- package/{json.js.flow → cjs/json.js.flow} +0 -0
- package/{lazy.js → cjs/lazy.js} +0 -0
- package/{lazy.js.flow → cjs/lazy.js.flow} +0 -0
- package/{mapping.js → cjs/mapping.js} +4 -4
- package/{mapping.js.flow → cjs/mapping.js.flow} +1 -1
- package/{number.js → cjs/number.js} +3 -3
- package/{number.js.flow → cjs/number.js.flow} +1 -1
- package/{object.js → cjs/object.js} +8 -8
- package/{object.js.flow → cjs/object.js.flow} +1 -1
- package/{optional.js → cjs/optional.js} +5 -5
- package/{optional.js.flow → cjs/optional.js.flow} +1 -1
- package/{string.js → cjs/string.js} +7 -6
- package/{string.js.flow → cjs/string.js.flow} +1 -1
- package/{tuple.js → cjs/tuple.js} +13 -13
- package/{tuple.js.flow → cjs/tuple.js.flow} +1 -1
- package/cjs/types.js +3 -0
- package/{types.js.flow → cjs/types.js.flow} +3 -1
- package/{utils.js → cjs/utils.js} +6 -6
- package/{utils.js.flow → cjs/utils.js.flow} +1 -1
- package/es/index.js +1039 -0
- package/package.json +9 -5
- package/{array.d.ts → ts/array.d.ts} +1 -1
- package/{boolean.d.ts → ts/boolean.d.ts} +0 -0
- package/{constants.d.ts → ts/constants.d.ts} +1 -2
- package/{date.d.ts → ts/date.d.ts} +0 -0
- package/{describe.d.ts → ts/describe.d.ts} +0 -0
- package/{dispatch.d.ts → ts/dispatch.d.ts} +0 -0
- package/{either.d.ts → ts/either.d.ts} +1 -3
- package/{fail.d.ts → ts/fail.d.ts} +0 -0
- package/{guard.d.ts → ts/guard.d.ts} +0 -0
- package/ts/helpers.d.ts +79 -0
- package/{index.d.ts → ts/index.d.ts} +1 -1
- package/{instanceOf.d.ts → ts/instanceOf.d.ts} +0 -0
- package/{json.d.ts → ts/json.d.ts} +0 -0
- package/{lazy.d.ts → ts/lazy.d.ts} +0 -0
- package/{mapping.d.ts → ts/mapping.d.ts} +0 -0
- package/{number.d.ts → ts/number.d.ts} +0 -0
- package/{object.d.ts → ts/object.d.ts} +3 -3
- package/{optional.d.ts → ts/optional.d.ts} +0 -0
- package/{string.d.ts → ts/string.d.ts} +0 -0
- package/{tuple.d.ts → ts/tuple.d.ts} +0 -0
- package/{types.d.ts → ts/types.d.ts} +3 -1
- package/{utils.d.ts → ts/utils.d.ts} +0 -0
- package/helpers.d.ts +0 -62
- package/types.js +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
## v1.26.0-beta1
|
|
2
|
+
|
|
3
|
+
- Include ES modules in published NPM builds
|
|
4
|
+
|
|
5
|
+
## v1.25.5
|
|
6
|
+
|
|
7
|
+
- Fix compatibility issue with TypeScript projects configured with
|
|
8
|
+
`strictNullChecks: false` (or `strict: false`) (Thanks, @stevekrouse and @djlauk!)
|
|
9
|
+
|
|
10
|
+
- Officially support Node 16.x
|
|
11
|
+
|
|
12
|
+
## v1.25.4
|
|
13
|
+
|
|
14
|
+
- Expose `nonEmptyArray` function in TypeScript (Thanks, @mszczepanczyk!)
|
|
15
|
+
|
|
16
|
+
## v1.25.3
|
|
17
|
+
|
|
18
|
+
- Argument to `constant(...)` now has to be scalar value in both Flow and TypeScript,
|
|
19
|
+
which matches its intended purpose.
|
|
20
|
+
|
|
1
21
|
## v1.25.2
|
|
2
22
|
|
|
3
23
|
- Avoid the need for having to manually specify "as const" in TypeScript when using
|
|
@@ -9,7 +9,7 @@ exports.poja = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _debrief = require("debrief");
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _lemons = require("lemons");
|
|
13
13
|
|
|
14
14
|
var _utils = require("./utils");
|
|
15
15
|
|
|
@@ -33,10 +33,10 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
33
33
|
*/
|
|
34
34
|
var poja = function poja(blob) {
|
|
35
35
|
if (!Array.isArray(blob)) {
|
|
36
|
-
return (0,
|
|
36
|
+
return (0, _lemons.Err)((0, _debrief.annotate)(blob, 'Must be an array'));
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
return (0,
|
|
39
|
+
return (0, _lemons.Ok)( // NOTE: Since Flow 0.98, Array.isArray() returns $ReadOnlyArray<mixed>
|
|
40
40
|
// instead of Array<mixed>. For rationale, see
|
|
41
41
|
// https://github.com/facebook/flow/issues/7684. In this case, we
|
|
42
42
|
// don't want to output read-only types because it's up to the user of
|
|
@@ -85,7 +85,7 @@ function all(iterable, blobs) {
|
|
|
85
85
|
// errValue.push('...'); // TODO: make special mark, not string!
|
|
86
86
|
// }
|
|
87
87
|
|
|
88
|
-
return (0,
|
|
88
|
+
return (0, _lemons.Err)((0, _debrief.annotate)(clone));
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
index++;
|
|
@@ -96,7 +96,7 @@ function all(iterable, blobs) {
|
|
|
96
96
|
_iterator.f();
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
return (0,
|
|
99
|
+
return (0, _lemons.Ok)(results);
|
|
100
100
|
}
|
|
101
101
|
/**
|
|
102
102
|
* Given a T, builds a decoder that assumes an array input and returns an
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.truthy = exports.numericBoolean = exports["boolean"] = void 0;
|
|
7
7
|
|
|
8
8
|
var _debrief = require("debrief");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _lemons = require("lemons");
|
|
11
11
|
|
|
12
12
|
var _number = require("./number");
|
|
13
13
|
|
|
@@ -17,7 +17,7 @@ var _utils = require("./utils");
|
|
|
17
17
|
* Decoder that only returns Ok for boolean inputs. Err otherwise.
|
|
18
18
|
*/
|
|
19
19
|
var _boolean = function _boolean(blob) {
|
|
20
|
-
return typeof blob === 'boolean' ? (0,
|
|
20
|
+
return typeof blob === 'boolean' ? (0, _lemons.Ok)(blob) : (0, _lemons.Err)((0, _debrief.annotate)(blob, 'Must be boolean'));
|
|
21
21
|
};
|
|
22
22
|
/**
|
|
23
23
|
* Decoder that returns true for all truthy values, and false otherwise. Never fails.
|
|
@@ -27,7 +27,7 @@ var _boolean = function _boolean(blob) {
|
|
|
27
27
|
exports["boolean"] = _boolean;
|
|
28
28
|
|
|
29
29
|
var truthy = function truthy(blob) {
|
|
30
|
-
return (0,
|
|
30
|
+
return (0, _lemons.Ok)(!!blob);
|
|
31
31
|
};
|
|
32
32
|
/**
|
|
33
33
|
* Decoder that only returns Ok for numeric input values representing booleans.
|
|
@@ -5,17 +5,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.constant = constant;
|
|
7
7
|
exports.hardcoded = hardcoded;
|
|
8
|
-
exports.unknown = exports.
|
|
8
|
+
exports.unknown = exports.undefined_ = exports.null_ = exports.mixed = void 0;
|
|
9
9
|
|
|
10
10
|
var _debrief = require("debrief");
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _lemons = require("lemons");
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Decoder that only returns Ok for `null` inputs. Err otherwise.
|
|
16
16
|
*/
|
|
17
17
|
var null_ = function null_(blob) {
|
|
18
|
-
return blob === null ? (0,
|
|
18
|
+
return blob === null ? (0, _lemons.Ok)(blob) : (0, _lemons.Err)((0, _debrief.annotate)(blob, 'Must be null'));
|
|
19
19
|
};
|
|
20
20
|
/**
|
|
21
21
|
* Decoder that only returns Ok for `undefined` inputs. Err otherwise.
|
|
@@ -25,7 +25,7 @@ var null_ = function null_(blob) {
|
|
|
25
25
|
exports.null_ = null_;
|
|
26
26
|
|
|
27
27
|
var undefined_ = function undefined_(blob) {
|
|
28
|
-
return blob === undefined ? (0,
|
|
28
|
+
return blob === undefined ? (0, _lemons.Ok)(blob) : (0, _lemons.Err)((0, _debrief.annotate)(blob, 'Must be undefined'));
|
|
29
29
|
};
|
|
30
30
|
/**
|
|
31
31
|
* Decoder that only returns Ok for the given value constant. Err otherwise.
|
|
@@ -36,7 +36,7 @@ exports.undefined_ = undefined_;
|
|
|
36
36
|
|
|
37
37
|
function constant(value) {
|
|
38
38
|
return function (blob) {
|
|
39
|
-
return blob === value ? (0,
|
|
39
|
+
return blob === value ? (0, _lemons.Ok)(value) : (0, _lemons.Err)((0, _debrief.annotate)(blob, "Must be constant ".concat(String(value))));
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
@@ -46,7 +46,7 @@ function constant(value) {
|
|
|
46
46
|
|
|
47
47
|
function hardcoded(value) {
|
|
48
48
|
return function (_) {
|
|
49
|
-
return (0,
|
|
49
|
+
return (0, _lemons.Ok)(value);
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
@@ -55,7 +55,7 @@ function hardcoded(value) {
|
|
|
55
55
|
|
|
56
56
|
|
|
57
57
|
var mixed = function mixed(blob) {
|
|
58
|
-
return (0,
|
|
58
|
+
return (0, _lemons.Ok)(blob);
|
|
59
59
|
};
|
|
60
60
|
/**
|
|
61
61
|
* Alias of mixed.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// @flow strict
|
|
2
2
|
|
|
3
3
|
import { annotate } from 'debrief';
|
|
4
|
-
import { Err, Ok } from 'lemons
|
|
4
|
+
import { Err, Ok } from 'lemons';
|
|
5
5
|
|
|
6
|
-
import type { Decoder } from './types';
|
|
6
|
+
import type { Decoder, Scalar } from './types';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Decoder that only returns Ok for `null` inputs. Err otherwise.
|
|
@@ -20,7 +20,7 @@ export const undefined_: Decoder<void> = (blob: mixed) =>
|
|
|
20
20
|
/**
|
|
21
21
|
* Decoder that only returns Ok for the given value constant. Err otherwise.
|
|
22
22
|
*/
|
|
23
|
-
export function constant<T>(value: T): Decoder<T> {
|
|
23
|
+
export function constant<T: Scalar>(value: T): Decoder<T> {
|
|
24
24
|
return (blob: mixed) =>
|
|
25
25
|
blob === value
|
|
26
26
|
? Ok(value)
|
package/{date.js → cjs/date.js}
RENAMED
|
@@ -7,7 +7,7 @@ exports.iso8601 = exports.date = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _debrief = require("debrief");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _lemons = require("lemons");
|
|
11
11
|
|
|
12
12
|
var _string = require("./string");
|
|
13
13
|
|
|
@@ -19,7 +19,7 @@ var _utils = require("./utils");
|
|
|
19
19
|
var iso8601_re = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:[.]\d+)?(?:Z|[+-]\d{2}:?\d{2})$/;
|
|
20
20
|
|
|
21
21
|
var date = function date(value) {
|
|
22
|
-
return (0, _utils.isDate)(value) ? (0,
|
|
22
|
+
return (0, _utils.isDate)(value) ? (0, _lemons.Ok)(value) : (0, _lemons.Err)((0, _debrief.annotate)(value, 'Must be a Date'));
|
|
23
23
|
};
|
|
24
24
|
/**
|
|
25
25
|
* Decoder that only returns Ok for strings that are valid ISO8601 date
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -15,7 +15,7 @@ exports.oneOf = oneOf;
|
|
|
15
15
|
|
|
16
16
|
var _debrief = require("debrief");
|
|
17
17
|
|
|
18
|
-
var
|
|
18
|
+
var _lemons = require("lemons");
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Indents and adds a dash in front of this (potentially multiline) string.
|
|
@@ -29,12 +29,12 @@ function itemize() {
|
|
|
29
29
|
function either(d1, d2) {
|
|
30
30
|
return function (blob) {
|
|
31
31
|
return d1(blob).dispatch(function (value1) {
|
|
32
|
-
return (0,
|
|
32
|
+
return (0, _lemons.Ok)(value1);
|
|
33
33
|
}, function (err1) {
|
|
34
34
|
return d2(blob).dispatch(function (value2) {
|
|
35
|
-
return (0,
|
|
35
|
+
return (0, _lemons.Ok)(value2);
|
|
36
36
|
}, function (err2) {
|
|
37
|
-
return (0,
|
|
37
|
+
return (0, _lemons.Err)((0, _debrief.annotate)(blob, ['Either:', itemize((0, _debrief.summarize)(err1).join('\n')), itemize((0, _debrief.summarize)(err2).join('\n'))].join('\n')));
|
|
38
38
|
});
|
|
39
39
|
});
|
|
40
40
|
};
|
|
@@ -75,10 +75,10 @@ function oneOf(constants) {
|
|
|
75
75
|
});
|
|
76
76
|
|
|
77
77
|
if (winner !== undefined) {
|
|
78
|
-
return (0,
|
|
78
|
+
return (0, _lemons.Ok)(winner);
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
return (0,
|
|
81
|
+
return (0, _lemons.Err)((0, _debrief.annotate)(blob, "Must be one of ".concat(constants.map(function (value) {
|
|
82
82
|
return JSON.stringify(value);
|
|
83
83
|
}).join(', '))));
|
|
84
84
|
};
|
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
import { annotate, indent } from 'debrief';
|
|
4
4
|
import { summarize } from 'debrief';
|
|
5
|
-
import { Err, Ok } from 'lemons
|
|
5
|
+
import { Err, Ok } from 'lemons';
|
|
6
6
|
|
|
7
|
-
import type { Decoder } from './types';
|
|
8
|
-
|
|
9
|
-
export type Scalar = string | number | boolean | symbol | void | null;
|
|
7
|
+
import type { Decoder, Scalar } from './types';
|
|
10
8
|
|
|
11
9
|
/**
|
|
12
10
|
* Indents and adds a dash in front of this (potentially multiline) string.
|
package/{fail.js → cjs/fail.js}
RENAMED
|
@@ -7,13 +7,13 @@ exports.fail = fail;
|
|
|
7
7
|
|
|
8
8
|
var _debrief = require("debrief");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _lemons = require("lemons");
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Decoder that always fails with the given error message, no matter what the input.
|
|
14
14
|
*/
|
|
15
15
|
function fail(msg) {
|
|
16
16
|
return function (blob) {
|
|
17
|
-
return (0,
|
|
17
|
+
return (0, _lemons.Err)((0, _debrief.annotate)(blob, msg));
|
|
18
18
|
};
|
|
19
19
|
}
|
|
File without changes
|
|
File without changes
|