decoders 2.0.0-beta1 → 2.0.0-beta10

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.
Files changed (160) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/Decoder.d.ts +27 -0
  3. package/Decoder.js +199 -0
  4. package/Decoder.js.flow +224 -0
  5. package/Decoder.mjs +192 -0
  6. package/NotSupportedTSVersion.d.ts +1 -0
  7. package/README.md +105 -961
  8. package/_utils.d.ts +9 -0
  9. package/{cjs/_utils.js → _utils.js} +12 -18
  10. package/{cjs/_utils.js.flow → _utils.js.flow} +15 -19
  11. package/{es/_utils.js → _utils.mjs} +11 -15
  12. package/{ts/annotate.d.ts → annotate.d.ts} +25 -21
  13. package/{cjs/annotate.js → annotate.js} +0 -0
  14. package/{cjs/annotate.js.flow → annotate.js.flow} +0 -0
  15. package/{es/annotate.js → annotate.mjs} +0 -0
  16. package/format.d.ts +4 -0
  17. package/{cjs/format/inline.js → format.js} +7 -2
  18. package/{cjs/format/inline.js.flow → format.js.flow} +7 -3
  19. package/{es/format/inline.js → format.mjs} +5 -2
  20. package/index.d.ts +40 -0
  21. package/index.js +90 -0
  22. package/index.js.flow +44 -0
  23. package/index.mjs +11 -0
  24. package/{ts → lib}/_helpers.d.ts +0 -0
  25. package/lib/arrays.d.ts +37 -0
  26. package/lib/arrays.js +138 -0
  27. package/lib/arrays.js.flow +138 -0
  28. package/lib/arrays.mjs +123 -0
  29. package/lib/basics.d.ts +14 -0
  30. package/lib/basics.js +109 -0
  31. package/lib/basics.js.flow +85 -0
  32. package/lib/basics.mjs +85 -0
  33. package/{ts/boolean.d.ts → lib/booleans.d.ts} +1 -1
  34. package/lib/booleans.js +35 -0
  35. package/lib/booleans.js.flow +22 -0
  36. package/lib/booleans.mjs +25 -0
  37. package/{ts/date.d.ts → lib/dates.d.ts} +1 -1
  38. package/lib/dates.js +44 -0
  39. package/lib/dates.js.flow +40 -0
  40. package/lib/dates.mjs +34 -0
  41. package/{ts → lib}/json.d.ts +1 -1
  42. package/lib/json.js +55 -0
  43. package/lib/json.js.flow +50 -0
  44. package/lib/json.mjs +40 -0
  45. package/{ts/number.d.ts → lib/numbers.d.ts} +2 -1
  46. package/lib/numbers.js +52 -0
  47. package/lib/numbers.js.flow +49 -0
  48. package/lib/numbers.mjs +42 -0
  49. package/{ts/object.d.ts → lib/objects.d.ts} +9 -4
  50. package/lib/objects.js +240 -0
  51. package/lib/objects.js.flow +246 -0
  52. package/lib/objects.mjs +223 -0
  53. package/lib/strings.d.ts +13 -0
  54. package/lib/strings.js +101 -0
  55. package/lib/strings.js.flow +90 -0
  56. package/lib/strings.mjs +82 -0
  57. package/lib/unions.d.ts +78 -0
  58. package/lib/unions.js +161 -0
  59. package/lib/unions.js.flow +158 -0
  60. package/lib/unions.mjs +145 -0
  61. package/lib/utilities.d.ts +10 -0
  62. package/lib/utilities.js +94 -0
  63. package/lib/utilities.js.flow +84 -0
  64. package/lib/utilities.mjs +79 -0
  65. package/package.json +79 -29
  66. package/result.d.ts +16 -0
  67. package/result.js +34 -0
  68. package/result.js.flow +26 -0
  69. package/result.mjs +27 -0
  70. package/cjs/_guard.js +0 -26
  71. package/cjs/_guard.js.flow +0 -20
  72. package/cjs/_types.js +0 -1
  73. package/cjs/_types.js.flow +0 -20
  74. package/cjs/format/index.js +0 -12
  75. package/cjs/format/index.js.flow +0 -4
  76. package/cjs/format/short.js +0 -10
  77. package/cjs/format/short.js.flow +0 -8
  78. package/cjs/index.js +0 -120
  79. package/cjs/index.js.flow +0 -63
  80. package/cjs/result.js +0 -172
  81. package/cjs/result.js.flow +0 -166
  82. package/cjs/stdlib/array.js +0 -108
  83. package/cjs/stdlib/array.js.flow +0 -103
  84. package/cjs/stdlib/boolean.js +0 -44
  85. package/cjs/stdlib/boolean.js.flow +0 -29
  86. package/cjs/stdlib/composition.js +0 -56
  87. package/cjs/stdlib/composition.js.flow +0 -43
  88. package/cjs/stdlib/constants.js +0 -69
  89. package/cjs/stdlib/constants.js.flow +0 -46
  90. package/cjs/stdlib/date.js +0 -46
  91. package/cjs/stdlib/date.js.flow +0 -40
  92. package/cjs/stdlib/describe.js +0 -26
  93. package/cjs/stdlib/describe.js.flow +0 -17
  94. package/cjs/stdlib/dispatch.js +0 -62
  95. package/cjs/stdlib/dispatch.js.flow +0 -58
  96. package/cjs/stdlib/either.js +0 -117
  97. package/cjs/stdlib/either.js.flow +0 -151
  98. package/cjs/stdlib/fail.js +0 -21
  99. package/cjs/stdlib/fail.js.flow +0 -12
  100. package/cjs/stdlib/instanceOf.js +0 -19
  101. package/cjs/stdlib/instanceOf.js.flow +0 -20
  102. package/cjs/stdlib/json.js +0 -31
  103. package/cjs/stdlib/json.js.flow +0 -28
  104. package/cjs/stdlib/lazy.js +0 -16
  105. package/cjs/stdlib/lazy.js.flow +0 -15
  106. package/cjs/stdlib/mapping.js +0 -67
  107. package/cjs/stdlib/mapping.js.flow +0 -54
  108. package/cjs/stdlib/number.js +0 -40
  109. package/cjs/stdlib/number.js.flow +0 -34
  110. package/cjs/stdlib/object.js +0 -194
  111. package/cjs/stdlib/object.js.flow +0 -203
  112. package/cjs/stdlib/optional.js +0 -54
  113. package/cjs/stdlib/optional.js.flow +0 -41
  114. package/cjs/stdlib/string.js +0 -98
  115. package/cjs/stdlib/string.js.flow +0 -82
  116. package/cjs/stdlib/tuple.js +0 -173
  117. package/cjs/stdlib/tuple.js.flow +0 -220
  118. package/es/_guard.js +0 -15
  119. package/es/_types.js +0 -0
  120. package/es/format/index.js +0 -2
  121. package/es/format/short.js +0 -4
  122. package/es/index.js +0 -37
  123. package/es/result.js +0 -139
  124. package/es/stdlib/array.js +0 -91
  125. package/es/stdlib/boolean.js +0 -28
  126. package/es/stdlib/composition.js +0 -42
  127. package/es/stdlib/constants.js +0 -46
  128. package/es/stdlib/date.js +0 -28
  129. package/es/stdlib/describe.js +0 -16
  130. package/es/stdlib/dispatch.js +0 -51
  131. package/es/stdlib/either.js +0 -90
  132. package/es/stdlib/fail.js +0 -11
  133. package/es/stdlib/instanceOf.js +0 -8
  134. package/es/stdlib/json.js +0 -15
  135. package/es/stdlib/lazy.js +0 -11
  136. package/es/stdlib/mapping.js +0 -54
  137. package/es/stdlib/number.js +0 -25
  138. package/es/stdlib/object.js +0 -175
  139. package/es/stdlib/optional.js +0 -38
  140. package/es/stdlib/string.js +0 -76
  141. package/es/stdlib/tuple.js +0 -155
  142. package/ts/_guard.d.ts +0 -7
  143. package/ts/_types.d.ts +0 -16
  144. package/ts/_utils.d.ts +0 -13
  145. package/ts/array.d.ts +0 -5
  146. package/ts/constants.d.ts +0 -11
  147. package/ts/describe.d.ts +0 -3
  148. package/ts/dispatch.d.ts +0 -8
  149. package/ts/either.d.ts +0 -61
  150. package/ts/fail.d.ts +0 -3
  151. package/ts/index.d.ts +0 -42
  152. package/ts/inline.d.ts +0 -3
  153. package/ts/instanceOf.d.ts +0 -3
  154. package/ts/lazy.d.ts +0 -3
  155. package/ts/mapping.d.ts +0 -4
  156. package/ts/optional.d.ts +0 -5
  157. package/ts/result.d.ts +0 -39
  158. package/ts/short.d.ts +0 -3
  159. package/ts/string.d.ts +0 -7
  160. package/ts/tuple.d.ts +0 -30
