decoders 2.0.0-beta12 → 2.0.0-beta13

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/lib/unions.mjs CHANGED
@@ -83,8 +83,8 @@ function _either() {
83
83
 
84
84
  export var either = _either;
85
85
  /**
86
- * Accepts any value that is strictly-equal (using ===) to one of the specified
87
- * values.
86
+ * Accepts any value that is strictly-equal (using `===`) to one of the
87
+ * specified values.
88
88
  */
89
89
 
90
90
  export function oneOf(constants) {
@@ -111,11 +111,13 @@ export function oneOf(constants) {
111
111
  * unions](https://en.wikipedia.org/wiki/Tagged_union), i.e. a union of
112
112
  * objects where one field is used as the discriminator.
113
113
  *
114
- * const A = object({ tag: constant('A'), foo: string });
115
- * const B = object({ tag: constant('B'), bar: number });
114
+ * ```ts
115
+ * const A = object({ tag: constant('A'), foo: string });
116
+ * const B = object({ tag: constant('B'), bar: number });
116
117
  *
117
- * const AorB = taggedUnion('tag', { A, B });
118
- * // ^^^
118
+ * const AorB = taggedUnion('tag', { A, B });
119
+ * // ^^^
120
+ * ```
119
121
  *
120
122
  * Decoding now works in two steps:
121
123
  *
@@ -141,5 +143,4 @@ export function taggedUnion(field, mapping) {
141
143
  var decoder = mapping[key];
142
144
  return decoder.decode(blob);
143
145
  });
144
- }
145
- export var dispatch = taggedUnion;
146
+ }
@@ -1,10 +1,34 @@
1
1
  import { Decoder } from '../Decoder';
2
2
 
3
+ /**
4
+ * Accepts any value that is an ``instanceof`` the given class.
5
+ */
3
6
  export function instanceOf<T>(klass: new (...args: readonly any[]) => T): Decoder<T>;
7
+
8
+ /**
9
+ * Lazily evaluate the given decoder. This is useful to build self-referential
10
+ * types for recursive data structures.
11
+ */
4
12
  export function lazy<T>(decoderFn: () => Decoder<T>): Decoder<T>;
13
+
14
+ /**
15
+ * Pre-process the data input before passing it into the decoder. This gives
16
+ * you the ability to arbitrarily customize the input on the fly before passing
17
+ * it to the decoder. Of course, the input value at that point is still of
18
+ * ``unknown`` type, so you will have to deal with that accordingly.
19
+ */
5
20
  export function prep<T>(
6
21
  mapperFn: (blob: unknown) => unknown,
7
22
  decoder: Decoder<T>,
8
23
  ): Decoder<T>;
24
+
25
+ /**
26
+ * Rejects all inputs, and always fails with the given error message. May be
27
+ * useful for explicitly disallowing keys, or for testing purposes.
28
+ */
9
29
  export function never(msg: string): Decoder<never>;
30
+
31
+ /**
32
+ * Alias of never().
33
+ */
10
34
  export function fail(msg: string): Decoder<never>;
package/lib/utilities.js CHANGED
@@ -23,25 +23,6 @@ function instanceOf(klass) {
23
23
  /**
24
24
  * Lazily evaluate the given decoder. This is useful to build self-referential
25
25
  * types for recursive data structures.
26
- *
27
- * Example:
28
- *
29
- * ```ts
30
- * type Tree = {
31
- * value: string;
32
- * children: Array<Tree>;
33
- * // ^^^^
34
- * // Self-reference defining a recursive type
35
- * };
36
- *
37
- * const treeDecoder: Decoder<Tree> = object({
38
- * value: string,
39
- * children: array(lazy(() => treeDecoder)),
40
- * // ^^^^^^^^^^^^^^^^^^^^^^^
41
- * // Use lazy() like this to refer to the treeDecoder which is
42
- * // getting defined here
43
- * });
44
- * ```
45
26
  */
46
27
 
47
28
 
@@ -23,25 +23,6 @@ export function instanceOf<T>(klass: Class<T>): Decoder<T> {
23
23
  /**
24
24
  * Lazily evaluate the given decoder. This is useful to build self-referential
25
25
  * types for recursive data structures.
26
- *
27
- * Example:
28
- *
29
- * ```ts
30
- * type Tree = {
31
- * value: string;
32
- * children: Array<Tree>;
33
- * // ^^^^
34
- * // Self-reference defining a recursive type
35
- * };
36
- *
37
- * const treeDecoder: Decoder<Tree> = object({
38
- * value: string,
39
- * children: array(lazy(() => treeDecoder)),
40
- * // ^^^^^^^^^^^^^^^^^^^^^^^
41
- * // Use lazy() like this to refer to the treeDecoder which is
42
- * // getting defined here
43
- * });
44
- * ```
45
26
  */
46
27
  export function lazy<T>(decoderFn: () => Decoder<T>): Decoder<T> {
47
28
  return define((blob) => decoderFn().decode(blob));
package/lib/utilities.mjs CHANGED
@@ -13,25 +13,6 @@ export function instanceOf(klass) {
13
13
  /**
14
14
  * Lazily evaluate the given decoder. This is useful to build self-referential
15
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
16
  */
36
17
 
37
18
  export function lazy(decoderFn) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "decoders",
3
- "version": "2.0.0-beta12",
3
+ "version": "2.0.0-beta13",
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": {