decoders 2.0.3 → 2.0.4
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 +6 -1
- package/Decoder.js +0 -10
- package/Decoder.mjs +0 -7
- package/_utils.js +0 -11
- package/_utils.mjs +0 -8
- package/annotate.js +0 -23
- package/annotate.mjs +0 -17
- package/format.js +0 -24
- package/format.mjs +0 -20
- package/index.js +0 -22
- package/lib/arrays.js +0 -12
- package/lib/arrays.mjs +0 -9
- package/lib/basics.js +2 -22
- package/lib/basics.mjs +2 -17
- package/lib/booleans.js +0 -4
- package/lib/dates.js +0 -5
- package/lib/dates.mjs +0 -2
- package/lib/json.js +0 -8
- package/lib/numbers.js +0 -1
- package/lib/objects.js +0 -23
- package/lib/objects.mjs +0 -19
- package/lib/strings.js +1 -5
- package/lib/strings.js.flow +1 -1
- package/lib/strings.mjs +1 -1
- package/lib/unions.js +0 -14
- package/lib/unions.mjs +0 -8
- package/lib/utilities.js +0 -4
- package/lib/utilities.mjs +0 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
## v2.0.
|
|
1
|
+
## v2.0.4
|
|
2
|
+
|
|
3
|
+
- Fix a bug in the `url` decoder, which could incorrectly reject URLs with a `/` in the
|
|
4
|
+
query path. Thanks, @gcampax!
|
|
5
|
+
|
|
6
|
+
## v2.0.3
|
|
2
7
|
|
|
3
8
|
- Fix bundling issue where TypeScript types would not get picked up correctly in old
|
|
4
9
|
TypeScript versions. Thanks, @robinchow!
|
package/Decoder.js
CHANGED
|
@@ -2,11 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true
|
|
4
4
|
exports.define = define
|
|
5
|
-
|
|
6
5
|
var _annotate = require('./annotate')
|
|
7
|
-
|
|
8
6
|
var _format = require('./format')
|
|
9
|
-
|
|
10
7
|
var _result = require('./result')
|
|
11
8
|
|
|
12
9
|
function noThrow(fn) {
|
|
@@ -19,13 +16,10 @@ function noThrow(fn) {
|
|
|
19
16
|
}
|
|
20
17
|
}
|
|
21
18
|
}
|
|
22
|
-
|
|
23
19
|
function format(err, formatter) {
|
|
24
20
|
var formatted = formatter(err)
|
|
25
|
-
|
|
26
21
|
if (typeof formatted === 'string') {
|
|
27
22
|
var _err = new Error('\n' + formatted)
|
|
28
|
-
|
|
29
23
|
_err.name = 'Decoding error'
|
|
30
24
|
return _err
|
|
31
25
|
} else {
|
|
@@ -44,9 +38,7 @@ function define(fn) {
|
|
|
44
38
|
if (formatter === void 0) {
|
|
45
39
|
formatter = _format.formatInline
|
|
46
40
|
}
|
|
47
|
-
|
|
48
41
|
var result = decode(blob)
|
|
49
|
-
|
|
50
42
|
if (result.ok) {
|
|
51
43
|
return result.value
|
|
52
44
|
} else {
|
|
@@ -85,7 +77,6 @@ function define(fn) {
|
|
|
85
77
|
function describe(message) {
|
|
86
78
|
return define(function (blob, _, err) {
|
|
87
79
|
var result = decode(blob)
|
|
88
|
-
|
|
89
80
|
if (result.ok) {
|
|
90
81
|
return result
|
|
91
82
|
} else {
|
|
@@ -100,7 +91,6 @@ function define(fn) {
|
|
|
100
91
|
return result.ok ? next([blob, result.value], ok, err) : result
|
|
101
92
|
})
|
|
102
93
|
}
|
|
103
|
-
|
|
104
94
|
return Object.freeze({
|
|
105
95
|
verify: verify,
|
|
106
96
|
value: value,
|
package/Decoder.mjs
CHANGED
|
@@ -12,13 +12,10 @@ function noThrow(fn) {
|
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
|
|
16
15
|
function format(err, formatter) {
|
|
17
16
|
var formatted = formatter(err)
|
|
18
|
-
|
|
19
17
|
if (typeof formatted === 'string') {
|
|
20
18
|
var _err = new Error('\n' + formatted)
|
|
21
|
-
|
|
22
19
|
_err.name = 'Decoding error'
|
|
23
20
|
return _err
|
|
24
21
|
} else {
|
|
@@ -37,9 +34,7 @@ export function define(fn) {
|
|
|
37
34
|
if (formatter === void 0) {
|
|
38
35
|
formatter = formatInline
|
|
39
36
|
}
|
|
40
|
-
|
|
41
37
|
var result = decode(blob)
|
|
42
|
-
|
|
43
38
|
if (result.ok) {
|
|
44
39
|
return result.value
|
|
45
40
|
} else {
|
|
@@ -78,7 +73,6 @@ export function define(fn) {
|
|
|
78
73
|
function describe(message) {
|
|
79
74
|
return define(function (blob, _, err) {
|
|
80
75
|
var result = decode(blob)
|
|
81
|
-
|
|
82
76
|
if (result.ok) {
|
|
83
77
|
return result
|
|
84
78
|
} else {
|
|
@@ -93,7 +87,6 @@ export function define(fn) {
|
|
|
93
87
|
return result.ok ? next([blob, result.value], ok, err) : result
|
|
94
88
|
})
|
|
95
89
|
}
|
|
96
|
-
|
|
97
90
|
return Object.freeze({
|
|
98
91
|
verify: verify,
|
|
99
92
|
value: value,
|
package/_utils.js
CHANGED
|
@@ -10,7 +10,6 @@ exports.summarize = summarize
|
|
|
10
10
|
var INDENT = ' '
|
|
11
11
|
|
|
12
12
|
exports.INDENT = INDENT
|
|
13
|
-
|
|
14
13
|
function subtract(xs, ys) {
|
|
15
14
|
var result = new Set()
|
|
16
15
|
xs.forEach(function (x) {
|
|
@@ -24,16 +23,13 @@ function subtract(xs, ys) {
|
|
|
24
23
|
function asDate(value) {
|
|
25
24
|
return !!value && Object.prototype.toString.call(value) === '[object Date]' && !isNaN(value) ? value : null
|
|
26
25
|
}
|
|
27
|
-
|
|
28
26
|
function isMultiline(s) {
|
|
29
27
|
return s.indexOf('\n') >= 0
|
|
30
28
|
}
|
|
31
|
-
|
|
32
29
|
function indent(s, prefix) {
|
|
33
30
|
if (prefix === void 0) {
|
|
34
31
|
prefix = INDENT
|
|
35
32
|
}
|
|
36
|
-
|
|
37
33
|
if (isMultiline(s)) {
|
|
38
34
|
return s
|
|
39
35
|
.split('\n')
|
|
@@ -50,9 +46,7 @@ function summarize(ann, keypath) {
|
|
|
50
46
|
if (keypath === void 0) {
|
|
51
47
|
keypath = []
|
|
52
48
|
}
|
|
53
|
-
|
|
54
49
|
var result = []
|
|
55
|
-
|
|
56
50
|
if (ann.type === 'array') {
|
|
57
51
|
var items = ann.items
|
|
58
52
|
var index = 0
|
|
@@ -70,15 +64,11 @@ function summarize(ann, keypath) {
|
|
|
70
64
|
})
|
|
71
65
|
})
|
|
72
66
|
}
|
|
73
|
-
|
|
74
67
|
var text = ann.text
|
|
75
|
-
|
|
76
68
|
if (!text) {
|
|
77
69
|
return result
|
|
78
70
|
}
|
|
79
|
-
|
|
80
71
|
var prefix
|
|
81
|
-
|
|
82
72
|
if (keypath.length === 0) {
|
|
83
73
|
prefix = ''
|
|
84
74
|
} else if (keypath.length === 1) {
|
|
@@ -86,6 +76,5 @@ function summarize(ann, keypath) {
|
|
|
86
76
|
} else {
|
|
87
77
|
prefix = 'Value at keypath ' + keypath.map(String).join('.') + ': '
|
|
88
78
|
}
|
|
89
|
-
|
|
90
79
|
return [].concat(result, ['' + prefix + text])
|
|
91
80
|
}
|
package/_utils.mjs
CHANGED
|
@@ -20,7 +20,6 @@ export function indent(s, prefix) {
|
|
|
20
20
|
if (prefix === void 0) {
|
|
21
21
|
prefix = INDENT
|
|
22
22
|
}
|
|
23
|
-
|
|
24
23
|
if (isMultiline(s)) {
|
|
25
24
|
return s
|
|
26
25
|
.split('\n')
|
|
@@ -37,9 +36,7 @@ export function summarize(ann, keypath) {
|
|
|
37
36
|
if (keypath === void 0) {
|
|
38
37
|
keypath = []
|
|
39
38
|
}
|
|
40
|
-
|
|
41
39
|
var result = []
|
|
42
|
-
|
|
43
40
|
if (ann.type === 'array') {
|
|
44
41
|
var items = ann.items
|
|
45
42
|
var index = 0
|
|
@@ -57,15 +54,11 @@ export function summarize(ann, keypath) {
|
|
|
57
54
|
})
|
|
58
55
|
})
|
|
59
56
|
}
|
|
60
|
-
|
|
61
57
|
var text = ann.text
|
|
62
|
-
|
|
63
58
|
if (!text) {
|
|
64
59
|
return result
|
|
65
60
|
}
|
|
66
|
-
|
|
67
61
|
var prefix
|
|
68
|
-
|
|
69
62
|
if (keypath.length === 0) {
|
|
70
63
|
prefix = ''
|
|
71
64
|
} else if (keypath.length === 1) {
|
|
@@ -73,6 +66,5 @@ export function summarize(ann, keypath) {
|
|
|
73
66
|
} else {
|
|
74
67
|
prefix = 'Value at keypath ' + keypath.map(String).join('.') + ': '
|
|
75
68
|
}
|
|
76
|
-
|
|
77
69
|
return [].concat(result, ['' + prefix + text])
|
|
78
70
|
}
|
package/annotate.js
CHANGED
|
@@ -13,7 +13,6 @@ exports.object = object
|
|
|
13
13
|
exports.scalar = scalar
|
|
14
14
|
exports.unknown = unknown
|
|
15
15
|
exports.updateText = updateText
|
|
16
|
-
|
|
17
16
|
function _extends() {
|
|
18
17
|
_extends = Object.assign
|
|
19
18
|
? Object.assign.bind()
|
|
@@ -30,15 +29,11 @@ function _extends() {
|
|
|
30
29
|
}
|
|
31
30
|
return _extends.apply(this, arguments)
|
|
32
31
|
}
|
|
33
|
-
|
|
34
32
|
var _register = new WeakSet()
|
|
35
|
-
|
|
36
33
|
function brand(ann) {
|
|
37
34
|
_register.add(ann)
|
|
38
|
-
|
|
39
35
|
return ann
|
|
40
36
|
}
|
|
41
|
-
|
|
42
37
|
function object(fields, text) {
|
|
43
38
|
return brand({
|
|
44
39
|
type: 'object',
|
|
@@ -46,7 +41,6 @@ function object(fields, text) {
|
|
|
46
41
|
text: text,
|
|
47
42
|
})
|
|
48
43
|
}
|
|
49
|
-
|
|
50
44
|
function array(items, text) {
|
|
51
45
|
return brand({
|
|
52
46
|
type: 'array',
|
|
@@ -54,14 +48,12 @@ function array(items, text) {
|
|
|
54
48
|
text: text,
|
|
55
49
|
})
|
|
56
50
|
}
|
|
57
|
-
|
|
58
51
|
function func(text) {
|
|
59
52
|
return brand({
|
|
60
53
|
type: 'function',
|
|
61
54
|
text: text,
|
|
62
55
|
})
|
|
63
56
|
}
|
|
64
|
-
|
|
65
57
|
function unknown(value, text) {
|
|
66
58
|
return brand({
|
|
67
59
|
type: 'unknown',
|
|
@@ -69,7 +61,6 @@ function unknown(value, text) {
|
|
|
69
61
|
text: text,
|
|
70
62
|
})
|
|
71
63
|
}
|
|
72
|
-
|
|
73
64
|
function scalar(value, text) {
|
|
74
65
|
return brand({
|
|
75
66
|
type: 'scalar',
|
|
@@ -77,7 +68,6 @@ function scalar(value, text) {
|
|
|
77
68
|
text: text,
|
|
78
69
|
})
|
|
79
70
|
}
|
|
80
|
-
|
|
81
71
|
function circularRef(text) {
|
|
82
72
|
return brand({
|
|
83
73
|
type: 'circular-ref',
|
|
@@ -99,14 +89,11 @@ function updateText(annotation, text) {
|
|
|
99
89
|
|
|
100
90
|
function merge(objAnnotation, fields) {
|
|
101
91
|
var newFields = _extends({}, objAnnotation.fields, fields)
|
|
102
|
-
|
|
103
92
|
return object(newFields, objAnnotation.text)
|
|
104
93
|
}
|
|
105
|
-
|
|
106
94
|
function asAnnotation(thing) {
|
|
107
95
|
return typeof thing === 'object' && thing !== null && _register.has(thing) ? thing : undefined
|
|
108
96
|
}
|
|
109
|
-
|
|
110
97
|
function annotateArray(value, text, seen) {
|
|
111
98
|
seen.add(value)
|
|
112
99
|
var items = value.map(function (v) {
|
|
@@ -114,7 +101,6 @@ function annotateArray(value, text, seen) {
|
|
|
114
101
|
})
|
|
115
102
|
return array(items, text)
|
|
116
103
|
}
|
|
117
|
-
|
|
118
104
|
function annotateObject(obj, text, seen) {
|
|
119
105
|
seen.add(obj)
|
|
120
106
|
var fields = {}
|
|
@@ -124,18 +110,14 @@ function annotateObject(obj, text, seen) {
|
|
|
124
110
|
})
|
|
125
111
|
return object(fields, text)
|
|
126
112
|
}
|
|
127
|
-
|
|
128
113
|
function annotate(value, text, seen) {
|
|
129
114
|
if (value === null || value === undefined || typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean' || typeof value === 'symbol' || typeof value.getMonth === 'function') {
|
|
130
115
|
return scalar(value, text)
|
|
131
116
|
}
|
|
132
|
-
|
|
133
117
|
var ann = asAnnotation(value)
|
|
134
|
-
|
|
135
118
|
if (ann) {
|
|
136
119
|
return updateText(ann, text)
|
|
137
120
|
}
|
|
138
|
-
|
|
139
121
|
if (Array.isArray(value)) {
|
|
140
122
|
if (seen.has(value)) {
|
|
141
123
|
return circularRef(text)
|
|
@@ -143,7 +125,6 @@ function annotate(value, text, seen) {
|
|
|
143
125
|
return annotateArray(value, text, seen)
|
|
144
126
|
}
|
|
145
127
|
}
|
|
146
|
-
|
|
147
128
|
if (typeof value === 'object') {
|
|
148
129
|
if (seen.has(value)) {
|
|
149
130
|
return circularRef(text)
|
|
@@ -151,18 +132,14 @@ function annotate(value, text, seen) {
|
|
|
151
132
|
return annotateObject(value, text, seen)
|
|
152
133
|
}
|
|
153
134
|
}
|
|
154
|
-
|
|
155
135
|
if (typeof value === 'function') {
|
|
156
136
|
return func(text)
|
|
157
137
|
}
|
|
158
|
-
|
|
159
138
|
return unknown(value, text)
|
|
160
139
|
}
|
|
161
|
-
|
|
162
140
|
function public_annotate(value, text) {
|
|
163
141
|
return annotate(value, text, new WeakSet())
|
|
164
142
|
}
|
|
165
|
-
|
|
166
143
|
function public_annotateObject(obj, text) {
|
|
167
144
|
return annotateObject(obj, text, new WeakSet())
|
|
168
145
|
}
|
package/annotate.mjs
CHANGED
|
@@ -14,15 +14,11 @@ function _extends() {
|
|
|
14
14
|
}
|
|
15
15
|
return _extends.apply(this, arguments)
|
|
16
16
|
}
|
|
17
|
-
|
|
18
17
|
var _register = new WeakSet()
|
|
19
|
-
|
|
20
18
|
function brand(ann) {
|
|
21
19
|
_register.add(ann)
|
|
22
|
-
|
|
23
20
|
return ann
|
|
24
21
|
}
|
|
25
|
-
|
|
26
22
|
export function object(fields, text) {
|
|
27
23
|
return brand({
|
|
28
24
|
type: 'object',
|
|
@@ -78,13 +74,11 @@ export function updateText(annotation, text) {
|
|
|
78
74
|
|
|
79
75
|
export function merge(objAnnotation, fields) {
|
|
80
76
|
var newFields = _extends({}, objAnnotation.fields, fields)
|
|
81
|
-
|
|
82
77
|
return object(newFields, objAnnotation.text)
|
|
83
78
|
}
|
|
84
79
|
export function asAnnotation(thing) {
|
|
85
80
|
return typeof thing === 'object' && thing !== null && _register.has(thing) ? thing : undefined
|
|
86
81
|
}
|
|
87
|
-
|
|
88
82
|
function annotateArray(value, text, seen) {
|
|
89
83
|
seen.add(value)
|
|
90
84
|
var items = value.map(function (v) {
|
|
@@ -92,7 +86,6 @@ function annotateArray(value, text, seen) {
|
|
|
92
86
|
})
|
|
93
87
|
return array(items, text)
|
|
94
88
|
}
|
|
95
|
-
|
|
96
89
|
function annotateObject(obj, text, seen) {
|
|
97
90
|
seen.add(obj)
|
|
98
91
|
var fields = {}
|
|
@@ -102,18 +95,14 @@ function annotateObject(obj, text, seen) {
|
|
|
102
95
|
})
|
|
103
96
|
return object(fields, text)
|
|
104
97
|
}
|
|
105
|
-
|
|
106
98
|
function annotate(value, text, seen) {
|
|
107
99
|
if (value === null || value === undefined || typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean' || typeof value === 'symbol' || typeof value.getMonth === 'function') {
|
|
108
100
|
return scalar(value, text)
|
|
109
101
|
}
|
|
110
|
-
|
|
111
102
|
var ann = asAnnotation(value)
|
|
112
|
-
|
|
113
103
|
if (ann) {
|
|
114
104
|
return updateText(ann, text)
|
|
115
105
|
}
|
|
116
|
-
|
|
117
106
|
if (Array.isArray(value)) {
|
|
118
107
|
if (seen.has(value)) {
|
|
119
108
|
return circularRef(text)
|
|
@@ -121,7 +110,6 @@ function annotate(value, text, seen) {
|
|
|
121
110
|
return annotateArray(value, text, seen)
|
|
122
111
|
}
|
|
123
112
|
}
|
|
124
|
-
|
|
125
113
|
if (typeof value === 'object') {
|
|
126
114
|
if (seen.has(value)) {
|
|
127
115
|
return circularRef(text)
|
|
@@ -129,20 +117,15 @@ function annotate(value, text, seen) {
|
|
|
129
117
|
return annotateObject(value, text, seen)
|
|
130
118
|
}
|
|
131
119
|
}
|
|
132
|
-
|
|
133
120
|
if (typeof value === 'function') {
|
|
134
121
|
return func(text)
|
|
135
122
|
}
|
|
136
|
-
|
|
137
123
|
return unknown(value, text)
|
|
138
124
|
}
|
|
139
|
-
|
|
140
125
|
function public_annotate(value, text) {
|
|
141
126
|
return annotate(value, text, new WeakSet())
|
|
142
127
|
}
|
|
143
|
-
|
|
144
128
|
function public_annotateObject(obj, text) {
|
|
145
129
|
return annotateObject(obj, text, new WeakSet())
|
|
146
130
|
}
|
|
147
|
-
|
|
148
131
|
export { public_annotate as annotate, public_annotateObject as annotateObject, annotate as __private_annotate }
|
package/format.js
CHANGED
|
@@ -5,73 +5,57 @@ exports.formatInline = formatInline
|
|
|
5
5
|
exports.formatShort = formatShort
|
|
6
6
|
exports.serializeAnnotation = serializeAnnotation
|
|
7
7
|
exports.serializeValue = serializeValue
|
|
8
|
-
|
|
9
8
|
var _utils = require('./_utils')
|
|
10
|
-
|
|
11
9
|
function serializeString(s, width) {
|
|
12
10
|
if (width === void 0) {
|
|
13
11
|
width = 80
|
|
14
12
|
}
|
|
15
13
|
var ser = JSON.stringify(s)
|
|
16
|
-
|
|
17
14
|
if (ser.length <= width) {
|
|
18
15
|
return ser
|
|
19
16
|
}
|
|
20
|
-
|
|
21
17
|
var truncated = s.substring(0, width - 15) + '...'
|
|
22
18
|
ser = JSON.stringify(truncated) + ' [truncated]'
|
|
23
19
|
return ser
|
|
24
20
|
}
|
|
25
|
-
|
|
26
21
|
function serializeArray(annotation, prefix) {
|
|
27
22
|
var items = annotation.items
|
|
28
|
-
|
|
29
23
|
if (items.length === 0) {
|
|
30
24
|
return '[]'
|
|
31
25
|
}
|
|
32
|
-
|
|
33
26
|
var result = []
|
|
34
27
|
items.forEach(function (item) {
|
|
35
28
|
var _serializeAnnotation = serializeAnnotation(item, '' + prefix + _utils.INDENT),
|
|
36
29
|
ser = _serializeAnnotation[0],
|
|
37
30
|
ann = _serializeAnnotation[1]
|
|
38
|
-
|
|
39
31
|
result.push('' + prefix + _utils.INDENT + ser + ',')
|
|
40
|
-
|
|
41
32
|
if (ann !== undefined) {
|
|
42
33
|
result.push((0, _utils.indent)(ann, '' + prefix + _utils.INDENT))
|
|
43
34
|
}
|
|
44
35
|
})
|
|
45
36
|
return ['['].concat(result, [prefix + ']']).join('\n')
|
|
46
37
|
}
|
|
47
|
-
|
|
48
38
|
function serializeObject(annotation, prefix) {
|
|
49
39
|
var fields = annotation.fields
|
|
50
40
|
var fieldNames = Object.keys(fields)
|
|
51
|
-
|
|
52
41
|
if (fieldNames.length === 0) {
|
|
53
42
|
return '{}'
|
|
54
43
|
}
|
|
55
|
-
|
|
56
44
|
var result = []
|
|
57
45
|
fieldNames.forEach(function (key) {
|
|
58
46
|
var valueAnnotation = fields[key]
|
|
59
47
|
var kser = serializeValue(key)
|
|
60
48
|
var valPrefix = '' + prefix + _utils.INDENT + ' '.repeat(kser.length + 2)
|
|
61
|
-
|
|
62
49
|
var _serializeAnnotation2 = serializeAnnotation(valueAnnotation, '' + prefix + _utils.INDENT),
|
|
63
50
|
vser = _serializeAnnotation2[0],
|
|
64
51
|
vann = _serializeAnnotation2[1]
|
|
65
|
-
|
|
66
52
|
result.push('' + prefix + _utils.INDENT + kser + ': ' + vser + ',')
|
|
67
|
-
|
|
68
53
|
if (vann !== undefined) {
|
|
69
54
|
result.push((0, _utils.indent)(vann, valPrefix))
|
|
70
55
|
}
|
|
71
56
|
})
|
|
72
57
|
return ['{'].concat(result, [prefix + '}']).join('\n')
|
|
73
58
|
}
|
|
74
|
-
|
|
75
59
|
function serializeValue(value) {
|
|
76
60
|
if (typeof value === 'string') {
|
|
77
61
|
return serializeString(value)
|
|
@@ -83,7 +67,6 @@ function serializeValue(value) {
|
|
|
83
67
|
return 'undefined'
|
|
84
68
|
} else {
|
|
85
69
|
var valueAsDate = (0, _utils.asDate)(value)
|
|
86
|
-
|
|
87
70
|
if (valueAsDate !== null) {
|
|
88
71
|
return 'new Date(' + JSON.stringify(valueAsDate.toISOString()) + ')'
|
|
89
72
|
} else if (value instanceof Date) {
|
|
@@ -93,13 +76,11 @@ function serializeValue(value) {
|
|
|
93
76
|
}
|
|
94
77
|
}
|
|
95
78
|
}
|
|
96
|
-
|
|
97
79
|
function serializeAnnotation(ann, prefix) {
|
|
98
80
|
if (prefix === void 0) {
|
|
99
81
|
prefix = ''
|
|
100
82
|
}
|
|
101
83
|
var serialized
|
|
102
|
-
|
|
103
84
|
if (ann.type === 'array') {
|
|
104
85
|
serialized = serializeArray(ann, prefix)
|
|
105
86
|
} else if (ann.type === 'object') {
|
|
@@ -113,9 +94,7 @@ function serializeAnnotation(ann, prefix) {
|
|
|
113
94
|
} else {
|
|
114
95
|
serialized = serializeValue(ann.value)
|
|
115
96
|
}
|
|
116
|
-
|
|
117
97
|
var text = ann.text
|
|
118
|
-
|
|
119
98
|
if (text !== undefined) {
|
|
120
99
|
var sep = '^'.repeat((0, _utils.isMultiline)(serialized) ? 1 : serialized.length)
|
|
121
100
|
return [serialized, [sep, text].join((0, _utils.isMultiline)(text) ? '\n' : ' ')]
|
|
@@ -123,19 +102,16 @@ function serializeAnnotation(ann, prefix) {
|
|
|
123
102
|
return [serialized, undefined]
|
|
124
103
|
}
|
|
125
104
|
}
|
|
126
|
-
|
|
127
105
|
function formatInline(ann) {
|
|
128
106
|
var _serializeAnnotation3 = serializeAnnotation(ann),
|
|
129
107
|
serialized = _serializeAnnotation3[0],
|
|
130
108
|
annotation = _serializeAnnotation3[1]
|
|
131
|
-
|
|
132
109
|
if (annotation !== undefined) {
|
|
133
110
|
return serialized + '\n' + annotation
|
|
134
111
|
} else {
|
|
135
112
|
return serialized
|
|
136
113
|
}
|
|
137
114
|
}
|
|
138
|
-
|
|
139
115
|
function formatShort(ann) {
|
|
140
116
|
return (0, _utils.summarize)(ann, []).join('\n')
|
|
141
117
|
}
|
package/format.mjs
CHANGED
|
@@ -1,69 +1,54 @@
|
|
|
1
1
|
import { summarize as _summarize, asDate, INDENT, indent, isMultiline } from './_utils.mjs'
|
|
2
|
-
|
|
3
2
|
function serializeString(s, width) {
|
|
4
3
|
if (width === void 0) {
|
|
5
4
|
width = 80
|
|
6
5
|
}
|
|
7
6
|
var ser = JSON.stringify(s)
|
|
8
|
-
|
|
9
7
|
if (ser.length <= width) {
|
|
10
8
|
return ser
|
|
11
9
|
}
|
|
12
|
-
|
|
13
10
|
var truncated = s.substring(0, width - 15) + '...'
|
|
14
11
|
ser = JSON.stringify(truncated) + ' [truncated]'
|
|
15
12
|
return ser
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
function serializeArray(annotation, prefix) {
|
|
19
15
|
var items = annotation.items
|
|
20
|
-
|
|
21
16
|
if (items.length === 0) {
|
|
22
17
|
return '[]'
|
|
23
18
|
}
|
|
24
|
-
|
|
25
19
|
var result = []
|
|
26
20
|
items.forEach(function (item) {
|
|
27
21
|
var _serializeAnnotation = serializeAnnotation(item, '' + prefix + INDENT),
|
|
28
22
|
ser = _serializeAnnotation[0],
|
|
29
23
|
ann = _serializeAnnotation[1]
|
|
30
|
-
|
|
31
24
|
result.push('' + prefix + INDENT + ser + ',')
|
|
32
|
-
|
|
33
25
|
if (ann !== undefined) {
|
|
34
26
|
result.push(indent(ann, '' + prefix + INDENT))
|
|
35
27
|
}
|
|
36
28
|
})
|
|
37
29
|
return ['['].concat(result, [prefix + ']']).join('\n')
|
|
38
30
|
}
|
|
39
|
-
|
|
40
31
|
function serializeObject(annotation, prefix) {
|
|
41
32
|
var fields = annotation.fields
|
|
42
33
|
var fieldNames = Object.keys(fields)
|
|
43
|
-
|
|
44
34
|
if (fieldNames.length === 0) {
|
|
45
35
|
return '{}'
|
|
46
36
|
}
|
|
47
|
-
|
|
48
37
|
var result = []
|
|
49
38
|
fieldNames.forEach(function (key) {
|
|
50
39
|
var valueAnnotation = fields[key]
|
|
51
40
|
var kser = serializeValue(key)
|
|
52
41
|
var valPrefix = '' + prefix + INDENT + ' '.repeat(kser.length + 2)
|
|
53
|
-
|
|
54
42
|
var _serializeAnnotation2 = serializeAnnotation(valueAnnotation, '' + prefix + INDENT),
|
|
55
43
|
vser = _serializeAnnotation2[0],
|
|
56
44
|
vann = _serializeAnnotation2[1]
|
|
57
|
-
|
|
58
45
|
result.push('' + prefix + INDENT + kser + ': ' + vser + ',')
|
|
59
|
-
|
|
60
46
|
if (vann !== undefined) {
|
|
61
47
|
result.push(indent(vann, valPrefix))
|
|
62
48
|
}
|
|
63
49
|
})
|
|
64
50
|
return ['{'].concat(result, [prefix + '}']).join('\n')
|
|
65
51
|
}
|
|
66
|
-
|
|
67
52
|
export function serializeValue(value) {
|
|
68
53
|
if (typeof value === 'string') {
|
|
69
54
|
return serializeString(value)
|
|
@@ -75,7 +60,6 @@ export function serializeValue(value) {
|
|
|
75
60
|
return 'undefined'
|
|
76
61
|
} else {
|
|
77
62
|
var valueAsDate = asDate(value)
|
|
78
|
-
|
|
79
63
|
if (valueAsDate !== null) {
|
|
80
64
|
return 'new Date(' + JSON.stringify(valueAsDate.toISOString()) + ')'
|
|
81
65
|
} else if (value instanceof Date) {
|
|
@@ -90,7 +74,6 @@ export function serializeAnnotation(ann, prefix) {
|
|
|
90
74
|
prefix = ''
|
|
91
75
|
}
|
|
92
76
|
var serialized
|
|
93
|
-
|
|
94
77
|
if (ann.type === 'array') {
|
|
95
78
|
serialized = serializeArray(ann, prefix)
|
|
96
79
|
} else if (ann.type === 'object') {
|
|
@@ -104,9 +87,7 @@ export function serializeAnnotation(ann, prefix) {
|
|
|
104
87
|
} else {
|
|
105
88
|
serialized = serializeValue(ann.value)
|
|
106
89
|
}
|
|
107
|
-
|
|
108
90
|
var text = ann.text
|
|
109
|
-
|
|
110
91
|
if (text !== undefined) {
|
|
111
92
|
var sep = '^'.repeat(isMultiline(serialized) ? 1 : serialized.length)
|
|
112
93
|
return [serialized, [sep, text].join(isMultiline(text) ? '\n' : ' ')]
|
|
@@ -118,7 +99,6 @@ export function formatInline(ann) {
|
|
|
118
99
|
var _serializeAnnotation3 = serializeAnnotation(ann),
|
|
119
100
|
serialized = _serializeAnnotation3[0],
|
|
120
101
|
annotation = _serializeAnnotation3[1]
|
|
121
|
-
|
|
122
102
|
if (annotation !== undefined) {
|
|
123
103
|
return serialized + '\n' + annotation
|
|
124
104
|
} else {
|