@@ -0,0 +1,79 @@
1
+ import { annotate } from '../annotate.mjs';
2
+ import { define } from '../Decoder.mjs';
3
+
4
+ /**
5
+ * Accepts any value that is an ``instanceof`` the given class.
6
+ */
7
+ export function instanceOf(klass) {
8
+ return define(function (blob, ok, err) {
9
+ return blob instanceof klass ? ok(blob) : err("Must be " + // $FlowFixMe[incompatible-use] - klass.name is fine?
10
+ klass.name + " instance");
11
+ });
12
+ }
13
+ /**
14
+ * Lazily evaluate the given decoder. This is useful to build self-referential
15
+ * types for recursive data structures.
16
+ *
17
+ * Example:
18
+ *
19
+ * ```ts
20
+ * type Tree = {
21
+ * value: string;
22
+ * children: Array<Tree>;
23
+ * // ^^^^
24
+ * // Self-reference defining a recursive type
25
+ * };
26
+ *
27
+ * const treeDecoder: Decoder<Tree> = object({
28
+ * value: string,
29
+ * children: array(lazy(() => treeDecoder)),
30
+ * // ^^^^^^^^^^^^^^^^^^^^^^^
31
+ * // Use lazy() like this to refer to the treeDecoder which is
32
+ * // getting defined here
33
+ * });
34
+ * ```
35
+ */
36
+
37
+ export function lazy(decoderFn) {
38
+ return define(function (blob) {
39
+ return decoderFn().decode(blob);
40
+ });
41
+ }
42
+ /**
43
+ * Pre-process the data input before passing it into the decoder. This gives
44
+ * you the ability to arbitrarily customize the input on the fly before passing
45
+ * it to the decoder. Of course, the input value at that point is still of
46
+ * ``unknown`` type, so you will have to deal with that accordingly.
47
+ */
48
+
49
+ export function prep(mapperFn, decoder) {
50
+ return define(function (originalInput, _, err) {
51
+ var blob;
52
+
53
+ try {
54
+ blob = mapperFn(originalInput);
55
+ } catch (e) {
56
+ return err(annotate(originalInput, e.message));
57
+ }
58
+
59
+ var r = decoder.decode(blob);
60
+ return r.ok ? r : err(annotate(originalInput, r.error.text)); // ^^^^^^^^^^^^^
61
+ // Annotates the _original_ input value
62
+ // (instead of echoing back blob)
63
+ });
64
+ }
65
+ /**
66
+ * Rejects all inputs, and always fails with the given error message. May be
67
+ * useful for explicitly disallowing keys, or for testing purposes.
68
+ */
69
+
70
+ export function never(msg) {
71
+ return define(function (_, __, err) {
72
+ return err(msg);
73
+ });
74
+ }
75
+ /**
76
+ * Alias of never().
77
+ */
78
+
79
+ export var fail = never;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "decoders",
3
- "version": "2.0.0-beta1",
3
+ "version": "2.0.0-beta10",
4
4
  "description": "Elegant and battle-tested validation library for type-safe input data (for TypeScript and Flow)",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -12,43 +12,93 @@
