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/lib/basics.js.flow
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
// @flow strict
|
|
2
|
-
|
|
3
|
-
import { define } from '../Decoder';
|
|
4
|
-
import { either } from './unions';
|
|
5
|
-
import type { _Any } from '../_utils';
|
|
6
|
-
import type { Decoder, Scalar } from '../Decoder';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Accepts and returns only the literal `null` value.
|
|
10
|
-
*/
|
|
11
|
-
export const null_: Decoder<null> = define((blob, ok, err) =>
|
|
12
|
-
blob === null ? ok(blob) : err('Must be null'),
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Accepts and returns only the literal `undefined` value.
|
|
17
|
-
*/
|
|
18
|
-
export const undefined_: Decoder<void> = define((blob, ok, err) =>
|
|
19
|
-
blob === undefined ? ok(blob) : err('Must be undefined'),
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
const undefined_or_null: Decoder<null | void> = define((blob, ok, err) =>
|
|
23
|
-
blob === undefined || blob === null
|
|
24
|
-
? ok(blob)
|
|
25
|
-
: // Combine error message into a single line for readability
|
|
26
|
-
err('Must be undefined or null'),
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
interface Maybeish<E> {
|
|
30
|
-
<T>(decoder: Decoder<T>): Decoder<E | T>;
|
|
31
|
-
<T, V>(
|
|
32
|
-
decoder: Decoder<T>,
|
|
33
|
-
defaultValue: (() => V) | V,
|
|
34
|
-
): Decoder<$NonMaybeType<T> | V>;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function _maybeish<E>(emptyCase: Decoder<E>): Maybeish<E> {
|
|
38
|
-
function _inner(decoder /* defaultValue */) {
|
|
39
|
-
const rv = either(emptyCase, decoder);
|
|
40
|
-
if (
|
|
41
|
-
// If a default value is provided...
|
|
42
|
-
arguments.length >= 2
|
|
43
|
-
) {
|
|
44
|
-
// ...then return the default value
|
|
45
|
-
const _defaultValue = arguments[1];
|
|
46
|
-
const defaultValue =
|
|
47
|
-
typeof _defaultValue === 'function' ? _defaultValue() : _defaultValue;
|
|
48
|
-
return rv.transform((value) => value ?? defaultValue);
|
|
49
|
-
} else {
|
|
50
|
-
// Otherwise the "normal" empty case
|
|
51
|
-
return rv;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return (_inner: _Any);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Accepts whatever the given decoder accepts, or `null`.
|
|
60
|
-
*
|
|
61
|
-
* If a default value is explicitly provided, return that instead in the `null`
|
|
62
|
-
* case.
|
|
63
|
-
*/
|
|
64
|
-
export const nullable: Maybeish<null> = _maybeish(null_);
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Accepts whatever the given decoder accepts, or `undefined`.
|
|
68
|
-
*
|
|
69
|
-
* If a default value is explicitly provided, return that instead in the
|
|
70
|
-
* `undefined` case.
|
|
71
|
-
*/
|
|
72
|
-
export const optional: Maybeish<void> = _maybeish(undefined_);
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Accepts whatever the given decoder accepts, or `null`, or `undefined`.
|
|
76
|
-
*
|
|
77
|
-
* If a default value is explicitly provided, return that instead in the
|
|
78
|
-
* `null`/`undefined` case.
|
|
79
|
-
*/
|
|
80
|
-
export const maybe: Maybeish<null | void> = _maybeish(undefined_or_null);
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Accepts only the given constant value.
|
|
84
|
-
*/
|
|
85
|
-
export function constant<T: Scalar>(value: T): Decoder<T> {
|
|
86
|
-
return define((blob, ok, err) =>
|
|
87
|
-
blob === value ? ok(value) : err(`Must be constant ${String(value)}`),
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Accepts anything, completely ignores it, and always returns the provided
|
|
93
|
-
* value instead.
|
|
94
|
-
*
|
|
95
|
-
* This is useful to manually add extra fields to object decoders.
|
|
96
|
-
*/
|
|
97
|
-
export function always<T>(value: (() => T) | T): Decoder<T> {
|
|
98
|
-
return define(
|
|
99
|
-
typeof value === 'function'
|
|
100
|
-
? (blob /* ignored */, ok, _) =>
|
|
101
|
-
// $FlowFixMe[incompatible-use]
|
|
102
|
-
ok(value())
|
|
103
|
-
: (blob /* ignored */, ok, _) => ok(value),
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Alias of always.
|
|
109
|
-
*/
|
|
110
|
-
export const hardcoded: <T>(T) => Decoder<T> = always;
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Accepts anything and returns it unchanged.
|
|
114
|
-
*
|
|
115
|
-
* Useful for situation in which you don't know or expect a specific type. Of
|
|
116
|
-
* course, the downside is that you won't know the type of the value statically
|
|
117
|
-
* and you'll have to further refine it yourself.
|
|
118
|
-
*/
|
|
119
|
-
export const unknown: Decoder<mixed> = define((blob, ok, _) => ok(blob));
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Alias of unknown.
|
|
123
|
-
*/
|
|
124
|
-
export const mixed: Decoder<mixed> = unknown;
|
package/lib/basics.mjs
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { define } from '../Decoder.mjs'
|
|
2
|
-
import { either } from './unions.mjs'
|
|
3
|
-
|
|
4
|
-
export var null_ = define(function (blob, ok, err) {
|
|
5
|
-
return blob === null ? ok(blob) : err('Must be null')
|
|
6
|
-
})
|
|
7
|
-
|
|
8
|
-
export var undefined_ = define(function (blob, ok, err) {
|
|
9
|
-
return blob === undefined ? ok(blob) : err('Must be undefined')
|
|
10
|
-
})
|
|
11
|
-
var undefined_or_null = define(function (blob, ok, err) {
|
|
12
|
-
return blob === undefined || blob === null ? ok(blob) : err('Must be undefined or null')
|
|
13
|
-
})
|
|
14
|
-
function _maybeish(emptyCase) {
|
|
15
|
-
function _inner(decoder) {
|
|
16
|
-
var rv = either(emptyCase, decoder)
|
|
17
|
-
if (arguments.length >= 2) {
|
|
18
|
-
var _defaultValue = arguments[1]
|
|
19
|
-
var _defaultValue2 = typeof _defaultValue === 'function' ? _defaultValue() : _defaultValue
|
|
20
|
-
return rv.transform(function (value) {
|
|
21
|
-
return value != null ? value : _defaultValue2
|
|
22
|
-
})
|
|
23
|
-
} else {
|
|
24
|
-
return rv
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return _inner
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export var nullable = _maybeish(null_)
|
|
31
|
-
|
|
32
|
-
export var optional = _maybeish(undefined_)
|
|
33
|
-
|
|
34
|
-
export var maybe = _maybeish(undefined_or_null)
|
|
35
|
-
|
|
36
|
-
export function constant(value) {
|
|
37
|
-
return define(function (blob, ok, err) {
|
|
38
|
-
return blob === value ? ok(value) : err('Must be constant ' + String(value))
|
|
39
|
-
})
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function always(value) {
|
|
43
|
-
return define(
|
|
44
|
-
typeof value === 'function'
|
|
45
|
-
? function (blob, ok, _) {
|
|
46
|
-
return ok(value())
|
|
47
|
-
}
|
|
48
|
-
: function (blob, ok, _) {
|
|
49
|
-
return ok(value)
|
|
50
|
-
}
|
|
51
|
-
)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export var hardcoded = always
|
|
55
|
-
|
|
56
|
-
export var unknown = define(function (blob, ok, _) {
|
|
57
|
-
return ok(blob)
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
export var mixed = unknown
|
package/lib/booleans.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Decoder } from '../Decoder';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Accepts and returns booleans.
|
|
5
|
-
*/
|
|
6
|
-
export const boolean: Decoder<boolean>;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Accepts anything and will return its "truth" value. Will never reject.
|
|
10
|
-
*/
|
|
11
|
-
export const truthy: Decoder<boolean>;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Accepts numbers, but return their boolean representation.
|
|
15
|
-
*/
|
|
16
|
-
export const numericBoolean: Decoder<boolean>;
|
package/lib/booleans.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
exports.__esModule = true
|
|
4
|
-
exports.truthy = exports.numericBoolean = exports['boolean'] = void 0
|
|
5
|
-
var _Decoder = require('../Decoder')
|
|
6
|
-
var _numbers = require('./numbers')
|
|
7
|
-
|
|
8
|
-
var _boolean = (0, _Decoder.define)(function (blob, ok, err) {
|
|
9
|
-
return typeof blob === 'boolean' ? ok(blob) : err('Must be boolean')
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
exports['boolean'] = _boolean
|
|
13
|
-
var truthy = (0, _Decoder.define)(function (blob, ok, _) {
|
|
14
|
-
return ok(!!blob)
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
exports.truthy = truthy
|
|
18
|
-
var numericBoolean = _numbers.number.transform(function (n) {
|
|
19
|
-
return !!n
|
|
20
|
-
})
|
|
21
|
-
exports.numericBoolean = numericBoolean
|
package/lib/booleans.js.flow
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// @flow strict
|
|
2
|
-
|
|
3
|
-
import { define } from '../Decoder';
|
|
4
|
-
import { number } from './numbers';
|
|
5
|
-
import type { Decoder } from '../Decoder';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Accepts and returns booleans.
|
|
9
|
-
*/
|
|
10
|
-
export const boolean: Decoder<boolean> = define((blob, ok, err) => {
|
|
11
|
-
return typeof blob === 'boolean' ? ok(blob) : err('Must be boolean');
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Accepts anything and will return its "truth" value. Will never reject.
|
|
16
|
-
*/
|
|
17
|
-
export const truthy: Decoder<boolean> = define((blob, ok, _) => ok(!!blob));
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Accepts numbers, but return their boolean representation.
|
|
21
|
-
*/
|
|
22
|
-
export const numericBoolean: Decoder<boolean> = number.transform((n) => !!n);
|
package/lib/booleans.mjs
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { define } from '../Decoder.mjs'
|
|
2
|
-
import { number } from './numbers.mjs'
|
|
3
|
-
|
|
4
|
-
var _boolean = define(function (blob, ok, err) {
|
|
5
|
-
return typeof blob === 'boolean' ? ok(blob) : err('Must be boolean')
|
|
6
|
-
})
|
|
7
|
-
|
|
8
|
-
export { _boolean as boolean }
|
|
9
|
-
export var truthy = define(function (blob, ok, _) {
|
|
10
|
-
return ok(!!blob)
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
export var numericBoolean = number.transform(function (n) {
|
|
14
|
-
return !!n
|
|
15
|
-
})
|
package/lib/dates.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Decoder } from '../Decoder';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Accepts and returns `Date` instances.
|
|
5
|
-
*/
|
|
6
|
-
export const date: Decoder<Date>;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Accepts [ISO8601](https://en.wikipedia.org/wiki/ISO_8601)-formatted strings,
|
|
10
|
-
* returns them as `Date` instances.
|
|
11
|
-
*
|
|
12
|
-
* This is very useful for working with dates in APIs: serialize them as
|
|
13
|
-
* `.toISOString()` when sending, decode them with `iso8601` when receiving.
|
|
14
|
-
*/
|
|
15
|
-
export const iso8601: Decoder<Date>;
|
package/lib/dates.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
exports.__esModule = true
|
|
4
|
-
exports.iso8601 = exports.date = void 0
|
|
5
|
-
var _utils = require('../_utils')
|
|
6
|
-
var _Decoder = require('../Decoder')
|
|
7
|
-
var _strings = require('./strings')
|
|
8
|
-
var iso8601_re = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:[.]\d+)?(?:Z|[+-]\d{2}:?\d{2})$/
|
|
9
|
-
|
|
10
|
-
var date = (0, _Decoder.define)(function (blob, ok, err) {
|
|
11
|
-
var date = (0, _utils.asDate)(blob)
|
|
12
|
-
return date !== null ? ok(date) : err('Must be a Date')
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
exports.date = date
|
|
16
|
-
var iso8601 = (0, _strings.regex)(iso8601_re, 'Must be ISO8601 format').transform(function (value) {
|
|
17
|
-
var date = new Date(value)
|
|
18
|
-
if (isNaN(date.getTime())) {
|
|
19
|
-
throw new Error('Must be valid date/time value')
|
|
20
|
-
}
|
|
21
|
-
return date
|
|
22
|
-
})
|
|
23
|
-
exports.iso8601 = iso8601
|
package/lib/dates.js.flow
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
// @flow strict
|
|
2
|
-
|
|
3
|
-
import { asDate } from '../_utils';
|
|
4
|
-
import { define } from '../Decoder';
|
|
5
|
-
import { regex } from './strings';
|
|
6
|
-
import type { Decoder } from '../Decoder';
|
|
7
|
-
|
|
8
|
-
// Only matches the shape. This "over-matches" some values that still aren't
|
|
9
|
-
// valid dates (like 9999-99-99), but those will be caught by JS Date's
|
|
10
|
-
// internal validations
|
|
11
|
-
const iso8601_re =
|
|
12
|
-
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:[.]\d+)?(?:Z|[+-]\d{2}:?\d{2})$/;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Accepts and returns `Date` instances.
|
|
16
|
-
*/
|
|
17
|
-
export const date: Decoder<Date> = define((blob, ok, err) => {
|
|
18
|
-
const date = asDate(blob);
|
|
19
|
-
return date !== null ? ok(date) : err('Must be a Date');
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Accepts [ISO8601](https://en.wikipedia.org/wiki/ISO_8601)-formatted strings,
|
|
24
|
-
* returns them as `Date` instances.
|
|
25
|
-
*
|
|
26
|
-
* This is very useful for working with dates in APIs: serialize them as
|
|
27
|
-
* `.toISOString()` when sending, decode them with `iso8601` when receiving.
|
|
28
|
-
*/
|
|
29
|
-
export const iso8601: Decoder<Date> =
|
|
30
|
-
// Input itself needs to match the ISO8601 regex...
|
|
31
|
-
regex(iso8601_re, 'Must be ISO8601 format').transform(
|
|
32
|
-
// Make sure it is a _valid_ date
|
|
33
|
-
(value: string) => {
|
|
34
|
-
const date = new Date(value);
|
|
35
|
-
if (isNaN(date.getTime())) {
|
|
36
|
-
throw new Error('Must be valid date/time value');
|
|
37
|
-
}
|
|
38
|
-
return date;
|
|
39
|
-
},
|
|
40
|
-
);
|
package/lib/dates.mjs
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { asDate } from '../_utils.mjs'
|
|
2
|
-
import { define } from '../Decoder.mjs'
|
|
3
|
-
import { regex } from './strings.mjs'
|
|
4
|
-
var iso8601_re = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:[.]\d+)?(?:Z|[+-]\d{2}:?\d{2})$/
|
|
5
|
-
|
|
6
|
-
export var date = define(function (blob, ok, err) {
|
|
7
|
-
var date = asDate(blob)
|
|
8
|
-
return date !== null ? ok(date) : err('Must be a Date')
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
export var iso8601 = regex(iso8601_re, 'Must be ISO8601 format').transform(function (value) {
|
|
12
|
-
var date = new Date(value)
|
|
13
|
-
if (isNaN(date.getTime())) {
|
|
14
|
-
throw new Error('Must be valid date/time value')
|
|
15
|
-
}
|
|
16
|
-
return date
|
|
17
|
-
})
|
package/lib/json.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { Decoder } from '../Decoder';
|
|
2
|
-
|
|
3
|
-
export type JSONValue = null | string | number | boolean | JSONObject | JSONArray;
|
|
4
|
-
export interface JSONObject {
|
|
5
|
-
[key: string]: JSONValue | undefined;
|
|
6
|
-
}
|
|
7
|
-
export type JSONArray = JSONValue[];
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Accepts any value that's a valid JSON value.
|
|
11
|
-
*
|
|
12
|
-
* In other words: any value returned by `JSON.parse()` should decode without
|
|
13
|
-
* failure.
|
|
14
|
-
*
|
|
15
|
-
* ```typescript
|
|
16
|
-
* type JSONValue =
|
|
17
|
-
* | null
|
|
18
|
-
* | string
|
|
19
|
-
* | number
|
|
20
|
-
* | boolean
|
|
21
|
-
* | { [string]: JSONValue }
|
|
22
|
-
* | JSONValue[]
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
export const json: Decoder<JSONValue>;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Accepts arrays that contain only valid JSON values.
|
|
29
|
-
*/
|
|
30
|
-
export const jsonArray: Decoder<JSONArray>;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Accepts objects that contain only valid JSON values.
|
|
34
|
-
*/
|
|
35
|
-
export const jsonObject: Decoder<JSONObject>;
|
package/lib/json.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
exports.__esModule = true
|
|
4
|
-
exports.jsonObject = exports.jsonArray = exports.json = void 0
|
|
5
|
-
var _arrays = require('./arrays')
|
|
6
|
-
var _booleans = require('./booleans')
|
|
7
|
-
var _objects = require('./objects')
|
|
8
|
-
var _unions = require('./unions')
|
|
9
|
-
var _utilities = require('./utilities')
|
|
10
|
-
var _basics = require('./basics')
|
|
11
|
-
var _numbers = require('./numbers')
|
|
12
|
-
var _strings = require('./strings')
|
|
13
|
-
|
|
14
|
-
var jsonObject = (0, _utilities.lazy)(function () {
|
|
15
|
-
return (0, _objects.dict)(json)
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
exports.jsonObject = jsonObject
|
|
19
|
-
var jsonArray = (0, _utilities.lazy)(function () {
|
|
20
|
-
return (0, _arrays.array)(json)
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
exports.jsonArray = jsonArray
|
|
24
|
-
var json = (0, _unions.either)(_basics.null_, _strings.string, _numbers.number, _booleans['boolean'], jsonObject, jsonArray).describe('Must be valid JSON value')
|
|
25
|
-
exports.json = json
|
package/lib/json.js.flow
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
// @flow strict
|
|
2
|
-
|
|
3
|
-
import { array } from './arrays';
|
|
4
|
-
import { boolean } from './booleans';
|
|
5
|
-
import { dict } from './objects';
|
|
6
|
-
import { either } from './unions';
|
|
7
|
-
import { lazy } from './utilities';
|
|
8
|
-
import { null_ } from './basics';
|
|
9
|
-
import { number } from './numbers';
|
|
10
|
-
import { string } from './strings';
|
|
11
|
-
import type { Decoder } from '../Decoder';
|
|
12
|
-
|
|
13
|
-
export type JSONValue = null | string | number | boolean | JSONObject | JSONArray;
|
|
14
|
-
export type JSONObject = { [string]: JSONValue };
|
|
15
|
-
export type JSONArray = Array<JSONValue>;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Accepts objects that contain only valid JSON values.
|
|
19
|
-
*/
|
|
20
|
-
export const jsonObject: Decoder<JSONObject> = lazy(() => dict(json));
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Accepts arrays that contain only valid JSON values.
|
|
24
|
-
*/
|
|
25
|
-
export const jsonArray: Decoder<JSONArray> = lazy(() => array(json));
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Accepts any value that's a valid JSON value.
|
|
29
|
-
*
|
|
30
|
-
* In other words: any value returned by `JSON.parse()` should decode without
|
|
31
|
-
* failure.
|
|
32
|
-
*
|
|
33
|
-
* ```typescript
|
|
34
|
-
* type JSONValue =
|
|
35
|
-
* | null
|
|
36
|
-
* | string
|
|
37
|
-
* | number
|
|
38
|
-
* | boolean
|
|
39
|
-
* | { [string]: JSONValue }
|
|
40
|
-
* | JSONValue[]
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
export const json: Decoder<JSONValue> = either(
|
|
44
|
-
null_,
|
|
45
|
-
string,
|
|
46
|
-
number,
|
|
47
|
-
boolean,
|
|
48
|
-
jsonObject,
|
|
49
|
-
jsonArray,
|
|
50
|
-
).describe('Must be valid JSON value');
|
package/lib/json.mjs
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { array } from './arrays.mjs'
|
|
2
|
-
import { boolean as _boolean } from './booleans.mjs'
|
|
3
|
-
import { dict } from './objects.mjs'
|
|
4
|
-
import { either } from './unions.mjs'
|
|
5
|
-
import { lazy } from './utilities.mjs'
|
|
6
|
-
import { null_ } from './basics.mjs'
|
|
7
|
-
import { number } from './numbers.mjs'
|
|
8
|
-
import { string } from './strings.mjs'
|
|
9
|
-
|
|
10
|
-
export var jsonObject = lazy(function () {
|
|
11
|
-
return dict(json)
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
export var jsonArray = lazy(function () {
|
|
15
|
-
return array(json)
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
export var json = either(null_, string, number, _boolean, jsonObject, jsonArray).describe('Must be valid JSON value')
|
package/lib/numbers.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Decoder } from '../Decoder';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Accepts any valid ``number`` value.
|
|
5
|
-
*
|
|
6
|
-
* This also accepts special values like `NaN` and `Infinity`. Unless you
|
|
7
|
-
* want to deliberately accept those, you'll likely want to use the
|
|
8
|
-
* `number` decoder instead.
|
|
9
|
-
*/
|
|
10
|
-
export const anyNumber: Decoder<number>;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Accepts finite numbers (can be integer or float values). Values `NaN`,
|
|
14
|
-
* or positive and negative `Infinity` will get rejected.
|
|
15
|
-
*/
|
|
16
|
-
export const number: Decoder<number>;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Accepts only finite whole numbers.
|
|
20
|
-
*/
|
|
21
|
-
export const integer: Decoder<number>;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Accepts only non-negative (zero or positive) finite numbers.
|
|
25
|
-
*/
|
|
26
|
-
export const positiveNumber: Decoder<number>;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Accepts only non-negative (zero or positive) finite whole numbers.
|
|
30
|
-
*/
|
|
31
|
-
export const positiveInteger: Decoder<number>;
|
package/lib/numbers.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
exports.__esModule = true
|
|
4
|
-
exports.positiveNumber = exports.positiveInteger = exports.number = exports.integer = exports.anyNumber = void 0
|
|
5
|
-
var _Decoder = require('../Decoder')
|
|
6
|
-
|
|
7
|
-
var anyNumber = (0, _Decoder.define)(function (blob, ok, err) {
|
|
8
|
-
return typeof blob === 'number' ? ok(blob) : err('Must be number')
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
exports.anyNumber = anyNumber
|
|
12
|
-
var number = anyNumber.refine(function (n) {
|
|
13
|
-
return Number.isFinite(n)
|
|
14
|
-
}, 'Number must be finite')
|
|
15
|
-
|
|
16
|
-
exports.number = number
|
|
17
|
-
var integer = number.refine(function (n) {
|
|
18
|
-
return Number.isInteger(n)
|
|
19
|
-
}, 'Number must be an integer')
|
|
20
|
-
|
|
21
|
-
exports.integer = integer
|
|
22
|
-
var positiveNumber = number
|
|
23
|
-
.refine(function (n) {
|
|
24
|
-
return n >= 0
|
|
25
|
-
}, 'Number must be positive')
|
|
26
|
-
.transform(Math.abs)
|
|
27
|
-
|
|
28
|
-
exports.positiveNumber = positiveNumber
|
|
29
|
-
var positiveInteger = integer
|
|
30
|
-
.refine(function (n) {
|
|
31
|
-
return n >= 0
|
|
32
|
-
}, 'Number must be positive')
|
|
33
|
-
.transform(Math.abs)
|
|
34
|
-
exports.positiveInteger = positiveInteger
|
package/lib/numbers.js.flow
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
// @flow strict
|
|
2
|
-
|
|
3
|
-
import { define } from '../Decoder';
|
|
4
|
-
import type { Decoder } from '../Decoder';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Accepts any valid ``number`` value.
|
|
8
|
-
*
|
|
9
|
-
* This also accepts special values like `NaN` and `Infinity`. Unless you
|
|
10
|
-
* want to deliberately accept those, you'll likely want to use the
|
|
11
|
-
* `number` decoder instead.
|
|
12
|
-
*/
|
|
13
|
-
export const anyNumber: Decoder<number> = define((blob, ok, err) =>
|
|
14
|
-
typeof blob === 'number' ? ok(blob) : err('Must be number'),
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Accepts finite numbers (can be integer or float values). Values `NaN`,
|
|
19
|
-
* or positive and negative `Infinity` will get rejected.
|
|
20
|
-
*/
|
|
21
|
-
export const number: Decoder<number> = anyNumber.refine(
|
|
22
|
-
(n) => Number.isFinite(n),
|
|
23
|
-
'Number must be finite',
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Accepts only finite whole numbers.
|
|
28
|
-
*/
|
|
29
|
-
export const integer: Decoder<number> = number.refine(
|
|
30
|
-
(n) => Number.isInteger(n),
|
|
31
|
-
'Number must be an integer',
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Accepts only non-negative (zero or positive) finite numbers.
|
|
36
|
-
*/
|
|
37
|
-
export const positiveNumber: Decoder<number> = number
|
|
38
|
-
.refine((n) => n >= 0, 'Number must be positive')
|
|
39
|
-
.transform(Math.abs); // Just here to handle the -0 case
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Accepts only non-negative (zero or positive) finite whole numbers.
|
|
43
|
-
*/
|
|
44
|
-
export const positiveInteger: Decoder<number> = integer
|
|
45
|
-
.refine((n) => n >= 0, 'Number must be positive')
|
|
46
|
-
.transform(Math.abs); // Just here to handle the -0 case
|
package/lib/numbers.mjs
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { define } from '../Decoder.mjs'
|
|
2
|
-
|
|
3
|
-
export var anyNumber = define(function (blob, ok, err) {
|
|
4
|
-
return typeof blob === 'number' ? ok(blob) : err('Must be number')
|
|
5
|
-
})
|
|
6
|
-
|
|
7
|
-
export var number = anyNumber.refine(function (n) {
|
|
8
|
-
return Number.isFinite(n)
|
|
9
|
-
}, 'Number must be finite')
|
|
10
|
-
|
|
11
|
-
export var integer = number.refine(function (n) {
|
|
12
|
-
return Number.isInteger(n)
|
|
13
|
-
}, 'Number must be an integer')
|
|
14
|
-
|
|
15
|
-
export var positiveNumber = number
|
|
16
|
-
.refine(function (n) {
|
|
17
|
-
return n >= 0
|
|
18
|
-
}, 'Number must be positive')
|
|
19
|
-
.transform(Math.abs)
|
|
20
|
-
|
|
21
|
-
export var positiveInteger = integer
|
|
22
|
-
.refine(function (n) {
|
|
23
|
-
return n >= 0
|
|
24
|
-
}, 'Number must be positive')
|
|
25
|
-
.transform(Math.abs)
|