decoders 2.0.5 → 2.2.0-test
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/README.md +12 -12
- package/dist/annotate-0PUmWHxH.d.cts +33 -0
- package/dist/annotate-0PUmWHxH.d.ts +33 -0
- package/dist/chunk-2C72BP5L.cjs +179 -0
- package/dist/chunk-2C72BP5L.cjs.map +1 -0
- package/dist/chunk-BPSZE2VX.js +13 -0
- package/dist/chunk-BPSZE2VX.js.map +1 -0
- package/dist/chunk-Q3YXBCTD.cjs +13 -0
- package/dist/chunk-Q3YXBCTD.cjs.map +1 -0
- package/dist/chunk-RUMDX66L.js +179 -0
- package/dist/chunk-RUMDX66L.js.map +1 -0
- package/dist/format.cjs +13 -0
- package/dist/format.cjs.map +1 -0
- package/dist/format.d.cts +9 -0
- package/dist/format.d.ts +9 -0
- package/dist/format.js +13 -0
- package/dist/format.js.map +1 -0
- package/dist/index.cjs +659 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +454 -0
- package/dist/index.d.ts +454 -0
- package/dist/index.js +659 -0
- package/dist/index.js.map +1 -0
- package/dist/result.cjs +9 -0
- package/dist/result.cjs.map +1 -0
- package/dist/result.d.cts +26 -0
- package/dist/result.d.ts +26 -0
- package/dist/result.js +9 -0
- package/dist/result.js.map +1 -0
- package/format.cjs +13 -0
- package/package.json +163 -100
- package/result.cjs +9 -0
- package/CHANGELOG.md +0 -665
- package/Decoder.d.ts +0 -94
- package/Decoder.js +0 -105
- package/Decoder.js.flow +0 -286
- package/Decoder.mjs +0 -101
- package/NotSupportedTSVersion.d.ts +0 -1
- package/_utils.d.ts +0 -9
- package/_utils.js +0 -80
- package/_utils.js.flow +0 -107
- package/_utils.mjs +0 -70
- package/annotate.d.ts +0 -62
- package/annotate.js +0 -145
- package/annotate.js.flow +0 -218
- package/annotate.mjs +0 -131
- package/format.d.ts +0 -6
- package/format.js +0 -117
- package/format.js.flow +0 -128
- package/format.mjs +0 -110
- package/index.d.ts +0 -40
- package/index.js +0 -67
- package/index.js.flow +0 -44
- package/index.mjs +0 -11
- package/lib/_helpers.d.ts +0 -79
- package/lib/arrays.d.ts +0 -59
- package/lib/arrays.js +0 -85
- package/lib/arrays.js.flow +0 -138
- package/lib/arrays.mjs +0 -75
- package/lib/basics.d.ts +0 -93
- package/lib/basics.js +0 -74
- package/lib/basics.js.flow +0 -124
- package/lib/basics.mjs +0 -60
- package/lib/booleans.d.ts +0 -16
- package/lib/booleans.js +0 -21
- package/lib/booleans.js.flow +0 -22
- package/lib/booleans.mjs +0 -15
- package/lib/dates.d.ts +0 -15
- package/lib/dates.js +0 -23
- package/lib/dates.js.flow +0 -40
- package/lib/dates.mjs +0 -17
- package/lib/json.d.ts +0 -35
- package/lib/json.js +0 -25
- package/lib/json.js.flow +0 -50
- package/lib/json.mjs +0 -18
- package/lib/numbers.d.ts +0 -31
- package/lib/numbers.js +0 -34
- package/lib/numbers.js.flow +0 -46
- package/lib/numbers.mjs +0 -25
- package/lib/objects.d.ts +0 -76
- package/lib/objects.js +0 -138
- package/lib/objects.js.flow +0 -238
- package/lib/objects.mjs +0 -128
- package/lib/strings.d.ts +0 -56
- package/lib/strings.js +0 -54
- package/lib/strings.js.flow +0 -90
- package/lib/strings.mjs +0 -40
- package/lib/unions.d.ts +0 -55
- package/lib/unions.js +0 -82
- package/lib/unions.js.flow +0 -155
- package/lib/unions.mjs +0 -75
- package/lib/utilities.d.ts +0 -40
- package/lib/utilities.js +0 -44
- package/lib/utilities.js.flow +0 -65
- package/lib/utilities.mjs +0 -35
- package/result.d.ts +0 -16
- package/result.js +0 -21
- package/result.js.flow +0 -26
- package/result.mjs +0 -15
package/annotate.mjs
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
function _extends() {
|
|
2
|
-
_extends = Object.assign
|
|
3
|
-
? Object.assign.bind()
|
|
4
|
-
: function (target) {
|
|
5
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
6
|
-
var source = arguments[i]
|
|
7
|
-
for (var key in source) {
|
|
8
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
9
|
-
target[key] = source[key]
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return target
|
|
14
|
-
}
|
|
15
|
-
return _extends.apply(this, arguments)
|
|
16
|
-
}
|
|
17
|
-
var _register = new WeakSet()
|
|
18
|
-
function brand(ann) {
|
|
19
|
-
_register.add(ann)
|
|
20
|
-
return ann
|
|
21
|
-
}
|
|
22
|
-
export function object(fields, text) {
|
|
23
|
-
return brand({
|
|
24
|
-
type: 'object',
|
|
25
|
-
fields: fields,
|
|
26
|
-
text: text,
|
|
27
|
-
})
|
|
28
|
-
}
|
|
29
|
-
export function array(items, text) {
|
|
30
|
-
return brand({
|
|
31
|
-
type: 'array',
|
|
32
|
-
items: items,
|
|
33
|
-
text: text,
|
|
34
|
-
})
|
|
35
|
-
}
|
|
36
|
-
export function func(text) {
|
|
37
|
-
return brand({
|
|
38
|
-
type: 'function',
|
|
39
|
-
text: text,
|
|
40
|
-
})
|
|
41
|
-
}
|
|
42
|
-
export function unknown(value, text) {
|
|
43
|
-
return brand({
|
|
44
|
-
type: 'unknown',
|
|
45
|
-
value: value,
|
|
46
|
-
text: text,
|
|
47
|
-
})
|
|
48
|
-
}
|
|
49
|
-
export function scalar(value, text) {
|
|
50
|
-
return brand({
|
|
51
|
-
type: 'scalar',
|
|
52
|
-
value: value,
|
|
53
|
-
text: text,
|
|
54
|
-
})
|
|
55
|
-
}
|
|
56
|
-
export function circularRef(text) {
|
|
57
|
-
return brand({
|
|
58
|
-
type: 'circular-ref',
|
|
59
|
-
text: text,
|
|
60
|
-
})
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function updateText(annotation, text) {
|
|
64
|
-
if (text !== undefined) {
|
|
65
|
-
return brand(
|
|
66
|
-
_extends({}, annotation, {
|
|
67
|
-
text: text,
|
|
68
|
-
})
|
|
69
|
-
)
|
|
70
|
-
} else {
|
|
71
|
-
return annotation
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function merge(objAnnotation, fields) {
|
|
76
|
-
var newFields = _extends({}, objAnnotation.fields, fields)
|
|
77
|
-
return object(newFields, objAnnotation.text)
|
|
78
|
-
}
|
|
79
|
-
export function asAnnotation(thing) {
|
|
80
|
-
return typeof thing === 'object' && thing !== null && _register.has(thing) ? thing : undefined
|
|
81
|
-
}
|
|
82
|
-
function annotateArray(value, text, seen) {
|
|
83
|
-
seen.add(value)
|
|
84
|
-
var items = value.map(function (v) {
|
|
85
|
-
return annotate(v, undefined, seen)
|
|
86
|
-
})
|
|
87
|
-
return array(items, text)
|
|
88
|
-
}
|
|
89
|
-
function annotateObject(obj, text, seen) {
|
|
90
|
-
seen.add(obj)
|
|
91
|
-
var fields = {}
|
|
92
|
-
Object.keys(obj).forEach(function (key) {
|
|
93
|
-
var value = obj[key]
|
|
94
|
-
fields[key] = annotate(value, undefined, seen)
|
|
95
|
-
})
|
|
96
|
-
return object(fields, text)
|
|
97
|
-
}
|
|
98
|
-
function annotate(value, text, seen) {
|
|
99
|
-
if (value === null || value === undefined || typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean' || typeof value === 'symbol' || typeof value.getMonth === 'function') {
|
|
100
|
-
return scalar(value, text)
|
|
101
|
-
}
|
|
102
|
-
var ann = asAnnotation(value)
|
|
103
|
-
if (ann) {
|
|
104
|
-
return updateText(ann, text)
|
|
105
|
-
}
|
|
106
|
-
if (Array.isArray(value)) {
|
|
107
|
-
if (seen.has(value)) {
|
|
108
|
-
return circularRef(text)
|
|
109
|
-
} else {
|
|
110
|
-
return annotateArray(value, text, seen)
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
if (typeof value === 'object') {
|
|
114
|
-
if (seen.has(value)) {
|
|
115
|
-
return circularRef(text)
|
|
116
|
-
} else {
|
|
117
|
-
return annotateObject(value, text, seen)
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
if (typeof value === 'function') {
|
|
121
|
-
return func(text)
|
|
122
|
-
}
|
|
123
|
-
return unknown(value, text)
|
|
124
|
-
}
|
|
125
|
-
function public_annotate(value, text) {
|
|
126
|
-
return annotate(value, text, new WeakSet())
|
|
127
|
-
}
|
|
128
|
-
function public_annotateObject(obj, text) {
|
|
129
|
-
return annotateObject(obj, text, new WeakSet())
|
|
130
|
-
}
|
|
131
|
-
export { public_annotate as annotate, public_annotateObject as annotateObject, annotate as __private_annotate }
|
package/format.d.ts
DELETED
package/format.js
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
exports.__esModule = true
|
|
4
|
-
exports.formatInline = formatInline
|
|
5
|
-
exports.formatShort = formatShort
|
|
6
|
-
exports.serializeAnnotation = serializeAnnotation
|
|
7
|
-
exports.serializeValue = serializeValue
|
|
8
|
-
var _utils = require('./_utils')
|
|
9
|
-
function serializeString(s, width) {
|
|
10
|
-
if (width === void 0) {
|
|
11
|
-
width = 80
|
|
12
|
-
}
|
|
13
|
-
var ser = JSON.stringify(s)
|
|
14
|
-
if (ser.length <= width) {
|
|
15
|
-
return ser
|
|
16
|
-
}
|
|
17
|
-
var truncated = s.substring(0, width - 15) + '...'
|
|
18
|
-
ser = JSON.stringify(truncated) + ' [truncated]'
|
|
19
|
-
return ser
|
|
20
|
-
}
|
|
21
|
-
function serializeArray(annotation, prefix) {
|
|
22
|
-
var items = annotation.items
|
|
23
|
-
if (items.length === 0) {
|
|
24
|
-
return '[]'
|
|
25
|
-
}
|
|
26
|
-
var result = []
|
|
27
|
-
items.forEach(function (item) {
|
|
28
|
-
var _serializeAnnotation = serializeAnnotation(item, '' + prefix + _utils.INDENT),
|
|
29
|
-
ser = _serializeAnnotation[0],
|
|
30
|
-
ann = _serializeAnnotation[1]
|
|
31
|
-
result.push('' + prefix + _utils.INDENT + ser + ',')
|
|
32
|
-
if (ann !== undefined) {
|
|
33
|
-
result.push((0, _utils.indent)(ann, '' + prefix + _utils.INDENT))
|
|
34
|
-
}
|
|
35
|
-
})
|
|
36
|
-
return ['['].concat(result, [prefix + ']']).join('\n')
|
|
37
|
-
}
|
|
38
|
-
function serializeObject(annotation, prefix) {
|
|
39
|
-
var fields = annotation.fields
|
|
40
|
-
var fieldNames = Object.keys(fields)
|
|
41
|
-
if (fieldNames.length === 0) {
|
|
42
|
-
return '{}'
|
|
43
|
-
}
|
|
44
|
-
var result = []
|
|
45
|
-
fieldNames.forEach(function (key) {
|
|
46
|
-
var valueAnnotation = fields[key]
|
|
47
|
-
var kser = serializeValue(key)
|
|
48
|
-
var valPrefix = '' + prefix + _utils.INDENT + ' '.repeat(kser.length + 2)
|
|
49
|
-
var _serializeAnnotation2 = serializeAnnotation(valueAnnotation, '' + prefix + _utils.INDENT),
|
|
50
|
-
vser = _serializeAnnotation2[0],
|
|
51
|
-
vann = _serializeAnnotation2[1]
|
|
52
|
-
result.push('' + prefix + _utils.INDENT + kser + ': ' + vser + ',')
|
|
53
|
-
if (vann !== undefined) {
|
|
54
|
-
result.push((0, _utils.indent)(vann, valPrefix))
|
|
55
|
-
}
|
|
56
|
-
})
|
|
57
|
-
return ['{'].concat(result, [prefix + '}']).join('\n')
|
|
58
|
-
}
|
|
59
|
-
function serializeValue(value) {
|
|
60
|
-
if (typeof value === 'string') {
|
|
61
|
-
return serializeString(value)
|
|
62
|
-
} else if (typeof value === 'number' || typeof value === 'boolean') {
|
|
63
|
-
return value.toString()
|
|
64
|
-
} else if (value === null) {
|
|
65
|
-
return 'null'
|
|
66
|
-
} else if (value === undefined) {
|
|
67
|
-
return 'undefined'
|
|
68
|
-
} else {
|
|
69
|
-
var valueAsDate = (0, _utils.asDate)(value)
|
|
70
|
-
if (valueAsDate !== null) {
|
|
71
|
-
return 'new Date(' + JSON.stringify(valueAsDate.toISOString()) + ')'
|
|
72
|
-
} else if (value instanceof Date) {
|
|
73
|
-
return '(Invalid Date)'
|
|
74
|
-
} else {
|
|
75
|
-
return '(unserializable)'
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
function serializeAnnotation(ann, prefix) {
|
|
80
|
-
if (prefix === void 0) {
|
|
81
|
-
prefix = ''
|
|
82
|
-
}
|
|
83
|
-
var serialized
|
|
84
|
-
if (ann.type === 'array') {
|
|
85
|
-
serialized = serializeArray(ann, prefix)
|
|
86
|
-
} else if (ann.type === 'object') {
|
|
87
|
-
serialized = serializeObject(ann, prefix)
|
|
88
|
-
} else if (ann.type === 'function') {
|
|
89
|
-
serialized = '<function>'
|
|
90
|
-
} else if (ann.type === 'circular-ref') {
|
|
91
|
-
serialized = '<circular ref>'
|
|
92
|
-
} else if (ann.type === 'unknown') {
|
|
93
|
-
serialized = '???'
|
|
94
|
-
} else {
|
|
95
|
-
serialized = serializeValue(ann.value)
|
|
96
|
-
}
|
|
97
|
-
var text = ann.text
|
|
98
|
-
if (text !== undefined) {
|
|
99
|
-
var sep = '^'.repeat((0, _utils.isMultiline)(serialized) ? 1 : serialized.length)
|
|
100
|
-
return [serialized, [sep, text].join((0, _utils.isMultiline)(text) ? '\n' : ' ')]
|
|
101
|
-
} else {
|
|
102
|
-
return [serialized, undefined]
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
function formatInline(ann) {
|
|
106
|
-
var _serializeAnnotation3 = serializeAnnotation(ann),
|
|
107
|
-
serialized = _serializeAnnotation3[0],
|
|
108
|
-
annotation = _serializeAnnotation3[1]
|
|
109
|
-
if (annotation !== undefined) {
|
|
110
|
-
return serialized + '\n' + annotation
|
|
111
|
-
} else {
|
|
112
|
-
return serialized
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
function formatShort(ann) {
|
|
116
|
-
return (0, _utils.summarize)(ann, []).join('\n')
|
|
117
|
-
}
|
package/format.js.flow
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
// @flow strict
|
|
2
|
-
|
|
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;
|
|
7
|
-
|
|
8
|
-
function serializeString(s: string, width: number = 80): string {
|
|
9
|
-
// Full string
|
|
10
|
-
// Abbreviated to $maxlen i.e. "Vincent Driess..." [truncated]
|
|
11
|
-
let ser = JSON.stringify(s);
|
|
12
|
-
if (ser.length <= width) {
|
|
13
|
-
return ser;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// Cut off a bit
|
|
17
|
-
const truncated = `${s.substring(0, width - 15)}...`;
|
|
18
|
-
ser = `${JSON.stringify(truncated)} [truncated]`;
|
|
19
|
-
return ser;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function serializeArray(annotation: ArrayAnnotation, prefix: string): string {
|
|
23
|
-
const { items } = annotation;
|
|
24
|
-
if (items.length === 0) {
|
|
25
|
-
return '[]';
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const result = [];
|
|
29
|
-
items.forEach((item) => {
|
|
30
|
-
const [ser, ann] = serializeAnnotation(item, `${prefix}${INDENT}`);
|
|
31
|
-
result.push(`${prefix}${INDENT}${ser}${','}`);
|
|
32
|
-
if (ann !== undefined) {
|
|
33
|
-
result.push(indent(ann, `${prefix}${INDENT}`));
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
return ['[', ...result, `${prefix}]`].join('\n');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function serializeObject(annotation: ObjectAnnotation, prefix: string): string {
|
|
40
|
-
const { fields } = annotation;
|
|
41
|
-
|
|
42
|
-
const fieldNames = Object.keys(fields);
|
|
43
|
-
if (fieldNames.length === 0) {
|
|
44
|
-
return '{}';
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const result = [];
|
|
48
|
-
fieldNames.forEach((key) => {
|
|
49
|
-
const valueAnnotation = fields[key];
|
|
50
|
-
const kser = serializeValue(key);
|
|
51
|
-
|
|
52
|
-
const valPrefix = `${prefix}${INDENT}${' '.repeat(kser.length + 2)}`;
|
|
53
|
-
const [vser, vann] = serializeAnnotation(valueAnnotation, `${prefix}${INDENT}`);
|
|
54
|
-
|
|
55
|
-
result.push(`${prefix}${INDENT}${kser}: ${vser},`);
|
|
56
|
-
if (vann !== undefined) {
|
|
57
|
-
result.push(indent(vann, valPrefix));
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
return ['{', ...result, `${prefix}}`].join('\n');
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function serializeValue(value: mixed): string {
|
|
64
|
-
// istanbul ignore else
|
|
65
|
-
if (typeof value === 'string') {
|
|
66
|
-
return serializeString(value);
|
|
67
|
-
} else if (typeof value === 'number' || typeof value === 'boolean') {
|
|
68
|
-
return value.toString();
|
|
69
|
-
} else if (value === null) {
|
|
70
|
-
return 'null';
|
|
71
|
-
} else if (value === undefined) {
|
|
72
|
-
return 'undefined';
|
|
73
|
-
} else {
|
|
74
|
-
const valueAsDate = asDate(value);
|
|
75
|
-
if (valueAsDate !== null) {
|
|
76
|
-
return `new Date(${JSON.stringify(valueAsDate.toISOString())})`;
|
|
77
|
-
} else if (value instanceof Date) {
|
|
78
|
-
// NOTE: Using `instanceof Date` is unreliable way of checking dates.
|
|
79
|
-
// If this case occurs (and it didn't pass the prior asDate())
|
|
80
|
-
// check, then this must be the case where it's an invalid date.
|
|
81
|
-
return '(Invalid Date)';
|
|
82
|
-
} else {
|
|
83
|
-
return '(unserializable)';
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export function serializeAnnotation(
|
|
89
|
-
ann: Annotation,
|
|
90
|
-
prefix: string = '',
|
|
91
|
-
): [string, string | void] {
|
|
92
|
-
// The serialized data (the input object echoed back)
|
|
93
|
-
let serialized;
|
|
94
|
-
if (ann.type === 'array') {
|
|
95
|
-
serialized = serializeArray(ann, prefix);
|
|
96
|
-
} else if (ann.type === 'object') {
|
|
97
|
-
serialized = serializeObject(ann, prefix);
|
|
98
|
-
} else if (ann.type === 'function') {
|
|
99
|
-
serialized = '<function>';
|
|
100
|
-
} else if (ann.type === 'circular-ref') {
|
|
101
|
-
serialized = '<circular ref>';
|
|
102
|
-
} else if (ann.type === 'unknown') {
|
|
103
|
-
serialized = '???';
|
|
104
|
-
} else {
|
|
105
|
-
serialized = serializeValue(ann.value);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const text = ann.text;
|
|
109
|
-
if (text !== undefined) {
|
|
110
|
-
const sep = '^'.repeat(isMultiline(serialized) ? 1 : serialized.length);
|
|
111
|
-
return [serialized, [sep, text].join(isMultiline(text) ? '\n' : ' ')];
|
|
112
|
-
} else {
|
|
113
|
-
return [serialized, undefined];
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export function formatInline(ann: Annotation): string {
|
|
118
|
-
const [serialized, annotation] = serializeAnnotation(ann);
|
|
119
|
-
if (annotation !== undefined) {
|
|
120
|
-
return `${serialized}\n${annotation}`;
|
|
121
|
-
} else {
|
|
122
|
-
return serialized;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export function formatShort(ann: Annotation): string {
|
|
127
|
-
return _summarize(ann, []).join('\n');
|
|
128
|
-
}
|
package/format.mjs
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { summarize as _summarize, asDate, INDENT, indent, isMultiline } from './_utils.mjs'
|
|
2
|
-
function serializeString(s, width) {
|
|
3
|
-
if (width === void 0) {
|
|
4
|
-
width = 80
|
|
5
|
-
}
|
|
6
|
-
var ser = JSON.stringify(s)
|
|
7
|
-
if (ser.length <= width) {
|
|
8
|
-
return ser
|
|
9
|
-
}
|
|
10
|
-
var truncated = s.substring(0, width - 15) + '...'
|
|
11
|
-
ser = JSON.stringify(truncated) + ' [truncated]'
|
|
12
|
-
return ser
|
|
13
|
-
}
|
|
14
|
-
function serializeArray(annotation, prefix) {
|
|
15
|
-
var items = annotation.items
|
|
16
|
-
if (items.length === 0) {
|
|
17
|
-
return '[]'
|
|
18
|
-
}
|
|
19
|
-
var result = []
|
|
20
|
-
items.forEach(function (item) {
|
|
21
|
-
var _serializeAnnotation = serializeAnnotation(item, '' + prefix + INDENT),
|
|
22
|
-
ser = _serializeAnnotation[0],
|
|
23
|
-
ann = _serializeAnnotation[1]
|
|
24
|
-
result.push('' + prefix + INDENT + ser + ',')
|
|
25
|
-
if (ann !== undefined) {
|
|
26
|
-
result.push(indent(ann, '' + prefix + INDENT))
|
|
27
|
-
}
|
|
28
|
-
})
|
|
29
|
-
return ['['].concat(result, [prefix + ']']).join('\n')
|
|
30
|
-
}
|
|
31
|
-
function serializeObject(annotation, prefix) {
|
|
32
|
-
var fields = annotation.fields
|
|
33
|
-
var fieldNames = Object.keys(fields)
|
|
34
|
-
if (fieldNames.length === 0) {
|
|
35
|
-
return '{}'
|
|
36
|
-
}
|
|
37
|
-
var result = []
|
|
38
|
-
fieldNames.forEach(function (key) {
|
|
39
|
-
var valueAnnotation = fields[key]
|
|
40
|
-
var kser = serializeValue(key)
|
|
41
|
-
var valPrefix = '' + prefix + INDENT + ' '.repeat(kser.length + 2)
|
|
42
|
-
var _serializeAnnotation2 = serializeAnnotation(valueAnnotation, '' + prefix + INDENT),
|
|
43
|
-
vser = _serializeAnnotation2[0],
|
|
44
|
-
vann = _serializeAnnotation2[1]
|
|
45
|
-
result.push('' + prefix + INDENT + kser + ': ' + vser + ',')
|
|
46
|
-
if (vann !== undefined) {
|
|
47
|
-
result.push(indent(vann, valPrefix))
|
|
48
|
-
}
|
|
49
|
-
})
|
|
50
|
-
return ['{'].concat(result, [prefix + '}']).join('\n')
|
|
51
|
-
}
|
|
52
|
-
export function serializeValue(value) {
|
|
53
|
-
if (typeof value === 'string') {
|
|
54
|
-
return serializeString(value)
|
|
55
|
-
} else if (typeof value === 'number' || typeof value === 'boolean') {
|
|
56
|
-
return value.toString()
|
|
57
|
-
} else if (value === null) {
|
|
58
|
-
return 'null'
|
|
59
|
-
} else if (value === undefined) {
|
|
60
|
-
return 'undefined'
|
|
61
|
-
} else {
|
|
62
|
-
var valueAsDate = asDate(value)
|
|
63
|
-
if (valueAsDate !== null) {
|
|
64
|
-
return 'new Date(' + JSON.stringify(valueAsDate.toISOString()) + ')'
|
|
65
|
-
} else if (value instanceof Date) {
|
|
66
|
-
return '(Invalid Date)'
|
|
67
|
-
} else {
|
|
68
|
-
return '(unserializable)'
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
export function serializeAnnotation(ann, prefix) {
|
|
73
|
-
if (prefix === void 0) {
|
|
74
|
-
prefix = ''
|
|
75
|
-
}
|
|
76
|
-
var serialized
|
|
77
|
-
if (ann.type === 'array') {
|
|
78
|
-
serialized = serializeArray(ann, prefix)
|
|
79
|
-
} else if (ann.type === 'object') {
|
|
80
|
-
serialized = serializeObject(ann, prefix)
|
|
81
|
-
} else if (ann.type === 'function') {
|
|
82
|
-
serialized = '<function>'
|
|
83
|
-
} else if (ann.type === 'circular-ref') {
|
|
84
|
-
serialized = '<circular ref>'
|
|
85
|
-
} else if (ann.type === 'unknown') {
|
|
86
|
-
serialized = '???'
|
|
87
|
-
} else {
|
|
88
|
-
serialized = serializeValue(ann.value)
|
|
89
|
-
}
|
|
90
|
-
var text = ann.text
|
|
91
|
-
if (text !== undefined) {
|
|
92
|
-
var sep = '^'.repeat(isMultiline(serialized) ? 1 : serialized.length)
|
|
93
|
-
return [serialized, [sep, text].join(isMultiline(text) ? '\n' : ' ')]
|
|
94
|
-
} else {
|
|
95
|
-
return [serialized, undefined]
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
export function formatInline(ann) {
|
|
99
|
-
var _serializeAnnotation3 = serializeAnnotation(ann),
|
|
100
|
-
serialized = _serializeAnnotation3[0],
|
|
101
|
-
annotation = _serializeAnnotation3[1]
|
|
102
|
-
if (annotation !== undefined) {
|
|
103
|
-
return serialized + '\n' + annotation
|
|
104
|
-
} else {
|
|
105
|
-
return serialized
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
export function formatShort(ann) {
|
|
109
|
-
return _summarize(ann, []).join('\n')
|
|
110
|
-
}
|
package/index.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
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
|
-
var _Decoder = require('./Decoder')
|
|
6
|
-
exports.define = _Decoder.define
|
|
7
|
-
var _basics = require('./lib/basics')
|
|
8
|
-
exports.always = _basics.always
|
|
9
|
-
exports.constant = _basics.constant
|
|
10
|
-
exports.hardcoded = _basics.hardcoded
|
|
11
|
-
exports.maybe = _basics.maybe
|
|
12
|
-
exports.mixed = _basics.mixed
|
|
13
|
-
exports.nullable = _basics.nullable
|
|
14
|
-
exports.null_ = _basics.null_
|
|
15
|
-
exports.optional = _basics.optional
|
|
16
|
-
exports.undefined_ = _basics.undefined_
|
|
17
|
-
exports.unknown = _basics.unknown
|
|
18
|
-
var _arrays = require('./lib/arrays')
|
|
19
|
-
exports.array = _arrays.array
|
|
20
|
-
exports.nonEmptyArray = _arrays.nonEmptyArray
|
|
21
|
-
exports.poja = _arrays.poja
|
|
22
|
-
exports.set = _arrays.set
|
|
23
|
-
exports.tuple = _arrays.tuple
|
|
24
|
-
var _booleans = require('./lib/booleans')
|
|
25
|
-
exports['boolean'] = _booleans['boolean']
|
|
26
|
-
exports.numericBoolean = _booleans.numericBoolean
|
|
27
|
-
exports.truthy = _booleans.truthy
|
|
28
|
-
var _dates = require('./lib/dates')
|
|
29
|
-
exports.date = _dates.date
|
|
30
|
-
exports.iso8601 = _dates.iso8601
|
|
31
|
-
var _objects = require('./lib/objects')
|
|
32
|
-
exports.dict = _objects.dict
|
|
33
|
-
exports.exact = _objects.exact
|
|
34
|
-
exports.inexact = _objects.inexact
|
|
35
|
-
exports.mapping = _objects.mapping
|
|
36
|
-
exports.object = _objects.object
|
|
37
|
-
exports.pojo = _objects.pojo
|
|
38
|
-
var _unions = require('./lib/unions')
|
|
39
|
-
exports.either = _unions.either
|
|
40
|
-
exports.oneOf = _unions.oneOf
|
|
41
|
-
exports.taggedUnion = _unions.taggedUnion
|
|
42
|
-
var _strings = require('./lib/strings')
|
|
43
|
-
exports.email = _strings.email
|
|
44
|
-
exports.httpsUrl = _strings.httpsUrl
|
|
45
|
-
exports.nonEmptyString = _strings.nonEmptyString
|
|
46
|
-
exports.regex = _strings.regex
|
|
47
|
-
exports.string = _strings.string
|
|
48
|
-
exports.url = _strings.url
|
|
49
|
-
exports.uuid = _strings.uuid
|
|
50
|
-
exports.uuidv1 = _strings.uuidv1
|
|
51
|
-
exports.uuidv4 = _strings.uuidv4
|
|
52
|
-
var _utilities = require('./lib/utilities')
|
|
53
|
-
exports.fail = _utilities.fail
|
|
54
|
-
exports.instanceOf = _utilities.instanceOf
|
|
55
|
-
exports.lazy = _utilities.lazy
|
|
56
|
-
exports.never = _utilities.never
|
|
57
|
-
exports.prep = _utilities.prep
|
|
58
|
-
var _numbers = require('./lib/numbers')
|
|
59
|
-
exports.anyNumber = _numbers.anyNumber
|
|
60
|
-
exports.integer = _numbers.integer
|
|
61
|
-
exports.number = _numbers.number
|
|
62
|
-
exports.positiveInteger = _numbers.positiveInteger
|
|
63
|
-
exports.positiveNumber = _numbers.positiveNumber
|
|
64
|
-
var _json = require('./lib/json')
|
|
65
|
-
exports.json = _json.json
|
|
66
|
-
exports.jsonObject = _json.jsonObject
|
|
67
|
-
exports.jsonArray = _json.jsonArray
|
package/index.js.flow
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
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'
|