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/_utils.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Annotation } from './annotate';
|
|
2
|
+
|
|
3
|
+
export function asDate(value: unknown): Date | null;
|
|
4
|
+
export function isMultiline(s: string): boolean;
|
|
5
|
+
export function indent(s: string, prefix?: string): string;
|
|
6
|
+
export function summarize(
|
|
7
|
+
ann: Annotation,
|
|
8
|
+
keypath?: ReadonlyArray<number | string>,
|
|
9
|
+
): string[];
|
|
@@ -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
|
-
// $FlowFixMe[unclear-type] - deliberate
|
|
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) {
|
|
@@ -2,34 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
import type { Annotation } from './annotate';
|
|
4
4
|
|
|
5
|
-
// $FlowFixMe[unclear-type] - deliberate
|
|
6
|
-
type
|
|
5
|
+
// $FlowFixMe[unclear-type] - deliberate use of `any`
|
|
6
|
+
export type _Any = any;
|
|
7
7
|
|
|
8
8
|
// Two spaces of indentation
|
|
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: cast): Date) : null;
|
|
27
|
+
? ((value: _Any): Date)
|
|
28
|
+
: null;
|
|
33
29
|
}
|
|
34
30
|
|
|
35
31
|
export function isMultiline(s: string): boolean {
|
|
@@ -1,25 +1,21 @@
|
|
|
1
|
-
// $FlowFixMe[unclear-type] - deliberate
|
|
1
|
+
// $FlowFixMe[unclear-type] - deliberate use of `any`
|
|
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;
|
|
@@ -1,29 +1,35 @@
|
|
|
1
1
|
export interface ObjectAnnotation {
|
|
2
|
-
type: 'object';
|
|
3
|
-
fields: { [key: string]: Annotation };
|
|
4
|
-
text?: string;
|
|
2
|
+
readonly type: 'object';
|
|
3
|
+
readonly fields: { readonly [key: string]: Annotation };
|
|
4
|
+
readonly text?: string;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
export interface ArrayAnnotation {
|
|
8
|
-
type: 'array';
|
|
9
|
-
items: readonly Annotation[];
|
|
10
|
-
text?: string;
|
|
8
|
+
readonly type: 'array';
|
|
9
|
+
readonly items: readonly Annotation[];
|
|
10
|
+
readonly text?: string;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export interface ScalarAnnotation {
|
|
14
|
-
type: 'scalar';
|
|
15
|
-
value: unknown;
|
|
16
|
-
text?: string;
|
|
14
|
+
readonly type: 'scalar';
|
|
15
|
+
readonly value: unknown;
|
|
16
|
+
readonly text?: string;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export interface FunctionAnnotation {
|
|
20
|
-
type: 'function';
|
|
21
|
-
text?: string;
|
|
20
|
+
readonly type: 'function';
|
|
21
|
+
readonly text?: string;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
export interface CircularRefAnnotation {
|
|
25
|
-
type: 'circular-ref';
|
|
26
|
-
text?: string;
|
|
25
|
+
readonly type: 'circular-ref';
|
|
26
|
+
readonly text?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface UnknownAnnotation {
|
|
30
|
+
readonly type: 'unknown';
|
|
31
|
+
readonly value: unknown;
|
|
32
|
+
readonly text?: string;
|
|
27
33
|
}
|
|
28
34
|
|
|
29
35
|
export type Annotation =
|
|
@@ -31,28 +37,26 @@ export type Annotation =
|
|
|
31
37
|
| ArrayAnnotation
|
|
32
38
|
| ScalarAnnotation
|
|
33
39
|
| FunctionAnnotation
|
|
34
|
-
| CircularRefAnnotation
|
|
40
|
+
| CircularRefAnnotation
|
|
41
|
+
| UnknownAnnotation;
|
|
35
42
|
|
|
36
43
|
export function object(
|
|
37
|
-
fields: { [key: string]: Annotation },
|
|
44
|
+
fields: { readonly [key: string]: Annotation },
|
|
38
45
|
text?: string,
|
|
39
46
|
): ObjectAnnotation;
|
|
40
47
|
export function array(items: readonly Annotation[], text?: string): ArrayAnnotation;
|
|
41
48
|
export function func(text?: string): FunctionAnnotation;
|
|
49
|
+
export function unknown(value: unknown, text?: string): UnknownAnnotation;
|
|
42
50
|
export function scalar(value: unknown, text?: string): ScalarAnnotation;
|
|
43
51
|
export function circularRef(text?: string): CircularRefAnnotation;
|
|
44
|
-
|
|
45
52
|
export function updateText<A extends Annotation>(annotation: A, text?: string): A;
|
|
46
|
-
|
|
47
53
|
export function merge(
|
|
48
54
|
objAnnotation: ObjectAnnotation,
|
|
49
|
-
fields: { [key: string]: Annotation },
|
|
55
|
+
fields: { readonly [key: string]: Annotation },
|
|
50
56
|
): ObjectAnnotation;
|
|
51
|
-
|
|
52
57
|
export function asAnnotation(thing: unknown): Annotation | void;
|
|
53
|
-
|
|
54
58
|
export function annotate(value: unknown, text?: string): Annotation;
|
|
55
59
|
export function annotateObject(
|
|
56
|
-
obj: { [
|
|
60
|
+
obj: { readonly [field: string]: unknown },
|
|
57
61
|
text?: string,
|
|
58
62
|
): ObjectAnnotation;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/format.d.ts
ADDED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.formatInline = formatInline;
|
|
5
|
+
exports.formatShort = formatShort;
|
|
5
6
|
exports.serializeAnnotation = serializeAnnotation;
|
|
6
7
|
exports.serializeValue = serializeValue;
|
|
7
8
|
|
|
8
|
-
var _utils = require("
|
|
9
|
+
var _utils = require("./_utils");
|
|
9
10
|
|
|
10
11
|
function serializeString(s, width) {
|
|
11
12
|
if (width === void 0) {
|
|
@@ -92,7 +93,7 @@ function serializeValue(value) {
|
|
|
92
93
|
return "new Date(" + JSON.stringify(valueAsDate.toISOString()) + ")";
|
|
93
94
|
} else if (value instanceof Date) {
|
|
94
95
|
// NOTE: Using `instanceof Date` is unreliable way of checking dates.
|
|
95
|
-
// If this case occurs (and it didn't pass the prior
|
|
96
|
+
// If this case occurs (and it didn't pass the prior asDate())
|
|
96
97
|
// check, then this must be the case where it's an invalid date.
|
|
97
98
|
return '(Invalid Date)';
|
|
98
99
|
} else {
|
|
@@ -143,4 +144,8 @@ function formatInline(ann) {
|
|
|
143
144
|
} else {
|
|
144
145
|
return serialized;
|
|
145
146
|
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function formatShort(ann) {
|
|
150
|
+
return (0, _utils.summarize)(ann, []).join('\n');
|
|
146
151
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// @flow strict
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import type { Annotation, ArrayAnnotation, ObjectAnnotation } from '
|
|
3
|
+
import { summarize as _summarize, asDate, INDENT, indent, isMultiline } from './_utils';
|
|
4
|
+
import type { Annotation, ArrayAnnotation, ObjectAnnotation } from './annotate';
|
|
5
|
+
|
|
6
|
+
export type Formatter = (err: Annotation) => string | Error;
|
|
5
7
|
|
|
6
8
|
function serializeString(s: string, width: number = 80): string {
|
|
7
9
|
// Full string
|
|
@@ -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 {
|
|
@@ -120,3 +122,7 @@ export function formatInline(ann: Annotation): string {
|
|
|
120
122
|
return serialized;
|
|
121
123
|
}
|
|
122
124
|
}
|
|
125
|
+
|
|
126
|
+
export function formatShort(ann: Annotation): string {
|
|
127
|
+
return _summarize(ann, []).join('\n');
|
|
128
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { summarize as _summarize, asDate, INDENT, indent, isMultiline } from './_utils.mjs';
|
|
2
2
|
|
|
3
3
|
function serializeString(s, width) {
|
|
4
4
|
if (width === void 0) {
|
|
@@ -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 {
|
|
@@ -134,4 +134,7 @@ export function formatInline(ann) {
|
|
|
134
134
|
} else {
|
|
135
135
|
return serialized;
|
|
136
136
|
}
|
|
137
|
+
}
|
|
138
|
+
export function formatShort(ann) {
|
|
139
|
+
return _summarize(ann, []).join('\n');
|
|
137
140
|
}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export { DecodeResult, Decoder, DecoderType, Scalar, define } from './Decoder';
|
|
2
|
+
export { JSONValue, JSONObject, JSONArray } from './lib/json';
|
|
3
|
+
|
|
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';
|
|
21
|
+
export {
|
|
22
|
+
email,
|
|
23
|
+
httpsUrl,
|
|
24
|
+
nonEmptyString,
|
|
25
|
+
regex,
|
|
26
|
+
string,
|
|
27
|
+
url,
|
|
28
|
+
uuid,
|
|
29
|
+
uuidv1,
|
|
30
|
+
uuidv4,
|
|
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
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
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
|
+
|
|
6
|
+
var _Decoder = require("./Decoder");
|
|
7
|
+
|
|
8
|
+
exports.define = _Decoder.define;
|
|
9
|
+
|
|
10
|
+
var _basics = require("./lib/basics");
|
|
11
|
+
|
|
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;
|
|
22
|
+
|
|
23
|
+
var _arrays = require("./lib/arrays");
|
|
24
|
+
|
|
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;
|
|
30
|
+
|
|
31
|
+
var _booleans = require("./lib/booleans");
|
|
32
|
+
|
|
33
|
+
exports["boolean"] = _booleans["boolean"];
|
|
34
|
+
exports.numericBoolean = _booleans.numericBoolean;
|
|
35
|
+
exports.truthy = _booleans.truthy;
|
|
36
|
+
|
|
37
|
+
var _dates = require("./lib/dates");
|
|
38
|
+
|
|
39
|
+
exports.date = _dates.date;
|
|
40
|
+
exports.iso8601 = _dates.iso8601;
|
|
41
|
+
|
|
42
|
+
var _objects = require("./lib/objects");
|
|
43
|
+
|
|
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;
|
|
50
|
+
|
|
51
|
+
var _unions = require("./lib/unions");
|
|
52
|
+
|
|
53
|
+
exports.either = _unions.either;
|
|
54
|
+
exports.oneOf = _unions.oneOf;
|
|
55
|
+
exports.taggedUnion = _unions.taggedUnion;
|
|
56
|
+
|
|
57
|
+
var _strings = require("./lib/strings");
|
|
58
|
+
|
|
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;
|
|
68
|
+
|
|
69
|
+
var _utilities = require("./lib/utilities");
|
|
70
|
+
|
|
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;
|
|
76
|
+
|
|
77
|
+
var _numbers = require("./lib/numbers");
|
|
78
|
+
|
|
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;
|
|
84
|
+
|
|
85
|
+
var _json = require("./lib/json");
|
|
86
|
+
|
|
87
|
+
exports.json = _json.json;
|
|
88
|
+
exports.jsonObject = _json.jsonObject;
|
|
89
|
+
exports.jsonArray = _json.jsonArray;
|
package/index.js.flow
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// @flow strict
|
|
2
|
+
|
|
3
|
+
export type { Decoder, DecodeResult, DecoderType, Scalar } from './Decoder';
|
|
4
|
+
export type { JSONValue, JSONObject, JSONArray } from './lib/json';
|
|
5
|
+
|
|
6
|
+
export { define } from './Decoder';
|
|
7
|
+
|
|
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';
|
|
25
|
+
export {
|
|
26
|
+
email,
|
|
27
|
+
httpsUrl,
|
|
28
|
+
nonEmptyString,
|
|
29
|
+
regex,
|
|
30
|
+
string,
|
|
31
|
+
url,
|
|
32
|
+
uuid,
|
|
33
|
+
uuidv1,
|
|
34
|
+
uuidv4,
|
|
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
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
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';
|
package/{ts → lib}/_helpers.d.ts
RENAMED
|
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]>;
|