decoders 2.0.0-beta8 → 2.0.1
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 +67 -20
- package/Decoder.d.ts +94 -0
- package/Decoder.js +115 -0
- package/Decoder.js.flow +286 -0
- package/Decoder.mjs +108 -0
- package/README.md +122 -1345
- package/_utils.d.ts +0 -1
- package/_utils.js +51 -68
- package/_utils.js.flow +30 -20
- package/_utils.mjs +39 -54
- package/annotate.js +79 -72
- package/annotate.mjs +62 -58
- package/format.d.ts +4 -2
- package/format.js +64 -74
- package/format.js.flow +14 -12
- package/format.mjs +58 -68
- package/index.d.ts +38 -41
- package/index.js +66 -98
- package/index.js.flow +39 -58
- package/index.mjs +11 -37
- package/{core → lib}/_helpers.d.ts +0 -0
- package/lib/arrays.d.ts +59 -0
- package/lib/arrays.js +97 -0
- package/lib/arrays.js.flow +138 -0
- package/lib/arrays.mjs +84 -0
- package/lib/basics.d.ts +93 -0
- package/lib/basics.js +94 -0
- package/lib/basics.js.flow +124 -0
- package/lib/basics.mjs +75 -0
- package/lib/booleans.d.ts +16 -0
- package/lib/booleans.js +25 -0
- package/lib/booleans.js.flow +22 -0
- package/lib/booleans.mjs +15 -0
- package/lib/dates.d.ts +15 -0
- package/lib/dates.js +28 -0
- package/lib/dates.js.flow +40 -0
- package/lib/dates.mjs +19 -0
- package/lib/json.d.ts +35 -0
- package/lib/json.js +33 -0
- package/lib/json.js.flow +50 -0
- package/lib/json.mjs +18 -0
- package/lib/numbers.d.ts +31 -0
- package/lib/numbers.js +31 -0
- package/lib/numbers.js.flow +48 -0
- package/lib/numbers.mjs +21 -0
- package/lib/objects.d.ts +76 -0
- package/lib/objects.js +161 -0
- package/lib/objects.js.flow +238 -0
- package/lib/objects.mjs +147 -0
- package/lib/strings.d.ts +56 -0
- package/lib/strings.js +58 -0
- package/lib/strings.js.flow +90 -0
- package/lib/strings.mjs +40 -0
- package/lib/unions.d.ts +55 -0
- package/lib/unions.js +96 -0
- package/lib/unions.js.flow +155 -0
- package/lib/unions.mjs +83 -0
- package/lib/utilities.d.ts +40 -0
- package/lib/utilities.js +48 -0
- package/lib/utilities.js.flow +65 -0
- package/lib/utilities.mjs +37 -0
- package/package.json +64 -17
- package/result.d.ts +2 -25
- package/result.js +9 -90
- package/result.js.flow +4 -76
- package/result.mjs +5 -71
- 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 -5
- package/core/array.js +0 -104
- package/core/array.js.flow +0 -100
- package/core/array.mjs +0 -91
- 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 -14
- package/core/composition.js +0 -54
- package/core/composition.js.flow +0 -48
- package/core/composition.mjs +0 -44
- 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 -58
- package/core/dispatch.js.flow +0 -58
- package/core/dispatch.mjs +0 -51
- package/core/either.d.ts +0 -61
- package/core/either.js +0 -113
- package/core/either.js.flow +0 -151
- 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/mapping.d.ts +0 -6
- package/core/mapping.js +0 -67
- package/core/mapping.js.flow +0 -62
- package/core/mapping.mjs +0 -58
- 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 -33
- package/core/object.js +0 -190
- package/core/object.js.flow +0 -203
- package/core/object.mjs +0 -175
- 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 -10
- package/core/string.js +0 -68
- package/core/string.js.flow +0 -59
- package/core/string.mjs +0 -49
- package/core/tuple.d.ts +0 -30
- package/core/tuple.js +0 -177
- package/core/tuple.js.flow +0 -211
- package/core/tuple.mjs +0 -159
package/format.mjs
CHANGED
|
@@ -1,140 +1,130 @@
|
|
|
1
|
-
import { summarize as _summarize, asDate, INDENT, indent, isMultiline } from './_utils.mjs'
|
|
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) {
|
|
5
|
-
width = 80
|
|
5
|
+
width = 80
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
// Full string
|
|
9
|
-
// Abbreviated to $maxlen i.e. "Vincent Driess..." [truncated]
|
|
10
|
-
var ser = JSON.stringify(s);
|
|
7
|
+
var ser = JSON.stringify(s)
|
|
11
8
|
|
|
12
9
|
if (ser.length <= width) {
|
|
13
|
-
return ser
|
|
14
|
-
}
|
|
15
|
-
|
|
10
|
+
return ser
|
|
11
|
+
}
|
|
16
12
|
|
|
17
|
-
var truncated = s.substring(0, width - 15) + '...'
|
|
18
|
-
ser = JSON.stringify(truncated) + ' [truncated]'
|
|
19
|
-
return ser
|
|
13
|
+
var truncated = s.substring(0, width - 15) + '...'
|
|
14
|
+
ser = JSON.stringify(truncated) + ' [truncated]'
|
|
15
|
+
return ser
|
|
20
16
|
}
|
|
21
17
|
|
|
22
18
|
function serializeArray(annotation, prefix) {
|
|
23
|
-
var items = annotation.items
|
|
19
|
+
var items = annotation.items
|
|
24
20
|
|
|
25
21
|
if (items.length === 0) {
|
|
26
|
-
return '[]'
|
|
22
|
+
return '[]'
|
|
27
23
|
}
|
|
28
24
|
|
|
29
|
-
var result = []
|
|
25
|
+
var result = []
|
|
30
26
|
items.forEach(function (item) {
|
|
31
|
-
var _serializeAnnotation = serializeAnnotation(item, prefix + INDENT),
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
var _serializeAnnotation = serializeAnnotation(item, '' + prefix + INDENT),
|
|
28
|
+
ser = _serializeAnnotation[0],
|
|
29
|
+
ann = _serializeAnnotation[1]
|
|
34
30
|
|
|
35
|
-
result.push(prefix + INDENT + ser + ',')
|
|
31
|
+
result.push('' + prefix + INDENT + ser + ',')
|
|
36
32
|
|
|
37
33
|
if (ann !== undefined) {
|
|
38
|
-
result.push(indent(ann, prefix + INDENT))
|
|
34
|
+
result.push(indent(ann, '' + prefix + INDENT))
|
|
39
35
|
}
|
|
40
|
-
})
|
|
41
|
-
return ['['].concat(result, [prefix + ']']).join('\n')
|
|
36
|
+
})
|
|
37
|
+
return ['['].concat(result, [prefix + ']']).join('\n')
|
|
42
38
|
}
|
|
43
39
|
|
|
44
40
|
function serializeObject(annotation, prefix) {
|
|
45
|
-
var fields = annotation.fields
|
|
46
|
-
var fieldNames = Object.keys(fields)
|
|
41
|
+
var fields = annotation.fields
|
|
42
|
+
var fieldNames = Object.keys(fields)
|
|
47
43
|
|
|
48
44
|
if (fieldNames.length === 0) {
|
|
49
|
-
return '{}'
|
|
45
|
+
return '{}'
|
|
50
46
|
}
|
|
51
47
|
|
|
52
|
-
var result = []
|
|
48
|
+
var result = []
|
|
53
49
|
fieldNames.forEach(function (key) {
|
|
54
|
-
var valueAnnotation = fields[key]
|
|
55
|
-
var kser = serializeValue(key)
|
|
56
|
-
var valPrefix = prefix + INDENT + ' '.repeat(kser.length + 2)
|
|
50
|
+
var valueAnnotation = fields[key]
|
|
51
|
+
var kser = serializeValue(key)
|
|
52
|
+
var valPrefix = '' + prefix + INDENT + ' '.repeat(kser.length + 2)
|
|
57
53
|
|
|
58
|
-
var _serializeAnnotation2 = serializeAnnotation(valueAnnotation, prefix + INDENT),
|
|
59
|
-
|
|
60
|
-
|
|
54
|
+
var _serializeAnnotation2 = serializeAnnotation(valueAnnotation, '' + prefix + INDENT),
|
|
55
|
+
vser = _serializeAnnotation2[0],
|
|
56
|
+
vann = _serializeAnnotation2[1]
|
|
61
57
|
|
|
62
|
-
result.push(prefix + INDENT + kser + ': ' + vser + ',')
|
|
58
|
+
result.push('' + prefix + INDENT + kser + ': ' + vser + ',')
|
|
63
59
|
|
|
64
60
|
if (vann !== undefined) {
|
|
65
|
-
result.push(indent(vann, valPrefix))
|
|
61
|
+
result.push(indent(vann, valPrefix))
|
|
66
62
|
}
|
|
67
|
-
})
|
|
68
|
-
return ['{'].concat(result, [prefix + '}']).join('\n')
|
|
63
|
+
})
|
|
64
|
+
return ['{'].concat(result, [prefix + '}']).join('\n')
|
|
69
65
|
}
|
|
70
66
|
|
|
71
67
|
export function serializeValue(value) {
|
|
72
|
-
// istanbul ignore else
|
|
73
68
|
if (typeof value === 'string') {
|
|
74
|
-
return serializeString(value)
|
|
69
|
+
return serializeString(value)
|
|
75
70
|
} else if (typeof value === 'number' || typeof value === 'boolean') {
|
|
76
|
-
return value.toString()
|
|
71
|
+
return value.toString()
|
|
77
72
|
} else if (value === null) {
|
|
78
|
-
return 'null'
|
|
73
|
+
return 'null'
|
|
79
74
|
} else if (value === undefined) {
|
|
80
|
-
return 'undefined'
|
|
75
|
+
return 'undefined'
|
|
81
76
|
} else {
|
|
82
|
-
var valueAsDate = asDate(value)
|
|
77
|
+
var valueAsDate = asDate(value)
|
|
83
78
|
|
|
84
79
|
if (valueAsDate !== null) {
|
|
85
|
-
return
|
|
80
|
+
return 'new Date(' + JSON.stringify(valueAsDate.toISOString()) + ')'
|
|
86
81
|
} else if (value instanceof Date) {
|
|
87
|
-
|
|
88
|
-
// If this case occurs (and it didn't pass the prior isDate())
|
|
89
|
-
// check, then this must be the case where it's an invalid date.
|
|
90
|
-
return '(Invalid Date)';
|
|
82
|
+
return '(Invalid Date)'
|
|
91
83
|
} else {
|
|
92
|
-
return '(unserializable)'
|
|
84
|
+
return '(unserializable)'
|
|
93
85
|
}
|
|
94
86
|
}
|
|
95
87
|
}
|
|
96
88
|
export function serializeAnnotation(ann, prefix) {
|
|
97
89
|
if (prefix === void 0) {
|
|
98
|
-
prefix = ''
|
|
90
|
+
prefix = ''
|
|
99
91
|
}
|
|
100
|
-
|
|
101
|
-
// The serialized data (the input object echoed back)
|
|
102
|
-
var serialized;
|
|
92
|
+
var serialized
|
|
103
93
|
|
|
104
94
|
if (ann.type === 'array') {
|
|
105
|
-
serialized = serializeArray(ann, prefix)
|
|
95
|
+
serialized = serializeArray(ann, prefix)
|
|
106
96
|
} else if (ann.type === 'object') {
|
|
107
|
-
serialized = serializeObject(ann, prefix)
|
|
97
|
+
serialized = serializeObject(ann, prefix)
|
|
108
98
|
} else if (ann.type === 'function') {
|
|
109
|
-
serialized = '<function>'
|
|
99
|
+
serialized = '<function>'
|
|
110
100
|
} else if (ann.type === 'circular-ref') {
|
|
111
|
-
serialized = '<circular ref>'
|
|
101
|
+
serialized = '<circular ref>'
|
|
112
102
|
} else if (ann.type === 'unknown') {
|
|
113
|
-
serialized = '???'
|
|
103
|
+
serialized = '???'
|
|
114
104
|
} else {
|
|
115
|
-
serialized = serializeValue(ann.value)
|
|
105
|
+
serialized = serializeValue(ann.value)
|
|
116
106
|
}
|
|
117
107
|
|
|
118
|
-
var text = ann.text
|
|
108
|
+
var text = ann.text
|
|
119
109
|
|
|
120
110
|
if (text !== undefined) {
|
|
121
|
-
var sep = '^'.repeat(isMultiline(serialized) ? 1 : serialized.length)
|
|
122
|
-
return [serialized, [sep, text].join(isMultiline(text) ? '\n' : ' ')]
|
|
111
|
+
var sep = '^'.repeat(isMultiline(serialized) ? 1 : serialized.length)
|
|
112
|
+
return [serialized, [sep, text].join(isMultiline(text) ? '\n' : ' ')]
|
|
123
113
|
} else {
|
|
124
|
-
return [serialized, undefined]
|
|
114
|
+
return [serialized, undefined]
|
|
125
115
|
}
|
|
126
116
|
}
|
|
127
117
|
export function formatInline(ann) {
|
|
128
118
|
var _serializeAnnotation3 = serializeAnnotation(ann),
|
|
129
|
-
|
|
130
|
-
|
|
119
|
+
serialized = _serializeAnnotation3[0],
|
|
120
|
+
annotation = _serializeAnnotation3[1]
|
|
131
121
|
|
|
132
122
|
if (annotation !== undefined) {
|
|
133
|
-
return serialized + '\n' + annotation
|
|
123
|
+
return serialized + '\n' + annotation
|
|
134
124
|
} else {
|
|
135
|
-
return serialized
|
|
125
|
+
return serialized
|
|
136
126
|
}
|
|
137
127
|
}
|
|
138
128
|
export function formatShort(ann) {
|
|
139
|
-
return _summarize(ann, []).join('\n')
|
|
140
|
-
}
|
|
129
|
+
return _summarize(ann, []).join('\n')
|
|
130
|
+
}
|
package/index.d.ts
CHANGED
|
@@ -1,43 +1,40 @@
|
|
|
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, map, predicate } from './core/composition';
|
|
1
|
+
export { DecodeResult, Decoder, DecoderType, Scalar, define } from './Decoder';
|
|
2
|
+
export { JSONValue, JSONObject, JSONArray } from './lib/json';
|
|
16
3
|
|
|
17
|
-
export { array, nonEmptyArray, poja } from './core/array';
|
|
18
|
-
export { boolean, numericBoolean, truthy } from './core/boolean';
|
|
19
|
-
export { constant, hardcoded, mixed, null_, undefined_, unknown } from './core/constants';
|
|
20
|
-
export { date, iso8601 } from './core/date';
|
|
21
|
-
export { describe } from './core/describe';
|
|
22
|
-
export { disjointUnion } from './core/dispatch';
|
|
23
4
|
export {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
export {
|
|
36
|
-
export {
|
|
37
|
-
export {
|
|
38
|
-
export { mapping,
|
|
39
|
-
export {
|
|
40
|
-
export {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
CHANGED
|
@@ -1,121 +1,89 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict'
|
|
2
2
|
|
|
3
|
-
exports.__esModule = true
|
|
4
|
-
exports.
|
|
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
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.
|
|
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
|
|
15
22
|
|
|
16
|
-
var
|
|
23
|
+
var _arrays = require('./lib/arrays')
|
|
17
24
|
|
|
18
|
-
exports.array =
|
|
19
|
-
exports.nonEmptyArray =
|
|
20
|
-
exports.poja =
|
|
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
|
|
21
30
|
|
|
22
|
-
var
|
|
31
|
+
var _booleans = require('./lib/booleans')
|
|
23
32
|
|
|
24
|
-
exports[
|
|
25
|
-
exports.numericBoolean =
|
|
26
|
-
exports.truthy =
|
|
33
|
+
exports['boolean'] = _booleans['boolean']
|
|
34
|
+
exports.numericBoolean = _booleans.numericBoolean
|
|
35
|
+
exports.truthy = _booleans.truthy
|
|
27
36
|
|
|
28
|
-
var
|
|
37
|
+
var _dates = require('./lib/dates')
|
|
29
38
|
|
|
30
|
-
exports.
|
|
31
|
-
exports.
|
|
32
|
-
exports.mixed = _constants.mixed;
|
|
33
|
-
exports.null_ = _constants.null_;
|
|
34
|
-
exports.undefined_ = _constants.undefined_;
|
|
35
|
-
exports.unknown = _constants.unknown;
|
|
39
|
+
exports.date = _dates.date
|
|
40
|
+
exports.iso8601 = _dates.iso8601
|
|
36
41
|
|
|
37
|
-
var
|
|
42
|
+
var _objects = require('./lib/objects')
|
|
38
43
|
|
|
39
|
-
exports.
|
|
40
|
-
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
|
|
41
50
|
|
|
42
|
-
var
|
|
51
|
+
var _unions = require('./lib/unions')
|
|
43
52
|
|
|
44
|
-
exports.
|
|
53
|
+
exports.either = _unions.either
|
|
54
|
+
exports.oneOf = _unions.oneOf
|
|
55
|
+
exports.taggedUnion = _unions.taggedUnion
|
|
45
56
|
|
|
46
|
-
var
|
|
57
|
+
var _strings = require('./lib/strings')
|
|
47
58
|
|
|
48
|
-
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
|
|
49
68
|
|
|
50
|
-
var
|
|
69
|
+
var _utilities = require('./lib/utilities')
|
|
51
70
|
|
|
52
|
-
exports.
|
|
53
|
-
exports.
|
|
54
|
-
exports.
|
|
55
|
-
exports.
|
|
56
|
-
exports.
|
|
57
|
-
exports.either7 = _either.either7;
|
|
58
|
-
exports.either8 = _either.either8;
|
|
59
|
-
exports.either9 = _either.either9;
|
|
60
|
-
exports.oneOf = _either.oneOf;
|
|
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.
|
|
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
|
|
65
84
|
|
|
66
|
-
var
|
|
85
|
+
var _json = require('./lib/json')
|
|
67
86
|
|
|
68
|
-
exports.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
exports.json = _json.json;
|
|
73
|
-
exports.jsonObject = _json.jsonObject;
|
|
74
|
-
exports.jsonArray = _json.jsonArray;
|
|
75
|
-
|
|
76
|
-
var _lazy = require("./core/lazy");
|
|
77
|
-
|
|
78
|
-
exports.lazy = _lazy.lazy;
|
|
79
|
-
|
|
80
|
-
var _mapping = require("./core/mapping");
|
|
81
|
-
|
|
82
|
-
exports.mapping = _mapping.mapping;
|
|
83
|
-
exports.dict = _mapping.dict;
|
|
84
|
-
|
|
85
|
-
var _number = require("./core/number");
|
|
86
|
-
|
|
87
|
-
exports.integer = _number.integer;
|
|
88
|
-
exports.number = _number.number;
|
|
89
|
-
exports.positiveInteger = _number.positiveInteger;
|
|
90
|
-
exports.positiveNumber = _number.positiveNumber;
|
|
91
|
-
|
|
92
|
-
var _object = require("./core/object");
|
|
93
|
-
|
|
94
|
-
exports.exact = _object.exact;
|
|
95
|
-
exports.inexact = _object.inexact;
|
|
96
|
-
exports.object = _object.object;
|
|
97
|
-
exports.pojo = _object.pojo;
|
|
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 _string = require("./core/string");
|
|
106
|
-
|
|
107
|
-
exports.email = _string.email;
|
|
108
|
-
exports.httpsUrl = _string.httpsUrl;
|
|
109
|
-
exports.nonEmptyString = _string.nonEmptyString;
|
|
110
|
-
exports.regex = _string.regex;
|
|
111
|
-
exports.string = _string.string;
|
|
112
|
-
exports.url = _string.url;
|
|
113
|
-
|
|
114
|
-
var _tuple = require("./core/tuple");
|
|
115
|
-
|
|
116
|
-
exports.tuple1 = _tuple.tuple1;
|
|
117
|
-
exports.tuple2 = _tuple.tuple2;
|
|
118
|
-
exports.tuple3 = _tuple.tuple3;
|
|
119
|
-
exports.tuple4 = _tuple.tuple4;
|
|
120
|
-
exports.tuple5 = _tuple.tuple5;
|
|
121
|
-
exports.tuple6 = _tuple.tuple6;
|
|
87
|
+
exports.json = _json.json
|
|
88
|
+
exports.jsonObject = _json.jsonObject
|
|
89
|
+
exports.jsonArray = _json.jsonArray
|
package/index.js.flow
CHANGED
|
@@ -1,63 +1,44 @@
|
|
|
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 { compose, map, predicate } from './core/composition';
|
|
36
|
-
|
|
37
|
-
export { array, nonEmptyArray, poja } from './core/array';
|
|
38
|
-
export { boolean, numericBoolean, truthy } from './core/boolean';
|
|
39
|
-
export { constant, hardcoded, mixed, null_, undefined_, unknown } from './core/constants';
|
|
40
|
-
export { date, iso8601 } from './core/date';
|
|
41
|
-
export { describe } from './core/describe';
|
|
42
|
-
export { disjointUnion } from './core/dispatch';
|
|
43
8
|
export {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
export {
|
|
56
|
-
export {
|
|
57
|
-
export {
|
|
58
|
-
export { mapping,
|
|
59
|
-
export {
|
|
60
|
-
export {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
CHANGED
|
@@ -1,37 +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, map, predicate } from './core/composition.mjs';
|
|
21
|
-
export { array, nonEmptyArray, poja } 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 { disjointUnion } from './core/dispatch.mjs';
|
|
27
|
-
export { either, either3, either4, either5, either6, either7, either8, either9, oneOf } from './core/either.mjs';
|
|
28
|
-
export { fail } from './core/fail.mjs';
|
|
29
|
-
export { instanceOf } from './core/instanceOf.mjs';
|
|
30
|
-
export { json, jsonObject, jsonArray } from './core/json.mjs';
|
|
31
|
-
export { lazy } from './core/lazy.mjs';
|
|
32
|
-
export { mapping, dict } from './core/mapping.mjs';
|
|
33
|
-
export { integer, number, positiveInteger, positiveNumber } from './core/number.mjs';
|
|
34
|
-
export { exact, inexact, object, pojo } from './core/object.mjs';
|
|
35
|
-
export { maybe, nullable, optional } from './core/optional.mjs';
|
|
36
|
-
export { email, httpsUrl, nonEmptyString, regex, string, url } from './core/string.mjs';
|
|
37
|
-
export { tuple1, tuple2, tuple3, tuple4, tuple5, tuple6 } 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
|