decoders 2.0.0-beta9 → 2.0.0
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 +56 -29
- package/Decoder.d.ts +94 -0
- package/Decoder.js +222 -0
- package/Decoder.js.flow +286 -0
- package/Decoder.mjs +215 -0
- package/README.md +122 -1507
- package/_utils.d.ts +0 -1
- package/_utils.js +11 -17
- package/_utils.js.flow +13 -17
- package/_utils.mjs +10 -14
- package/format.d.ts +4 -2
- package/format.js +1 -1
- package/format.js.flow +3 -1
- package/format.mjs +1 -1
- package/index.d.ts +29 -31
- package/index.js +62 -84
- package/index.js.flow +30 -48
- package/index.mjs +11 -36
- package/{core → 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/{core/object.js → lib/objects.js} +78 -85
- package/{core/object.js.flow → lib/objects.js.flow} +89 -102
- package/{core/object.mjs → lib/objects.mjs} +77 -82
- 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/{core/either.js.flow → lib/unions.js.flow} +67 -17
- 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 +64 -17
- package/result.d.ts +0 -23
- package/result.js +0 -68
- package/result.js.flow +0 -72
- package/result.mjs +0 -54
- package/_guard.d.ts +0 -7
- package/_guard.js +0 -22
- package/_guard.js.flow +0 -20
- package/_guard.mjs +0 -15
- package/_types.d.ts +0 -13
- package/_types.js +0 -1
- package/_types.js.flow +0 -20
- package/_types.mjs +0 -0
- package/core/array.d.ts +0 -8
- package/core/array.js +0 -115
- package/core/array.js.flow +0 -107
- package/core/array.mjs +0 -100
- package/core/boolean.d.ts +0 -5
- package/core/boolean.js +0 -40
- package/core/boolean.js.flow +0 -27
- package/core/boolean.mjs +0 -28
- package/core/composition.d.ts +0 -18
- package/core/composition.js +0 -82
- package/core/composition.js.flow +0 -74
- package/core/composition.mjs +0 -70
- package/core/constants.d.ts +0 -11
- package/core/constants.js +0 -65
- package/core/constants.js.flow +0 -44
- package/core/constants.mjs +0 -46
- package/core/date.d.ts +0 -4
- package/core/date.js +0 -42
- package/core/date.js.flow +0 -38
- package/core/date.mjs +0 -28
- package/core/describe.d.ts +0 -3
- package/core/describe.js +0 -22
- package/core/describe.js.flow +0 -17
- package/core/describe.mjs +0 -16
- package/core/dispatch.d.ts +0 -8
- package/core/dispatch.js +0 -60
- package/core/dispatch.js.flow +0 -59
- package/core/dispatch.mjs +0 -52
- package/core/either.d.ts +0 -66
- package/core/either.js +0 -101
- package/core/either.mjs +0 -90
- package/core/fail.d.ts +0 -3
- package/core/fail.js +0 -17
- package/core/fail.js.flow +0 -12
- package/core/fail.mjs +0 -11
- package/core/instanceOf.d.ts +0 -3
- package/core/instanceOf.js +0 -15
- package/core/instanceOf.js.flow +0 -20
- package/core/instanceOf.mjs +0 -8
- package/core/json.d.ts +0 -11
- package/core/json.js +0 -31
- package/core/json.js.flow +0 -28
- package/core/json.mjs +0 -15
- package/core/lazy.d.ts +0 -3
- package/core/lazy.js +0 -16
- package/core/lazy.js.flow +0 -15
- package/core/lazy.mjs +0 -11
- package/core/number.d.ts +0 -6
- package/core/number.js +0 -36
- package/core/number.js.flow +0 -40
- package/core/number.mjs +0 -25
- package/core/object.d.ts +0 -38
- package/core/optional.d.ts +0 -5
- package/core/optional.js +0 -50
- package/core/optional.js.flow +0 -41
- package/core/optional.mjs +0 -38
- package/core/string.d.ts +0 -13
- package/core/string.js +0 -80
- package/core/string.js.flow +0 -72
- package/core/string.mjs +0 -58
- package/core/tuple.d.ts +0 -30
- package/core/tuple.js +0 -54
- package/core/tuple.js.flow +0 -51
- package/core/tuple.mjs +0 -45
package/_utils.d.ts
CHANGED
package/_utils.js
CHANGED
|
@@ -4,34 +4,28 @@ exports.__esModule = true;
|
|
|
4
4
|
exports.INDENT = void 0;
|
|
5
5
|
exports.asDate = asDate;
|
|
6
6
|
exports.indent = indent;
|
|
7
|
-
exports.isDate = isDate;
|
|
8
7
|
exports.isMultiline = isMultiline;
|
|
9
8
|
exports.summarize = summarize;
|
|
10
9
|
// $FlowFixMe[unclear-type] - deliberate use of `any`
|
|
11
10
|
// Two spaces of indentation
|
|
12
11
|
var INDENT = ' ';
|
|
13
12
|
/**
|
|
14
|
-
*
|
|
15
|
-
* might get lost by the JS runtime), so we'll have to reside to more runtime
|
|
16
|
-
* inspection checks.
|
|
17
|
-
*
|
|
18
|
-
* Taken from https://stackoverflow.com/a/44198641
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
exports.INDENT = INDENT;
|
|
22
|
-
|
|
23
|
-
function isDate(value) {
|
|
24
|
-
return !!value && // $FlowFixMe[method-unbinding]
|
|
25
|
-
Object.prototype.toString.call(value) === '[object Date]' && !isNaN(value);
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Is value is a valid Date instance, then return that. If not, then return
|
|
13
|
+
* Is value is a valid Date instance, then return that. If not, then return
|
|
29
14
|
* null.
|
|
30
15
|
*/
|
|
31
16
|
|
|
17
|
+
exports.INDENT = INDENT;
|
|
32
18
|
|
|
33
19
|
function asDate(value) {
|
|
34
|
-
|
|
20
|
+
//
|
|
21
|
+
// `x instanceof Date` checks are unreliable across stack frames (that
|
|
22
|
+
// information might get lost by the JS runtime), so we'll have to reside
|
|
23
|
+
// to more runtime inspection checks.
|
|
24
|
+
//
|
|
25
|
+
// Taken from https://stackoverflow.com/a/44198641
|
|
26
|
+
//
|
|
27
|
+
return !!value && // $FlowFixMe[method-unbinding]
|
|
28
|
+
Object.prototype.toString.call(value) === '[object Date]' && !isNaN(value) ? value : null;
|
|
35
29
|
}
|
|
36
30
|
|
|
37
31
|
function isMultiline(s) {
|
package/_utils.js.flow
CHANGED
|
@@ -9,27 +9,23 @@ export type _Any = any;
|
|
|
9
9
|
export const INDENT = ' ';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* inspection checks.
|
|
15
|
-
*
|
|
16
|
-
* Taken from https://stackoverflow.com/a/44198641
|
|
12
|
+
* Is value is a valid Date instance, then return that. If not, then return
|
|
13
|
+
* null.
|
|
17
14
|
*/
|
|
18
|
-
export function
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
export function asDate(value: mixed): Date | null {
|
|
16
|
+
//
|
|
17
|
+
// `x instanceof Date` checks are unreliable across stack frames (that
|
|
18
|
+
// information might get lost by the JS runtime), so we'll have to reside
|
|
19
|
+
// to more runtime inspection checks.
|
|
20
|
+
//
|
|
21
|
+
// Taken from https://stackoverflow.com/a/44198641
|
|
22
|
+
//
|
|
23
|
+
return !!value &&
|
|
21
24
|
// $FlowFixMe[method-unbinding]
|
|
22
25
|
Object.prototype.toString.call(value) === '[object Date]' &&
|
|
23
26
|
!isNaN(value)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Is value is a valid Date instance, then return that. If not, then return
|
|
29
|
-
* null.
|
|
30
|
-
*/
|
|
31
|
-
export function asDate(value: mixed): Date | null {
|
|
32
|
-
return isDate(value) ? ((value: _Any): Date) : null;
|
|
27
|
+
? ((value: _Any): Date)
|
|
28
|
+
: null;
|
|
33
29
|
}
|
|
34
30
|
|
|
35
31
|
export function isMultiline(s: string): boolean {
|
package/_utils.mjs
CHANGED
|
@@ -2,24 +2,20 @@
|
|
|
2
2
|
// Two spaces of indentation
|
|
3
3
|
export var INDENT = ' ';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
* might get lost by the JS runtime), so we'll have to reside to more runtime
|
|
7
|
-
* inspection checks.
|
|
8
|
-
*
|
|
9
|
-
* Taken from https://stackoverflow.com/a/44198641
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
export function isDate(value) {
|
|
13
|
-
return !!value && // $FlowFixMe[method-unbinding]
|
|
14
|
-
Object.prototype.toString.call(value) === '[object Date]' && !isNaN(value);
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Is value is a valid Date instance, then return that. If not, then return
|
|
5
|
+
* Is value is a valid Date instance, then return that. If not, then return
|
|
18
6
|
* null.
|
|
19
7
|
*/
|
|
20
8
|
|
|
21
9
|
export function asDate(value) {
|
|
22
|
-
|
|
10
|
+
//
|
|
11
|
+
// `x instanceof Date` checks are unreliable across stack frames (that
|
|
12
|
+
// information might get lost by the JS runtime), so we'll have to reside
|
|
13
|
+
// to more runtime inspection checks.
|
|
14
|
+
//
|
|
15
|
+
// Taken from https://stackoverflow.com/a/44198641
|
|
16
|
+
//
|
|
17
|
+
return !!value && // $FlowFixMe[method-unbinding]
|
|
18
|
+
Object.prototype.toString.call(value) === '[object Date]' && !isNaN(value) ? value : null;
|
|
23
19
|
}
|
|
24
20
|
export function isMultiline(s) {
|
|
25
21
|
return s.indexOf('\n') >= 0;
|
package/format.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Annotation } from './annotate';
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
|
|
3
|
+
export type Formatter = (err: Annotation) => string | Error;
|
|
4
|
+
|
|
5
|
+
export const formatInline: Formatter;
|
|
6
|
+
export const formatShort: Formatter;
|
package/format.js
CHANGED
|
@@ -93,7 +93,7 @@ function serializeValue(value) {
|
|
|
93
93
|
return "new Date(" + JSON.stringify(valueAsDate.toISOString()) + ")";
|
|
94
94
|
} else if (value instanceof Date) {
|
|
95
95
|
// NOTE: Using `instanceof Date` is unreliable way of checking dates.
|
|
96
|
-
// If this case occurs (and it didn't pass the prior
|
|
96
|
+
// If this case occurs (and it didn't pass the prior asDate())
|
|
97
97
|
// check, then this must be the case where it's an invalid date.
|
|
98
98
|
return '(Invalid Date)';
|
|
99
99
|
} else {
|
package/format.js.flow
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
import { summarize as _summarize, asDate, INDENT, indent, isMultiline } from './_utils';
|
|
4
4
|
import type { Annotation, ArrayAnnotation, ObjectAnnotation } from './annotate';
|
|
5
5
|
|
|
6
|
+
export type Formatter = (err: Annotation) => string | Error;
|
|
7
|
+
|
|
6
8
|
function serializeString(s: string, width: number = 80): string {
|
|
7
9
|
// Full string
|
|
8
10
|
// Abbreviated to $maxlen i.e. "Vincent Driess..." [truncated]
|
|
@@ -74,7 +76,7 @@ export function serializeValue(value: mixed): string {
|
|
|
74
76
|
return `new Date(${JSON.stringify(valueAsDate.toISOString())})`;
|
|
75
77
|
} else if (value instanceof Date) {
|
|
76
78
|
// NOTE: Using `instanceof Date` is unreliable way of checking dates.
|
|
77
|
-
// If this case occurs (and it didn't pass the prior
|
|
79
|
+
// If this case occurs (and it didn't pass the prior asDate())
|
|
78
80
|
// check, then this must be the case where it's an invalid date.
|
|
79
81
|
return '(Invalid Date)';
|
|
80
82
|
} else {
|
package/format.mjs
CHANGED
|
@@ -85,7 +85,7 @@ export function serializeValue(value) {
|
|
|
85
85
|
return "new Date(" + JSON.stringify(valueAsDate.toISOString()) + ")";
|
|
86
86
|
} else if (value instanceof Date) {
|
|
87
87
|
// NOTE: Using `instanceof Date` is unreliable way of checking dates.
|
|
88
|
-
// If this case occurs (and it didn't pass the prior
|
|
88
|
+
// If this case occurs (and it didn't pass the prior asDate())
|
|
89
89
|
// check, then this must be the case where it's an invalid date.
|
|
90
90
|
return '(Invalid Date)';
|
|
91
91
|
} else {
|
package/index.d.ts
CHANGED
|
@@ -1,26 +1,23 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
DecodeResult,
|
|
4
|
-
DecoderType,
|
|
5
|
-
Guard,
|
|
6
|
-
GuardType,
|
|
7
|
-
Predicate,
|
|
8
|
-
Scalar,
|
|
9
|
-
} from './_types';
|
|
10
|
-
export { Result } from './result';
|
|
11
|
-
export { JSONValue, JSONObject, JSONArray } from './core/json';
|
|
12
|
-
|
|
13
|
-
export { guard } from './_guard';
|
|
14
|
-
|
|
15
|
-
export { compose, predicate, prep, transform } from './core/composition';
|
|
1
|
+
export { DecodeResult, Decoder, DecoderType, Scalar, define } from './Decoder';
|
|
2
|
+
export { JSONValue, JSONObject, JSONArray } from './lib/json';
|
|
16
3
|
|
|
17
|
-
export {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
4
|
+
export {
|
|
5
|
+
always,
|
|
6
|
+
constant,
|
|
7
|
+
hardcoded,
|
|
8
|
+
maybe,
|
|
9
|
+
mixed,
|
|
10
|
+
nullable,
|
|
11
|
+
null_,
|
|
12
|
+
optional,
|
|
13
|
+
undefined_,
|
|
14
|
+
unknown,
|
|
15
|
+
} from './lib/basics';
|
|
16
|
+
export { array, nonEmptyArray, poja, set, tuple } from './lib/arrays';
|
|
17
|
+
export { boolean, numericBoolean, truthy } from './lib/booleans';
|
|
18
|
+
export { date, iso8601 } from './lib/dates';
|
|
19
|
+
export { dict, exact, inexact, mapping, object, pojo } from './lib/objects';
|
|
20
|
+
export { either, oneOf, taggedUnion } from './lib/unions';
|
|
24
21
|
export {
|
|
25
22
|
email,
|
|
26
23
|
httpsUrl,
|
|
@@ -31,12 +28,13 @@ export {
|
|
|
31
28
|
uuid,
|
|
32
29
|
uuidv1,
|
|
33
30
|
uuidv4,
|
|
34
|
-
} from './
|
|
35
|
-
export { fail } from './
|
|
36
|
-
export {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
31
|
+
} from './lib/strings';
|
|
32
|
+
export { fail, instanceOf, lazy, never, prep } from './lib/utilities';
|
|
33
|
+
export {
|
|
34
|
+
anyNumber,
|
|
35
|
+
integer,
|
|
36
|
+
number,
|
|
37
|
+
positiveInteger,
|
|
38
|
+
positiveNumber,
|
|
39
|
+
} from './lib/numbers';
|
|
40
|
+
export { json, jsonObject, jsonArray } from './lib/json';
|
package/index.js
CHANGED
|
@@ -1,111 +1,89 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
|
-
exports.uuidv4 = exports.uuidv1 = exports.uuid = exports.url = exports.unknown = exports.undefined_ = exports.tuple = exports.truthy = exports.
|
|
4
|
+
exports.uuidv4 = exports.uuidv1 = exports.uuid = exports.url = exports.unknown = exports.undefined_ = exports.tuple = exports.truthy = exports.taggedUnion = exports.string = exports.set = exports.regex = exports.prep = exports.positiveNumber = exports.positiveInteger = exports.pojo = exports.poja = exports.optional = exports.oneOf = exports.object = exports.numericBoolean = exports.number = exports.nullable = exports.null_ = exports.nonEmptyString = exports.nonEmptyArray = exports.never = exports.mixed = exports.maybe = exports.mapping = exports.lazy = exports.jsonObject = exports.jsonArray = exports.json = exports.iso8601 = exports.integer = exports.instanceOf = exports.inexact = exports.httpsUrl = exports.hardcoded = exports.fail = exports.exact = exports.email = exports.either = exports.dict = exports.define = exports.date = exports.constant = exports["boolean"] = exports.array = exports.anyNumber = exports.always = void 0;
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _Decoder = require("./Decoder");
|
|
7
7
|
|
|
8
|
-
exports.
|
|
8
|
+
exports.define = _Decoder.define;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _basics = require("./lib/basics");
|
|
11
11
|
|
|
12
|
-
exports.
|
|
13
|
-
exports.
|
|
14
|
-
exports.
|
|
15
|
-
exports.
|
|
12
|
+
exports.always = _basics.always;
|
|
13
|
+
exports.constant = _basics.constant;
|
|
14
|
+
exports.hardcoded = _basics.hardcoded;
|
|
15
|
+
exports.maybe = _basics.maybe;
|
|
16
|
+
exports.mixed = _basics.mixed;
|
|
17
|
+
exports.nullable = _basics.nullable;
|
|
18
|
+
exports.null_ = _basics.null_;
|
|
19
|
+
exports.optional = _basics.optional;
|
|
20
|
+
exports.undefined_ = _basics.undefined_;
|
|
21
|
+
exports.unknown = _basics.unknown;
|
|
16
22
|
|
|
17
|
-
var
|
|
23
|
+
var _arrays = require("./lib/arrays");
|
|
18
24
|
|
|
19
|
-
exports.array =
|
|
20
|
-
exports.nonEmptyArray =
|
|
21
|
-
exports.poja =
|
|
22
|
-
exports.set =
|
|
25
|
+
exports.array = _arrays.array;
|
|
26
|
+
exports.nonEmptyArray = _arrays.nonEmptyArray;
|
|
27
|
+
exports.poja = _arrays.poja;
|
|
28
|
+
exports.set = _arrays.set;
|
|
29
|
+
exports.tuple = _arrays.tuple;
|
|
23
30
|
|
|
24
|
-
var
|
|
31
|
+
var _booleans = require("./lib/booleans");
|
|
25
32
|
|
|
26
|
-
exports["boolean"] =
|
|
27
|
-
exports.numericBoolean =
|
|
28
|
-
exports.truthy =
|
|
33
|
+
exports["boolean"] = _booleans["boolean"];
|
|
34
|
+
exports.numericBoolean = _booleans.numericBoolean;
|
|
35
|
+
exports.truthy = _booleans.truthy;
|
|
29
36
|
|
|
30
|
-
var
|
|
37
|
+
var _dates = require("./lib/dates");
|
|
31
38
|
|
|
32
|
-
exports.
|
|
33
|
-
exports.
|
|
34
|
-
exports.mixed = _constants.mixed;
|
|
35
|
-
exports.null_ = _constants.null_;
|
|
36
|
-
exports.undefined_ = _constants.undefined_;
|
|
37
|
-
exports.unknown = _constants.unknown;
|
|
39
|
+
exports.date = _dates.date;
|
|
40
|
+
exports.iso8601 = _dates.iso8601;
|
|
38
41
|
|
|
39
|
-
var
|
|
42
|
+
var _objects = require("./lib/objects");
|
|
40
43
|
|
|
41
|
-
exports.
|
|
42
|
-
exports.
|
|
44
|
+
exports.dict = _objects.dict;
|
|
45
|
+
exports.exact = _objects.exact;
|
|
46
|
+
exports.inexact = _objects.inexact;
|
|
47
|
+
exports.mapping = _objects.mapping;
|
|
48
|
+
exports.object = _objects.object;
|
|
49
|
+
exports.pojo = _objects.pojo;
|
|
43
50
|
|
|
44
|
-
var
|
|
51
|
+
var _unions = require("./lib/unions");
|
|
45
52
|
|
|
46
|
-
exports.
|
|
53
|
+
exports.either = _unions.either;
|
|
54
|
+
exports.oneOf = _unions.oneOf;
|
|
55
|
+
exports.taggedUnion = _unions.taggedUnion;
|
|
47
56
|
|
|
48
|
-
var
|
|
57
|
+
var _strings = require("./lib/strings");
|
|
49
58
|
|
|
50
|
-
exports.
|
|
51
|
-
exports.
|
|
52
|
-
exports.
|
|
53
|
-
exports.
|
|
54
|
-
exports.
|
|
55
|
-
exports.
|
|
59
|
+
exports.email = _strings.email;
|
|
60
|
+
exports.httpsUrl = _strings.httpsUrl;
|
|
61
|
+
exports.nonEmptyString = _strings.nonEmptyString;
|
|
62
|
+
exports.regex = _strings.regex;
|
|
63
|
+
exports.string = _strings.string;
|
|
64
|
+
exports.url = _strings.url;
|
|
65
|
+
exports.uuid = _strings.uuid;
|
|
66
|
+
exports.uuidv1 = _strings.uuidv1;
|
|
67
|
+
exports.uuidv4 = _strings.uuidv4;
|
|
56
68
|
|
|
57
|
-
var
|
|
69
|
+
var _utilities = require("./lib/utilities");
|
|
58
70
|
|
|
59
|
-
exports.
|
|
60
|
-
exports.
|
|
71
|
+
exports.fail = _utilities.fail;
|
|
72
|
+
exports.instanceOf = _utilities.instanceOf;
|
|
73
|
+
exports.lazy = _utilities.lazy;
|
|
74
|
+
exports.never = _utilities.never;
|
|
75
|
+
exports.prep = _utilities.prep;
|
|
61
76
|
|
|
62
|
-
var
|
|
77
|
+
var _numbers = require("./lib/numbers");
|
|
63
78
|
|
|
64
|
-
exports.
|
|
65
|
-
exports.
|
|
66
|
-
exports.
|
|
67
|
-
exports.
|
|
68
|
-
exports.
|
|
69
|
-
exports.url = _string.url;
|
|
70
|
-
exports.uuid = _string.uuid;
|
|
71
|
-
exports.uuidv1 = _string.uuidv1;
|
|
72
|
-
exports.uuidv4 = _string.uuidv4;
|
|
79
|
+
exports.anyNumber = _numbers.anyNumber;
|
|
80
|
+
exports.integer = _numbers.integer;
|
|
81
|
+
exports.number = _numbers.number;
|
|
82
|
+
exports.positiveInteger = _numbers.positiveInteger;
|
|
83
|
+
exports.positiveNumber = _numbers.positiveNumber;
|
|
73
84
|
|
|
74
|
-
var
|
|
75
|
-
|
|
76
|
-
exports.fail = _fail.fail;
|
|
77
|
-
|
|
78
|
-
var _instanceOf = require("./core/instanceOf");
|
|
79
|
-
|
|
80
|
-
exports.instanceOf = _instanceOf.instanceOf;
|
|
81
|
-
|
|
82
|
-
var _number = require("./core/number");
|
|
83
|
-
|
|
84
|
-
exports.integer = _number.integer;
|
|
85
|
-
exports.number = _number.number;
|
|
86
|
-
exports.positiveInteger = _number.positiveInteger;
|
|
87
|
-
exports.positiveNumber = _number.positiveNumber;
|
|
88
|
-
|
|
89
|
-
var _json = require("./core/json");
|
|
85
|
+
var _json = require("./lib/json");
|
|
90
86
|
|
|
91
87
|
exports.json = _json.json;
|
|
92
88
|
exports.jsonObject = _json.jsonObject;
|
|
93
|
-
exports.jsonArray = _json.jsonArray;
|
|
94
|
-
|
|
95
|
-
var _lazy = require("./core/lazy");
|
|
96
|
-
|
|
97
|
-
exports.lazy = _lazy.lazy;
|
|
98
|
-
|
|
99
|
-
var _optional = require("./core/optional");
|
|
100
|
-
|
|
101
|
-
exports.maybe = _optional.maybe;
|
|
102
|
-
exports.nullable = _optional.nullable;
|
|
103
|
-
exports.optional = _optional.optional;
|
|
104
|
-
|
|
105
|
-
var _dispatch = require("./core/dispatch");
|
|
106
|
-
|
|
107
|
-
exports.taggedUnion = _dispatch.taggedUnion;
|
|
108
|
-
|
|
109
|
-
var _tuple = require("./core/tuple");
|
|
110
|
-
|
|
111
|
-
exports.tuple = _tuple.tuple;
|
|
89
|
+
exports.jsonArray = _json.jsonArray;
|
package/index.js.flow
CHANGED
|
@@ -1,46 +1,27 @@
|
|
|
1
1
|
// @flow strict
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* See http://elmplayground.com/decoding-json-in-elm-1 for an introduction.
|
|
6
|
-
*
|
|
7
|
-
* Why? All JSON responses coming from our API endpoints are just that: free-form
|
|
8
|
-
* JSON data. To Flow, the only type classification possilbe is "any" -- effectively
|
|
9
|
-
* turning off all type checks for anything related to JSON. To the receiving end
|
|
10
|
-
* (our frontend), the structure of that data is completely opaque to any type
|
|
11
|
-
* checkers since JSON values can be anything: an object, an array, null, a string,
|
|
12
|
-
* a bool, etc. Our type system is not a runtime type system, so we need a way of
|
|
13
|
-
* "converting" an any-type JSON value into a type that we want to work with in our
|
|
14
|
-
* frontend code base.
|
|
15
|
-
*
|
|
16
|
-
* Elm's solution to this problem is to define composable decoders: functions that
|
|
17
|
-
* take anything and either fail with an error, or guarantee to return the expected
|
|
18
|
-
* type. In our case, it's fine to fail with a runtime error.
|
|
19
|
-
*
|
|
20
|
-
*/
|
|
21
|
-
export type {
|
|
22
|
-
Decoder,
|
|
23
|
-
DecodeResult,
|
|
24
|
-
DecoderType,
|
|
25
|
-
Guard,
|
|
26
|
-
GuardType,
|
|
27
|
-
Predicate,
|
|
28
|
-
Scalar,
|
|
29
|
-
} from './_types';
|
|
30
|
-
export type { Result } from './result';
|
|
31
|
-
export type { JSONValue, JSONObject, JSONArray } from './core/json';
|
|
3
|
+
export type { Decoder, DecodeResult, DecoderType, Scalar } from './Decoder';
|
|
4
|
+
export type { JSONValue, JSONObject, JSONArray } from './lib/json';
|
|
32
5
|
|
|
33
|
-
export {
|
|
6
|
+
export { define } from './Decoder';
|
|
34
7
|
|
|
35
|
-
export {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
8
|
+
export {
|
|
9
|
+
always,
|
|
10
|
+
constant,
|
|
11
|
+
hardcoded,
|
|
12
|
+
maybe,
|
|
13
|
+
mixed,
|
|
14
|
+
nullable,
|
|
15
|
+
null_,
|
|
16
|
+
optional,
|
|
17
|
+
undefined_,
|
|
18
|
+
unknown,
|
|
19
|
+
} from './lib/basics';
|
|
20
|
+
export { array, nonEmptyArray, poja, set, tuple } from './lib/arrays';
|
|
21
|
+
export { boolean, numericBoolean, truthy } from './lib/booleans';
|
|
22
|
+
export { date, iso8601 } from './lib/dates';
|
|
23
|
+
export { dict, exact, inexact, mapping, object, pojo } from './lib/objects';
|
|
24
|
+
export { either, oneOf, taggedUnion } from './lib/unions';
|
|
44
25
|
export {
|
|
45
26
|
email,
|
|
46
27
|
httpsUrl,
|
|
@@ -51,12 +32,13 @@ export {
|
|
|
51
32
|
uuid,
|
|
52
33
|
uuidv1,
|
|
53
34
|
uuidv4,
|
|
54
|
-
} from './
|
|
55
|
-
export { fail } from './
|
|
56
|
-
export {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
35
|
+
} from './lib/strings';
|
|
36
|
+
export { fail, instanceOf, lazy, never, prep } from './lib/utilities';
|
|
37
|
+
export {
|
|
38
|
+
anyNumber,
|
|
39
|
+
integer,
|
|
40
|
+
number,
|
|
41
|
+
positiveInteger,
|
|
42
|
+
positiveNumber,
|
|
43
|
+
} from './lib/numbers';
|
|
44
|
+
export { json, jsonObject, jsonArray } from './lib/json';
|
package/index.mjs
CHANGED
|
@@ -1,36 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* frontend code base.
|
|
13
|
-
*
|
|
14
|
-
* Elm's solution to this problem is to define composable decoders: functions that
|
|
15
|
-
* take anything and either fail with an error, or guarantee to return the expected
|
|
16
|
-
* type. In our case, it's fine to fail with a runtime error.
|
|
17
|
-
*
|
|
18
|
-
*/
|
|
19
|
-
export { guard } from './_guard.mjs';
|
|
20
|
-
export { compose, predicate, prep, transform } from './core/composition.mjs';
|
|
21
|
-
export { array, nonEmptyArray, poja, set } from './core/array.mjs';
|
|
22
|
-
export { boolean, numericBoolean, truthy } from './core/boolean.mjs';
|
|
23
|
-
export { constant, hardcoded, mixed, null_, undefined_, unknown } from './core/constants.mjs';
|
|
24
|
-
export { date, iso8601 } from './core/date.mjs';
|
|
25
|
-
export { describe } from './core/describe.mjs';
|
|
26
|
-
export { dict, exact, inexact, mapping, object, pojo } from './core/object.mjs';
|
|
27
|
-
export { either, oneOf } from './core/either.mjs';
|
|
28
|
-
export { email, httpsUrl, nonEmptyString, regex, string, url, uuid, uuidv1, uuidv4 } from './core/string.mjs';
|
|
29
|
-
export { fail } from './core/fail.mjs';
|
|
30
|
-
export { instanceOf } from './core/instanceOf.mjs';
|
|
31
|
-
export { integer, number, positiveInteger, positiveNumber } from './core/number.mjs';
|
|
32
|
-
export { json, jsonObject, jsonArray } from './core/json.mjs';
|
|
33
|
-
export { lazy } from './core/lazy.mjs';
|
|
34
|
-
export { maybe, nullable, optional } from './core/optional.mjs';
|
|
35
|
-
export { taggedUnion } from './core/dispatch.mjs';
|
|
36
|
-
export { tuple } from './core/tuple.mjs';
|
|
1
|
+
export { define } from './Decoder.mjs';
|
|
2
|
+
export { always, constant, hardcoded, maybe, mixed, nullable, null_, optional, undefined_, unknown } from './lib/basics.mjs';
|
|
3
|
+
export { array, nonEmptyArray, poja, set, tuple } from './lib/arrays.mjs';
|
|
4
|
+
export { boolean, numericBoolean, truthy } from './lib/booleans.mjs';
|
|
5
|
+
export { date, iso8601 } from './lib/dates.mjs';
|
|
6
|
+
export { dict, exact, inexact, mapping, object, pojo } from './lib/objects.mjs';
|
|
7
|
+
export { either, oneOf, taggedUnion } from './lib/unions.mjs';
|
|
8
|
+
export { email, httpsUrl, nonEmptyString, regex, string, url, uuid, uuidv1, uuidv4 } from './lib/strings.mjs';
|
|
9
|
+
export { fail, instanceOf, lazy, never, prep } from './lib/utilities.mjs';
|
|
10
|
+
export { anyNumber, integer, number, positiveInteger, positiveNumber } from './lib/numbers.mjs';
|
|
11
|
+
export { json, jsonObject, jsonArray } from './lib/json.mjs';
|
|
File without changes
|
package/lib/arrays.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/// <reference lib="es6" />
|
|
2
|
+
|
|
3
|
+
import { Decoder } from '../Decoder';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Accepts any array, but doesn't validate its items further.
|
|
7
|
+
*
|
|
8
|
+
* "poja" means "plain old JavaScript array", a play on `pojo()`.
|
|
9
|
+
*/
|
|
10
|
+
export const poja: Decoder<unknown[]>;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Accepts arrays of whatever the given decoder accepts.
|
|
14
|
+
*/
|
|
15
|
+
export function array<T>(decoder: Decoder<T>): Decoder<T[]>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Like `array()`, but will reject arrays with 0 elements.
|
|
19
|
+
*/
|
|
20
|
+
export function nonEmptyArray<T>(decoder: Decoder<T>): Decoder<[T, ...T[]]>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Similar to `array()`, but returns the result as an [ES6
|
|
24
|
+
* Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set).
|
|
25
|
+
*/
|
|
26
|
+
export function set<T>(decoder: Decoder<T>): Decoder<Set<T>>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Accepts a tuple (an array with exactly _n_ items) of values accepted by the
|
|
30
|
+
* _n_ given decoders.
|
|
31
|
+
*/
|
|
32
|
+
export function tuple<A>(a: Decoder<A>): Decoder<[A]>;
|
|
33
|
+
export function tuple<A, B>(a: Decoder<A>, b: Decoder<B>): Decoder<[A, B]>;
|
|
34
|
+
export function tuple<A, B, C>(
|
|
35
|
+
a: Decoder<A>,
|
|
36
|
+
b: Decoder<B>,
|
|
37
|
+
c: Decoder<C>,
|
|
38
|
+
): Decoder<[A, B, C]>;
|
|
39
|
+
export function tuple<A, B, C, D>(
|
|
40
|
+
a: Decoder<A>,
|
|
41
|
+
b: Decoder<B>,
|
|
42
|
+
c: Decoder<C>,
|
|
43
|
+
d: Decoder<D>,
|
|
44
|
+
): Decoder<[A, B, C, D]>;
|
|
45
|
+
export function tuple<A, B, C, D, E>(
|
|
46
|
+
a: Decoder<A>,
|
|
47
|
+
b: Decoder<B>,
|
|
48
|
+
c: Decoder<C>,
|
|
49
|
+
d: Decoder<D>,
|
|
50
|
+
e: Decoder<E>,
|
|
51
|
+
): Decoder<[A, B, C, D, E]>;
|
|
52
|
+
export function tuple<A, B, C, D, E, F>(
|
|
53
|
+
a: Decoder<A>,
|
|
54
|
+
b: Decoder<B>,
|
|
55
|
+
c: Decoder<C>,
|
|
56
|
+
d: Decoder<D>,
|
|
57
|
+
e: Decoder<E>,
|
|
58
|
+
f: Decoder<F>,
|
|
59
|
+
): Decoder<[A, B, C, D, E, F]>;
|