12
12
  "bugs": {
13
13
  "url": "https://github.com/nvie/decoders/issues"
14
14
  },
15
- "main": "./cjs/index.js",
16
- "module": "./es/index.js",
17
- "type": "module",
18
- "exports": {
19
- "require": "./cjs/index.js",
20
- "import": "./es/index.js"
21
- },
22
- "engines": {
23
- "node": ">=12"
24
- },
15
+ "main": "./index.js",
16
+ "module": "./index.mjs",
25
17
  "keywords": [
26
- "decoder",
27
18
  "decoders",
28
- "guard",
29
- "object",
19
+ "Decoder",
20
+ "always",
21
+ "and",
30
22
  "array",
31
- "string",
32
- "email",
33
- "regex",
34
- "number",
35
- "integer",
36
23
  "boolean",
37
- "truthy",
24
+ "then",
25
+ "compose",
26
+ "constant",
38
27
  "date",
39
- "mapping",
28
+ "decode",
29
+ "decoder",
30
+ "decoders",
31
+ "define",
32
+ "describe",
40
33
  "dict",
34
+ "either",
35
+ "email",
36
+ "exact",
37
+ "fail",
38
+ "hardcoded",
39
+ "httpsUrl",
40
+ "inexact",
41
+ "instanceOf",
42
+ "integer",
43
+ "iso8601",
44
+ "json",
45
+ "jsonArray",
46
+ "jsonObject",
47
+ "lazy",
48
+ "map",
49
+ "mapping",
50
+ "maybe",
41
51
  "mixed",
52
+ "mixedarray",
53
+ "never",
54
+ "nonEmptyArray",
55
+ "nonEmptyString",
56
+ "nullable",
57
+ "null_",
58
+ "number",
59
+ "numericBoolean",
60
+ "object",
61
+ "oneOf",
62
+ "optional",
63
+ "poja",
64
+ "pojo",
65
+ "positiveInteger",
66
+ "positiveNumber",
67
+ "predicate",
68
+ "prep",
69
+ "regex",
70
+ "set",
71
+ "string",
72
+ "taggedUnion",
73
+ "transform",
74
+ "truthy",
75
+ "tuple",
42
76
  "tuple2",
77
+ "undefined_",
43
78
  "unknown",
44
- "optional",
45
- "nullable",
46
- "maybe",
47
- "compose",
48
- "map",
49
- "predicate"
79
+ "url",
80
+ "uuid",
81
+ "uuidv1",
82
+ "uuidv4",
83
+ "verify",
84
+ "DecodeResult",
85
+ "DecoderType",
86
+ "JSONArray",
87
+ "JSONObject",
88
+ "JSONValue"
50
89
  ],
51
- "types": "./ts/index.d.ts",
52
90
  "githubUrl": "https://github.com/nvie/decoders",
53
- "sideEffects": false
91
+ "sideEffects": false,
92
+ "typesVersions": {
93
+ ">=4.1.0": {
94
+ "*": [
95
+ "*"
96
+ ]
97
+ },
98
+ "*": {
99
+ "*": [
100
+ "NotSupportedTSVersion.d.ts"
101
+ ]
102
+ }
103
+ }
54
104
  }
package/result.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ export interface Ok<T> {
2
+ ok: true;
3
+ value: T;
4
+ error: undefined;
5
+ }
6
+
7
+ export interface Err<E> {
8
+ ok: false;
9
+ value: undefined;
10
+ error: E;
11
+ }
12
+
13
+ export type Result<T, E> = Ok<T> | Err<E>;
14
+
15
+ export function ok<T>(value: T): Ok<T>;
16
+ export function err<E>(error: E): Err<E>;
package/result.js ADDED
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.err = err;
5
+ exports.ok = ok;
6
+
7
+ /**
8
+ * Result <value> <error>
9
+ * = Ok <value>
10
+ * | Err <error>
11
+ */
12
+
13
+ /**
14
+ * Create a new Result instance representing a successful computation.
15
+ */
16
+ function ok(value) {
17
+ return {
18
+ ok: true,
19
+ value: value,
20
+ error: undefined
21
+ };
22
+ }
23
+ /**
24
+ * Create a new Result instance representing a failed computation.
25
+ */
26
+
27
+
28
+ function err(error) {
29
+ return {
30
+ ok: false,
31
+ value: undefined,
32
+ error: error
33
+ };
34
+ }
package/result.js.flow ADDED
@@ -0,0 +1,26 @@
1
+ // @flow strict
2
+
3
+ /**
4
+ * Result <value> <error>
5
+ * = Ok <value>
6
+ * | Err <error>
7
+ */
8
+
9
+ type Ok<+T> = {| +ok: true, +value: T, +error: void |};
10
+ type Err<+E> = {| +ok: false, +value: void, +error: E |};
11
+
12
+ export type Result<+T, +E> = Ok<T> | Err<E>;
13
+
14
+ /**
15
+ * Create a new Result instance representing a successful computation.
16
+ */
17
+ export function ok<T>(value: T): Ok<T> {
18
+ return { ok: true, value, error: undefined };
19
+ }
20
+
21
+ /**
22
+ * Create a new Result instance representing a failed computation.
23
+ */
24
+ export function err<E>(error: E): Err<E> {
25
+ return { ok: false, value: undefined, error };
26
+ }
package/result.mjs ADDED
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Result <value> <error>
3
+ * = Ok <value>
4
+ * | Err <error>
5
+ */
6
+
7
+ /**
8
+ * Create a new Result instance representing a successful computation.
9
+ */
10
+ export function ok(value) {
11
+ return {
12
+ ok: true,
13
+ value: value,
14
+ error: undefined
15
+ };
16
+ }
17
+ /**
18
+ * Create a new Result instance representing a failed computation.
19
+ */
20
+
21
+ export function err(error) {
22
+ return {
23
+ ok: false,
24
+ value: undefined,
25
+ error: error
26
+ };
27
+ }
package/cjs/_guard.js DELETED
@@ -1,26 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.guard = guard;
5
-
6
- var Result = _interopRequireWildcard(require("./result"));
7
-
8
- var _format = require("./format");
9
-
10
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
11
-
12
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
13
-
14
- function guard(decoder, formatter) {
15
- if (formatter === void 0) {
16
- formatter = _format.formatInline;
17
- }
18
-
19
- return function (blob) {
20
- return Result.unwrap(Result.mapError(decoder(blob), function (annotation) {
21
- var err = new Error('\n' + formatter(annotation));
22
- err.name = 'Decoding error';
23
- return err;
24
- }));
25
- };
26
- }
@@ -1,20 +0,0 @@
1
- // @flow strict
2
-
3
- import * as Result from './result';
4
- import { formatInline } from './format';
5
- import type { Annotation } from './annotate';
6
- import type { Decoder, Guard } from './_types';
7
-
8
- export function guard<T>(
9
- decoder: Decoder<T>,
10
- formatter: (Annotation) => string = formatInline,
11
- ): Guard<T> {
12
- return (blob: mixed) =>
13
- Result.unwrap(
14
- Result.mapError(decoder(blob), (annotation) => {
15
- const err = new Error('\n' + formatter(annotation));
16
- err.name = 'Decoding error';
17
- return err;
18
- }),
19
- );
20
- }
package/cjs/_types.js DELETED
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,20 +0,0 @@
1
- // @flow strict
2
-
3
- import type { Annotation } from './annotate';
4
- import type { Result } from './result';
5
-
6
- export type Scalar = string | number | boolean | symbol | void | null;
7
-
8
- export type Predicate<T> = (T) => boolean;
9
- export type DecodeResult<T> = Result<T, Annotation>;
10
-
11
- export type Decoder<T, F = mixed> = (F) => DecodeResult<T>;
12
- export type Guard<T> = (mixed) => T;
13
-
14
- /**
15
- * A "type function" which informs Flow about how a type will be modified at runtime.
16
- * Read this as "given a Guard of type T, I can produce a value of type T". This
17
- * definition helps construct $ObjMap types.
18
- */
19
- export type DecoderType = <T>(Decoder<T>) => T;
20
- export type GuardType = <T>(Guard<T>) => T;
@@ -1,12 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.formatShort = exports.formatInline = void 0;
5
-
6
- var _inline = require("./inline");
7
-
8
- exports.formatInline = _inline.formatInline;
9
-
10
- var _short = require("./short");
11
-
12
- exports.formatShort = _short.formatShort;
@@ -1,4 +0,0 @@
1
- // @flow strict
2
-
3
- export { formatInline } from './inline';
4
- export { formatShort } from './short';
@@ -1,10 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.formatShort = formatShort;
5
-
6
- var _utils = require("../_utils");
7
-
8
- function formatShort(ann) {
9
- return (0, _utils.summarize)(ann, []).join('\n');
10
- }
@@ -1,8 +0,0 @@
1
- // @flow strict
2
-
3
- import { summarize as _summarize } from '../_utils';
4
- import type { Annotation } from '../annotate';
5
-
6
- export function formatShort(ann: Annotation): string {
7
- return _summarize(ann, []).join('\n');
8
- }
package/cjs/index.js DELETED
@@ -1,120 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.url = exports.unknown = exports.undefined_ = exports.tuple6 = exports.tuple5 = exports.tuple4 = exports.tuple3 = exports.tuple2 = exports.tuple1 = exports.truthy = exports.string = exports.regex = exports.predicate = 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.mixed = exports.maybe = exports.mapping = exports.map = exports.lazy = exports.jsonObject = exports.jsonArray = exports.json = exports.iso8601 = exports.integer = exports.instanceOf = exports.inexact = exports.hardcoded = exports.guard = exports.fail = exports.exact = exports.email = exports.either9 = exports.either8 = exports.either7 = exports.either6 = exports.either5 = exports.either4 = exports.either3 = exports.either = exports.dispatch = exports.dict = exports.describe = exports.date = exports.constant = exports.compose = exports["boolean"] = exports.array = void 0;
5
-
6
- var _guard = require("./_guard");
7
-
8
- exports.guard = _guard.guard;
9
-
10
- var _composition = require("./stdlib/composition");
11
-
12
- exports.compose = _composition.compose;
13
- exports.map = _composition.map;
14
- exports.predicate = _composition.predicate;
15
-
16
- var _array = require("./stdlib/array");
17
-
18
- exports.array = _array.array;
19
- exports.nonEmptyArray = _array.nonEmptyArray;
20
- exports.poja = _array.poja;
21
-
22
- var _boolean = require("./stdlib/boolean");
23
-
24
- exports["boolean"] = _boolean["boolean"];
25
- exports.numericBoolean = _boolean.numericBoolean;
26
- exports.truthy = _boolean.truthy;
27
-
28
- var _constants = require("./stdlib/constants");
29
-
30
- exports.constant = _constants.constant;
31
- exports.hardcoded = _constants.hardcoded;
32
- exports.mixed = _constants.mixed;
33
- exports.null_ = _constants.null_;
34
- exports.undefined_ = _constants.undefined_;
35
- exports.unknown = _constants.unknown;
36
-
37
- var _date = require("./stdlib/date");
38
-
39
- exports.date = _date.date;
40
- exports.iso8601 = _date.iso8601;
41
-
42
- var _describe = require("./stdlib/describe");
43
-
44
- exports.describe = _describe.describe;
45
-
46
- var _dispatch = require("./stdlib/dispatch");
47
-
48
- exports.dispatch = _dispatch.dispatch;
49
-
50
- var _either = require("./stdlib/either");
51
-
52
- exports.either = _either.either;
53
- exports.either3 = _either.either3;
54
- exports.either4 = _either.either4;
55
- exports.either5 = _either.either5;
56
- exports.either6 = _either.either6;
57
- exports.either7 = _either.either7;
58
- exports.either8 = _either.either8;
59
- exports.either9 = _either.either9;
60
- exports.oneOf = _either.oneOf;
61
-
62
- var _fail = require("./stdlib/fail");
63
-
64
- exports.fail = _fail.fail;
65
-
66
- var _instanceOf = require("./stdlib/instanceOf");
67
-
68
- exports.instanceOf = _instanceOf.instanceOf;
69
-
70
- var _json = require("./stdlib/json");
71
-
72
- exports.json = _json.json;
73
- exports.jsonObject = _json.jsonObject;
74
- exports.jsonArray = _json.jsonArray;
75
-
76
- var _lazy = require("./stdlib/lazy");
77
-
78
- exports.lazy = _lazy.lazy;
79
-
80
- var _mapping = require("./stdlib/mapping");
81
-
82
- exports.mapping = _mapping.mapping;
83
- exports.dict = _mapping.dict;
84
-
85
- var _number = require("./stdlib/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("./stdlib/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("./stdlib/optional");
100
-
101
- exports.maybe = _optional.maybe;
102
- exports.nullable = _optional.nullable;
103
- exports.optional = _optional.optional;
104
-
105
- var _string = require("./stdlib/string");
106
-
107
- exports.email = _string.email;
108
- exports.nonEmptyString = _string.nonEmptyString;
109
- exports.regex = _string.regex;
110
- exports.string = _string.string;
111
- exports.url = _string.url;
112
-
113
- var _tuple = require("./stdlib/tuple");
114
-
115
- exports.tuple1 = _tuple.tuple1;
116
- exports.tuple2 = _tuple.tuple2;
117
- exports.tuple3 = _tuple.tuple3;
118
- exports.tuple4 = _tuple.tuple4;
119
- exports.tuple5 = _tuple.tuple5;
120
- exports.tuple6 = _tuple.tuple6;
package/cjs/index.js.flow DELETED
@@ -1,63 +0,0 @@
1
- // @flow strict
2
-
3
- /**
4
- * Elm-like JSON decoders, for use with Flow.
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 { Decoder, Guard } from './_types';
22
- export type { DecoderType, GuardType } from './_types';
23
-
24
- export type { JSONValue, JSONObject, JSONArray } from './stdlib/json';
25
-
26
- export { guard } from './_guard';
27
-
28
- export { compose, map, predicate } from './stdlib/composition';
29
-
30
- export { array, nonEmptyArray, poja } from './stdlib/array';
31
- export { boolean, numericBoolean, truthy } from './stdlib/boolean';
32
- export {
33
- constant,
34
- hardcoded,
35
- mixed,
36
- null_,
37
- undefined_,
38
- unknown,
39
- } from './stdlib/constants';
40
- export { date, iso8601 } from './stdlib/date';
41
- export { describe } from './stdlib/describe';
42
- export { dispatch } from './stdlib/dispatch';
43
- export {
44
- either,
45
- either3,
46
- either4,
47
- either5,
48
- either6,
49
- either7,
50
- either8,
51
- either9,
52
- oneOf,
53
- } from './stdlib/either';
54
- export { fail } from './stdlib/fail';
55
- export { instanceOf } from './stdlib/instanceOf';
56
- export { json, jsonObject, jsonArray } from './stdlib/json';
57
- export { lazy } from './stdlib/lazy';
58
- export { mapping, dict } from './stdlib/mapping';
59
- export { integer, number, positiveInteger, positiveNumber } from './stdlib/number';
60
- export { exact, inexact, object, pojo } from './stdlib/object';
61
- export { maybe, nullable, optional } from './stdlib/optional';
62
- export { email, nonEmptyString, regex, string, url } from './stdlib/string';
63
- export { tuple1, tuple2, tuple3, tuple4, tuple5, tuple6 } from './stdlib/tuple';