decoders 2.0.0-beta1 → 2.0.0-beta5

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 (136) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/{es → _esm}/_guard.js +0 -0
  3. package/{cjs → _esm}/_guard.js.flow +0 -0
  4. package/{es → _esm}/_types.js +0 -0
  5. package/{cjs → _esm}/_types.js.flow +0 -0
  6. package/{es → _esm}/_utils.js +0 -0
  7. package/{cjs → _esm}/_utils.js.flow +0 -0
  8. package/{es → _esm}/annotate.js +0 -0
  9. package/{cjs → _esm}/annotate.js.flow +0 -0
  10. package/{es/stdlib → _esm/core}/array.js +0 -0
  11. package/{cjs/stdlib → _esm/core}/array.js.flow +0 -0
  12. package/{es/stdlib → _esm/core}/boolean.js +0 -0
  13. package/{cjs/stdlib → _esm/core}/boolean.js.flow +0 -0
  14. package/{es/stdlib → _esm/core}/composition.js +0 -0
  15. package/{cjs/stdlib → _esm/core}/composition.js.flow +0 -0
  16. package/{es/stdlib → _esm/core}/constants.js +0 -0
  17. package/{cjs/stdlib → _esm/core}/constants.js.flow +0 -0
  18. package/{es/stdlib → _esm/core}/date.js +0 -0
  19. package/{cjs/stdlib → _esm/core}/date.js.flow +0 -0
  20. package/{es/stdlib → _esm/core}/describe.js +0 -0
  21. package/{cjs/stdlib → _esm/core}/describe.js.flow +0 -0
  22. package/{es/stdlib → _esm/core}/dispatch.js +0 -0
  23. package/{cjs/stdlib → _esm/core}/dispatch.js.flow +0 -0
  24. package/{es/stdlib → _esm/core}/either.js +0 -0
  25. package/{cjs/stdlib → _esm/core}/either.js.flow +0 -0
  26. package/{es/stdlib → _esm/core}/fail.js +0 -0
  27. package/{cjs/stdlib → _esm/core}/fail.js.flow +0 -0
  28. package/{es/stdlib → _esm/core}/instanceOf.js +0 -0
  29. package/{cjs/stdlib → _esm/core}/instanceOf.js.flow +0 -0
  30. package/{es/stdlib → _esm/core}/json.js +0 -0
  31. package/{cjs/stdlib → _esm/core}/json.js.flow +0 -0
  32. package/{es/stdlib → _esm/core}/lazy.js +0 -0
  33. package/{cjs/stdlib → _esm/core}/lazy.js.flow +0 -0
  34. package/{es/stdlib → _esm/core}/mapping.js +0 -0
  35. package/{cjs/stdlib → _esm/core}/mapping.js.flow +0 -0
  36. package/{es/stdlib → _esm/core}/number.js +0 -0
  37. package/{cjs/stdlib → _esm/core}/number.js.flow +0 -0
  38. package/{es/stdlib → _esm/core}/object.js +0 -0
  39. package/{cjs/stdlib → _esm/core}/object.js.flow +0 -0
  40. package/{es/stdlib → _esm/core}/optional.js +0 -0
  41. package/{cjs/stdlib → _esm/core}/optional.js.flow +0 -0
  42. package/{es/stdlib → _esm/core}/string.js +0 -0
  43. package/{cjs/stdlib → _esm/core}/string.js.flow +0 -0
  44. package/{es/stdlib → _esm/core}/tuple.js +7 -7
  45. package/{cjs/stdlib → _esm/core}/tuple.js.flow +21 -26
  46. package/{es → _esm}/format/index.js +0 -0
  47. package/{cjs → _esm}/format/index.js.flow +0 -0
  48. package/{es → _esm}/format/inline.js +0 -0
  49. package/{cjs → _esm}/format/inline.js.flow +0 -0
  50. package/{es → _esm}/format/short.js +0 -0
  51. package/{cjs → _esm}/format/short.js.flow +0 -0
  52. package/{es → _esm}/index.js +18 -18
  53. package/{cjs → _esm}/index.js.flow +29 -29
  54. package/{es → _esm}/result.js +14 -5
  55. package/{cjs → _esm}/result.js.flow +14 -6
  56. package/{cjs/_guard.js → _guard.js} +0 -0
  57. package/_guard.js.flow +20 -0
  58. package/{cjs/_types.js → _types.js} +0 -0
  59. package/_types.js.flow +20 -0
  60. package/{cjs/_utils.js → _utils.js} +0 -0
  61. package/_utils.js.flow +97 -0
  62. package/{cjs/annotate.js → annotate.js} +0 -0
  63. package/annotate.js.flow +218 -0
  64. package/{cjs/stdlib → core}/array.js +0 -0
  65. package/core/array.js.flow +103 -0
  66. package/{cjs/stdlib → core}/boolean.js +0 -0
  67. package/core/boolean.js.flow +29 -0
  68. package/{cjs/stdlib → core}/composition.js +0 -0
  69. package/core/composition.js.flow +43 -0
  70. package/{cjs/stdlib → core}/constants.js +0 -0
  71. package/core/constants.js.flow +46 -0
  72. package/{cjs/stdlib → core}/date.js +0 -0
  73. package/core/date.js.flow +40 -0
  74. package/{cjs/stdlib → core}/describe.js +0 -0
  75. package/core/describe.js.flow +17 -0
  76. package/{cjs/stdlib → core}/dispatch.js +0 -0
  77. package/core/dispatch.js.flow +58 -0
  78. package/{cjs/stdlib → core}/either.js +0 -0
  79. package/core/either.js.flow +151 -0
  80. package/{cjs/stdlib → core}/fail.js +0 -0
  81. package/core/fail.js.flow +12 -0
  82. package/{cjs/stdlib → core}/instanceOf.js +0 -0
  83. package/core/instanceOf.js.flow +20 -0
  84. package/{cjs/stdlib → core}/json.js +0 -0
  85. package/core/json.js.flow +28 -0
  86. package/{cjs/stdlib → core}/lazy.js +0 -0
  87. package/core/lazy.js.flow +15 -0
  88. package/{cjs/stdlib → core}/mapping.js +0 -0
  89. package/core/mapping.js.flow +54 -0
  90. package/{cjs/stdlib → core}/number.js +0 -0
  91. package/core/number.js.flow +34 -0
  92. package/{cjs/stdlib → core}/object.js +0 -0
  93. package/core/object.js.flow +203 -0
  94. package/{cjs/stdlib → core}/optional.js +0 -0
  95. package/core/optional.js.flow +41 -0
  96. package/{cjs/stdlib → core}/string.js +0 -0
  97. package/core/string.js.flow +82 -0
  98. package/{cjs/stdlib → core}/tuple.js +6 -6
  99. package/core/tuple.js.flow +215 -0
  100. package/{cjs/format → format}/index.js +0 -0
  101. package/format/index.js.flow +4 -0
  102. package/{cjs/format → format}/inline.js +0 -0
  103. package/format/inline.js.flow +122 -0
  104. package/{cjs/format → format}/short.js +0 -0
  105. package/format/short.js.flow +8 -0
  106. package/{cjs/index.js → index.js} +18 -18
  107. package/index.js.flow +63 -0
  108. package/package.json +3 -12
  109. package/{cjs/result.js → result.js} +18 -7
  110. package/result.js.flow +174 -0
  111. package/ts/_guard.d.ts +0 -7
  112. package/ts/_helpers.d.ts +0 -79
  113. package/ts/_types.d.ts +0 -16
  114. package/ts/_utils.d.ts +0 -13
  115. package/ts/annotate.d.ts +0 -58
  116. package/ts/array.d.ts +0 -5
  117. package/ts/boolean.d.ts +0 -5
  118. package/ts/constants.d.ts +0 -11
  119. package/ts/date.d.ts +0 -4
  120. package/ts/describe.d.ts +0 -3
  121. package/ts/dispatch.d.ts +0 -8
  122. package/ts/either.d.ts +0 -61
  123. package/ts/fail.d.ts +0 -3
  124. package/ts/index.d.ts +0 -42
  125. package/ts/inline.d.ts +0 -3
  126. package/ts/instanceOf.d.ts +0 -3
  127. package/ts/json.d.ts +0 -11
  128. package/ts/lazy.d.ts +0 -3
  129. package/ts/mapping.d.ts +0 -4
  130. package/ts/number.d.ts +0 -6
  131. package/ts/object.d.ts +0 -33
  132. package/ts/optional.d.ts +0 -5
  133. package/ts/result.d.ts +0 -39
  134. package/ts/short.d.ts +0 -3
  135. package/ts/string.d.ts +0 -7
  136. package/ts/tuple.d.ts +0 -30
@@ -8,13 +8,14 @@ exports.errValue = errValue;
8
8
  exports.expect = expect;
9
9
  exports.isErr = isErr;
10
10
  exports.isOk = isOk;
11
- exports.map = map;
12
11
  exports.mapError = mapError;
12
+ exports.mapOk = mapOk;
13
13
  exports.ok = ok;
14
+ exports.okOrErrValue = okOrErrValue;
15
+ exports.okValue = okValue;
14
16
  exports.orElse = orElse;
15
17
  exports.toString = toString;
16
18
  exports.unwrap = unwrap;
17
- exports.value = value;
18
19
  exports.withDefault = withDefault;
19
20
 
20
21
  /**
@@ -29,7 +30,8 @@ exports.withDefault = withDefault;
29
30
  function ok(value) {
30
31
  return {
31
32
  type: 'ok',
32
- value: value
33
+ value: value,
34
+ error: undefined
33
35
  };
34
36
  }
35
37
  /**
@@ -40,6 +42,7 @@ function ok(value) {
40
42
  function err(error) {
41
43
  return {
42
44
  type: 'err',
45
+ value: undefined,
43
46
  error: error
44
47
  };
45
48
  }
@@ -58,15 +61,23 @@ function isErr(result) {
58
61
 
59
62
  function withDefault(result, defaultValue) {
60
63
  return result.type === 'ok' ? result.value : defaultValue;
61
- }
64
+ } // TODO: Remove this from the public API? The same can be achieved now with
65
+ // TODO: const { value } = result;
66
+
62
67
 
63
- function value(result) {
68
+ function okValue(result) {
64
69
  return result.type === 'ok' ? result.value : undefined;
65
- }
70
+ } // TODO: Remove this from the public API? The same can be achieved now with
71
+ // TODO: const { error } = result;
72
+
66
73
 
67
74
  function errValue(result) {
68
75
  return result.type === 'err' ? result.error : undefined;
69
76
  }
77
+
78
+ function okOrErrValue(result) {
79
+ return result.type === 'ok' ? result.value : result.error;
80
+ }
70
81
  /**
71
82
  * Unwrap the value from this Result instance if this is an "Ok" result.
72
83
  * Otherwise, will throw the "Err" error via a runtime exception.
@@ -159,7 +170,7 @@ function orElse(result1, lazyResult2) {
159
170
  */
160
171
 
161
172
 
162
- function map(result, mapper) {
173
+ function mapOk(result, mapper) {
163
174
  return result.type === 'ok' ? ok(mapper(result.value)) : result;
164
175
  }
165
176
  /**
package/result.js.flow ADDED
@@ -0,0 +1,174 @@
1
+ // @flow strict
2
+
3
+ /**
4
+ * Result <value> <error>
5
+ * = Ok <value>
6
+ * | Err <error>
7
+ */
8
+
9
+ type Ok<+T> = {| +type: 'ok', +value: T, +error: void |};
10
+ type Err<+E> = {| +type: 'err', +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 { type: 'ok', 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 { type: 'err', value: undefined, error };
26
+ }
27
+
28
+ export function toString(result: Result<mixed, mixed>): string {
29
+ return result.type === 'ok'
30
+ ? `Ok(${String(result.value)})`
31
+ : `Err(${String(result.error)})`;
32
+ }
33
+
34
+ export function isOk(result: Result<mixed, mixed>): boolean {
35
+ return result.type === 'ok';
36
+ }
37
+
38
+ export function isErr(result: Result<mixed, mixed>): boolean {
39
+ return result.type === 'err';
40
+ }
41
+
42
+ export function withDefault<T>(result: Result<T, mixed>, defaultValue: T): T {
43
+ return result.type === 'ok' ? result.value : defaultValue;
44
+ }
45
+
46
+ // TODO: Remove this from the public API? The same can be achieved now with
47
+ // TODO: const { value } = result;
48
+ export function okValue<T>(result: Result<T, mixed>): void | T {
49
+ return result.type === 'ok' ? result.value : undefined;
50
+ }
51
+
52
+ // TODO: Remove this from the public API? The same can be achieved now with
53
+ // TODO: const { error } = result;
54
+ export function errValue<E>(result: Result<mixed, E>): void | E {
55
+ return result.type === 'err' ? result.error : undefined;
56
+ }
57
+
58
+ export function okOrErrValue<T, E>(result: Result<T, E>): T | E {
59
+ return result.type === 'ok' ? result.value : result.error;
60
+ }
61
+
62
+ /**
63
+ * Unwrap the value from this Result instance if this is an "Ok" result.
64
+ * Otherwise, will throw the "Err" error via a runtime exception.
65
+ */
66
+ export function unwrap<T>(result: Result<T, mixed>): T {
67
+ if (result.type === 'ok') {
68
+ return result.value;
69
+ } else {
70
+ throw result.error;
71
+ }
72
+ }
73
+
74
+ export function expect<T>(result: Result<T, mixed>, message: string | Error): T {
75
+ if (result.type === 'ok') {
76
+ return result.value;
77
+ } else {
78
+ throw message instanceof Error ? message : new Error(message);
79
+ }
80
+ }
81
+
82
+ export function dispatch<T, E, O>(
83
+ result: Result<T, E>,
84
+ okCallback: (value: T) => O,
85
+ errCallback: (error: E) => O,
86
+ ): O {
87
+ return result.type === 'ok' ? okCallback(result.value) : errCallback(result.error);
88
+ }
89
+
90
+ /**
91
+ * If the given result is OK, defers to the other result. Otherwise returns the
92
+ * error result.
93
+ *
94
+ * It's like saying A && B, but on Result.
95
+ *
96
+ * Examples:
97
+ *
98
+ * Result.ok(42) && Result.ok('hi') // => Ok('hi')
99
+ * Result.err('boo') && Result.ok('hi') // => Err('boo')
100
+ * Result.ok(42) && Result.err('boo') // => Err('boo')
101
+ * Result.err('boo') && Result.err('boo') // => Err('boo')
102
+ *
103
+ */
104
+ // export function and<T, E, T2>(
105
+ // result1: Result<T, E>,
106
+ // result2: Result<T2, E>,
107
+ // ): Result<T2, E> {
108
+ // return result1.type === 'ok' ? result2 : result1;
109
+ // }
110
+
111
+ /**
112
+ * If the given result is OK, return that result. Otherwise, defers to the
113
+ * other result.
114
+ *
115
+ * It's like saying A || B, but on Result.
116
+ *
117
+ * Examples:
118
+ *
119
+ * Result.ok(42) || Result.ok('hi') // => Ok(42)
120
+ * Result.err('boo') || Result.ok('hi') // => Ok('hi')
121
+ * Result.ok(42) || Result.err('boo') // => Ok(42)
122
+ * Result.err('bleh') || Result.err('boo') // => Err('boo')
123
+ *
124
+ */
125
+ // export function or<T, E, E2>(
126
+ // result1: Result<T, E>,
127
+ // result2: Result<T, E2>,
128
+ // ): Result<T, E2> {
129
+ // return result1.type === 'ok' ? result1 : result2;
130
+ // }
131
+
132
+ /**
133
+ * Like .and(), aka &&, but the second argument gets evaluated lazily only if
134
+ * the first result is an Ok result. If so, it has access to the Ok value from
135
+ * the first argument.
136
+ */
137
+ export function andThen<T, E, T2>(
138
+ result1: Result<T, E>,
139
+ lazyResult2: (value: T) => Result<T2, E>,
140
+ ): Result<T2, E> {
141
+ return result1.type === 'ok' ? lazyResult2(result1.value) : result1;
142
+ }
143
+
144
+ /**
145
+ * Like .or(), aka ||, but the second argument gets evaluated lazily only if
146
+ * the first result is an Err result. If so, it has access to the Err value
147
+ * from the first argument.
148
+ */
149
+ export function orElse<T, E, E2>(
150
+ result1: Result<T, E>,
151
+ lazyResult2: (errValue: E) => Result<T, E2>,
152
+ ): Result<T, E2> {
153
+ return result1.type === 'ok' ? result1 : lazyResult2(result1.error);
154
+ }
155
+
156
+ /**
157
+ * Transform an Ok result. Will not touch Err results.
158
+ */
159
+ export function mapOk<T, E, T2>(
160
+ result: Result<T, E>,
161
+ mapper: (value: T) => T2,
162
+ ): Result<T2, E> {
163
+ return result.type === 'ok' ? ok(mapper(result.value)) : result;
164
+ }
165
+
166
+ /**
167
+ * Transform an Err value. Will not touch Ok results.
168
+ */
169
+ export function mapError<T, E, E2>(
170
+ result: Result<T, E>,
171
+ mapper: (error: E) => E2,
172
+ ): Result<T, E2> {
173
+ return result.type === 'ok' ? result : err(mapper(result.error));
174
+ }
package/ts/_guard.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import { Annotation } from './annotate';
2
- import { Decoder, Guard } from './_types';
3
-
4
- export function guard<T>(
5
- decoder: Decoder<T>,
6
- formatter?: (annotation: Annotation) => string,
7
- ): Guard<T>;
package/ts/_helpers.d.ts DELETED
@@ -1,79 +0,0 @@
1
- /**
2
- * Given a type like:
3
- *
4
- * {
5
- * a: string;
6
- * b: number | undefined;
7
- * c: null | undefined;
8
- * d: null;
9
- * e: undefined;
10
- * }
11
- *
12
- * Will drop all the "undefined" types. In this case, only "e":
13
- *
14
- * {
15
- * a: string;
16
- * b: number | undefined;
17
- * c: null | undefined;
18
- * d: null;
19
- * }
20
- *
21
- */
22
- type Compact<T> = { [K in IsDefined<T, keyof T>]: T[K] };
23
-
24
- type IsDefined<T, K extends keyof T> = K extends any
25
- ? T[K] extends undefined
26
- ? never
27
- : K
28
- : never;
29
-
30
- //
31
- // HACK:
32
- // These weird conditionals test whether TypeScript is configured with the
33
- // `strictNullChecks` compiler option. We use these definitions to influence
34
- // what's considered a "required" vs an "optional" key for the AllowImplicit
35
- // type.
36
- //
37
- // If strictNullChecks is false, then we should not be emitting any `?` fields
38
- // and consider all fields "required" because everything is optional by default
39
- // in that mode anyway.
40
- //
41
- type NoStrictNullChecks = undefined extends string ? 1 : undefined;
42
- // ^^^^^^^^^^^^^^^^^^^^^^^^
43
- type StrictNullChecks = undefined extends string ? undefined : 1;
44
- // ^^^^^^^^^^^^^^^^^^^^^^^^
45
-
46
- export type RequiredKeys<T> = keyof Compact<{
47
- [K in keyof T]: undefined extends T[K] ? NoStrictNullChecks : 1;
48
- }>;
49
-
50
- export type OptionalKeys<T> = keyof Compact<{
51
- [K in keyof T]: undefined extends T[K] ? 1 : StrictNullChecks;
52
- }>;
53
-
54
- /**
55
- * Transforms an object type, by marking all fields that contain "undefined"
56
- * with a question mark, i.e. allowing implicit-undefineds when
57
- * explicit-undefined are also allowed.
58
- *
59
- * For example, if:
60
- *
61
- * type User = {
62
- * name: string;
63
- * age: number | null | undefined;
64
- * }
65
- *
66
- * Then AllowImplicit<User> will become equivalent to:
67
- *
68
- * {
69
- * name: string;
70
- * age?: number | null;
71
- * ^
72
- * Note the question mark
73
- * }
74
- */
75
- type AllowImplicit<T> = { [K in RequiredKeys<T>]-?: T[K] } & {
76
- [K in OptionalKeys<T>]+?: Exclude<T[K], undefined>;
77
- };
78
-
79
- export { AllowImplicit };
package/ts/_types.d.ts DELETED
@@ -1,16 +0,0 @@
1
- import { Annotation } from './annotate';
2
- import { Result } from './result';
3
-
4
- export type Scalar = string | number | boolean | symbol | undefined | null;
5
-
6
- export interface Guard<T> {
7
- (blob: unknown): T;
8
- }
9
- export type Predicate<T> = (value: T) => boolean;
10
- export type DecodeResult<T> = Result<T, Annotation>;
11
- export interface Decoder<T, F = unknown> {
12
- (blob: F): DecodeResult<T>;
13
- }
14
-
15
- export type DecoderType<T> = T extends Decoder<infer V> ? V : never;
16
- export type GuardType<T> = T extends Guard<infer V> ? V : never;
package/ts/_utils.d.ts DELETED
@@ -1,13 +0,0 @@
1
- import { Decoder } from './_types';
2
-
3
- export function isDate(value: unknown): boolean;
4
- export function map<T, V>(decoder: Decoder<T>, mapper: (value: T) => V): Decoder<V>;
5
- export function compose<T, V>(decoder: Decoder<T>, next: Decoder<V, T>): Decoder<V>;
6
- export function predicate<T extends F, F = unknown>(
7
- predicate: (value: F) => value is T,
8
- msg: string,
9
- ): Decoder<T, F>;
10
- export function predicate<T>(
11
- predicate: (value: T) => boolean,
12
- msg: string,
13
- ): Decoder<T, T>;
package/ts/annotate.d.ts DELETED
@@ -1,58 +0,0 @@
1
- export interface ObjectAnnotation {
2
- type: 'object';
3
- fields: { [key: string]: Annotation };
4
- text?: string;
5
- }
6
-
7
- export interface ArrayAnnotation {
8
- type: 'array';
9
- items: readonly Annotation[];
10
- text?: string;
11
- }
12
-
13
- export interface ScalarAnnotation {
14
- type: 'scalar';
15
- value: unknown;
16
- text?: string;
17
- }
18
-
19
- export interface FunctionAnnotation {
20
- type: 'function';
21
- text?: string;
22
- }
23
-
24
- export interface CircularRefAnnotation {
25
- type: 'circular-ref';
26
- text?: string;
27
- }
28
-
29
- export type Annotation =
30
- | ObjectAnnotation
31
- | ArrayAnnotation
32
- | ScalarAnnotation
33
- | FunctionAnnotation
34
- | CircularRefAnnotation;
35
-
36
- export function object(
37
- fields: { [key: string]: Annotation },
38
- text?: string,
39
- ): ObjectAnnotation;
40
- export function array(items: readonly Annotation[], text?: string): ArrayAnnotation;
41
- export function func(text?: string): FunctionAnnotation;
42
- export function scalar(value: unknown, text?: string): ScalarAnnotation;
43
- export function circularRef(text?: string): CircularRefAnnotation;
44
-
45
- export function updateText<A extends Annotation>(annotation: A, text?: string): A;
46
-
47
- export function merge(
48
- objAnnotation: ObjectAnnotation,
49
- fields: { [key: string]: Annotation },
50
- ): ObjectAnnotation;
51
-
52
- export function asAnnotation(thing: unknown): Annotation | void;
53
-
54
- export function annotate(value: unknown, text?: string): Annotation;
55
- export function annotateObject(
56
- obj: { [key: string]: unknown },
57
- text?: string,
58
- ): ObjectAnnotation;
package/ts/array.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import { Decoder } from '../_types';
2
-
3
- export const poja: Decoder<unknown[]>;
4
- export function array<T>(decoder: Decoder<T>): Decoder<T[]>;
5
- export function nonEmptyArray<T>(decoder: Decoder<T>): Decoder<[T, ...T[]]>;
package/ts/boolean.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import { Decoder } from '../_types';
2
-
3
- export const boolean: Decoder<boolean>;
4
- export const truthy: Decoder<boolean>;
5
- export const numericBoolean: Decoder<boolean>;
package/ts/constants.d.ts DELETED
@@ -1,11 +0,0 @@
1
- import { Decoder, Scalar } from '../_types';
2
-
3
- // Constants
4
-
5
- export const null_: Decoder<null>;
6
- export const undefined_: Decoder<undefined>;
7
- export function constant<T extends Scalar>(value: T): Decoder<T>;
8
- export function hardcoded<T extends Scalar>(value: T): Decoder<T>;
9
- export function hardcoded<T>(value: T): Decoder<T>;
10
- export const mixed: Decoder<unknown>;
11
- export const unknown: Decoder<unknown>;
package/ts/date.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import { Decoder } from '../_types';
2
-
3
- export const date: Decoder<Date>;
4
- export const iso8601: Decoder<Date>;
package/ts/describe.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { Decoder } from '../_types';
2
-
3
- export function describe<T>(decoder: Decoder<T>, msg: string): Decoder<T>;
package/ts/dispatch.d.ts DELETED
@@ -1,8 +0,0 @@
1
- import { Decoder, DecoderType } from '../_types';
2
-
3
- export type $Values<T extends object> = T[keyof T];
4
-
5
- export function dispatch<O extends { [key: string]: Decoder<any> }>(
6
- field: string,
7
- mapping: O,
8
- ): Decoder<$Values<{ [key in keyof O]: DecoderType<O[key]> }>>;
package/ts/either.d.ts DELETED
@@ -1,61 +0,0 @@
1
- import { Decoder, Scalar } from '../_types';
2
-
3
- export function either<T1, T2>(d1: Decoder<T1>, d2: Decoder<T2>): Decoder<T1 | T2>;
4
- export function either2<T1, T2>(d1: Decoder<T1>, d2: Decoder<T2>): Decoder<T1 | T2>;
5
- export function either3<T1, T2, T3>(
6
- d1: Decoder<T1>,
7
- d2: Decoder<T2>,
8
- d3: Decoder<T3>,
9
- ): Decoder<T1 | T2 | T3>;
10
- export function either4<T1, T2, T3, T4>(
11
- d1: Decoder<T1>,
12
- d2: Decoder<T2>,
13
- d3: Decoder<T3>,
14
- d4: Decoder<T4>,
15
- ): Decoder<T1 | T2 | T3 | T4>;
16
- export function either5<T1, T2, T3, T4, T5>(
17
- d1: Decoder<T1>,
18
- d2: Decoder<T2>,
19
- d3: Decoder<T3>,
20
- d4: Decoder<T4>,
21
- d5: Decoder<T5>,
22
- ): Decoder<T1 | T2 | T3 | T4 | T5>;
23
- export function either6<T1, T2, T3, T4, T5, T6>(
24
- d1: Decoder<T1>,
25
- d2: Decoder<T2>,
26
- d3: Decoder<T3>,
27
- d4: Decoder<T4>,
28
- d5: Decoder<T5>,
29
- d6: Decoder<T6>,
30
- ): Decoder<T1 | T2 | T3 | T4 | T5 | T6>;
31
- export function either7<T1, T2, T3, T4, T5, T6, T7>(
32
- d1: Decoder<T1>,
33
- d2: Decoder<T2>,
34
- d3: Decoder<T3>,
35
- d4: Decoder<T4>,
36
- d5: Decoder<T5>,
37
- d6: Decoder<T6>,
38
- d7: Decoder<T7>,
39
- ): Decoder<T1 | T2 | T3 | T4 | T5 | T6 | T7>;
40
- export function either8<T1, T2, T3, T4, T5, T6, T7, T8>(
41
- d1: Decoder<T1>,
42
- d2: Decoder<T2>,
43
- d3: Decoder<T3>,
44
- d4: Decoder<T4>,
45
- d5: Decoder<T5>,
46
- d6: Decoder<T6>,
47
- d7: Decoder<T7>,
48
- d8: Decoder<T8>,
49
- ): Decoder<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8>;
50
- export function either9<T1, T2, T3, T4, T5, T6, T7, T8, T9>(
51
- d1: Decoder<T1>,
52
- d2: Decoder<T2>,
53
- d3: Decoder<T3>,
54
- d4: Decoder<T4>,
55
- d5: Decoder<T5>,
56
- d6: Decoder<T6>,
57
- d7: Decoder<T7>,
58
- d8: Decoder<T8>,
59
- d9: Decoder<T9>,
60
- ): Decoder<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9>;
61
- export function oneOf<T extends Scalar>(constants: readonly T[]): Decoder<T>;
package/ts/fail.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { Decoder } from '../_types';
2
-
3
- export function fail(msg: string): Decoder<never>;
package/ts/index.d.ts DELETED
@@ -1,42 +0,0 @@
1
- export { Decoder, Guard } from './_types';
2
- export { DecoderType, GuardType } from './_types';
3
-
4
- export { guard } from './_guard';
5
- export { compose, map, predicate } from './_utils';
6
-
7
- export { JSONArray, JSONObject, JSONValue } from './stdlib/json';
8
-
9
- export { array, nonEmptyArray, poja } from './stdlib/array';
10
- export { boolean, numericBoolean, truthy } from './stdlib/boolean';
11
- export {
12
- constant,
13
- hardcoded,
14
- mixed,
15
- null_,
16
- undefined_,
17
- unknown,
18
- } from './stdlib/constants';
19
- export { date, iso8601 } from './stdlib/date';
20
- export { describe } from './stdlib/describe';
21
- export { dispatch } from './stdlib/dispatch';
22
- export {
23
- either,
24
- either3,
25
- either4,
26
- either5,
27
- either6,
28
- either7,
29
- either8,
30
- either9,
31
- oneOf,
32
- } from './stdlib/either';
33
- export { fail } from './stdlib/fail';
34
- export { instanceOf } from './stdlib/instanceOf';
35
- export { json, jsonArray, jsonObject } from './stdlib/json';
36
- export { lazy } from './stdlib/lazy';
37
- export { mapping, dict } from './stdlib/mapping';
38
- export { integer, number, positiveInteger, positiveNumber } from './stdlib/number';
39
- export { exact, inexact, object, pojo } from './stdlib/object';
40
- export { maybe, nullable, optional } from './stdlib/optional';
41
- export { email, nonEmptyString, regex, string, url } from './stdlib/string';
42
- export { tuple1, tuple2, tuple3, tuple4, tuple5, tuple6 } from './stdlib/tuple';
package/ts/inline.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { Annotation } from '../annotate';
2
-
3
- export function formatInline(ann: Annotation): string;
@@ -1,3 +0,0 @@
1
- import { Decoder } from '../_types';
2
-
3
- export function instanceOf<T>(klass: new (...args: any) => T): Decoder<T>;
package/ts/json.d.ts DELETED
@@ -1,11 +0,0 @@
1
- import { Decoder } from '../_types';
2
-
3
- export type JSONValue = null | string | number | boolean | JSONObject | JSONArray;
4
- export interface JSONObject {
5
- [key: string]: JSONValue;
6
- }
7
- export type JSONArray = JSONValue[];
8
-
9
- export const json: Decoder<JSONValue>;
10
- export const jsonArray: Decoder<JSONArray>;
11
- export const jsonObject: Decoder<JSONObject>;
package/ts/lazy.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { Decoder } from '../_types';
2
-
3
- export function lazy<T>(decoderFn: () => Decoder<T>): Decoder<T>;
package/ts/mapping.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import { Decoder } from '../_types';
2
-
3
- export function mapping<T>(decoder: Decoder<T>): Decoder<Map<string, T>>;
4
- export function dict<T>(decoder: Decoder<T>): Decoder<{ [key: string]: T }>;
package/ts/number.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import { Decoder } from '../_types';
2
-
3
- export const integer: Decoder<number>;
4
- export const number: Decoder<number>;
5
- export const positiveInteger: Decoder<number>;
6
- export const positiveNumber: Decoder<number>;
package/ts/object.d.ts DELETED
@@ -1,33 +0,0 @@
1
- import { Decoder, DecoderType } from '../_types';
2
- import { AllowImplicit } from './_helpers';
3
-
4
- export type ObjectDecoderType<T> = AllowImplicit<{
5
- [key in keyof T]: DecoderType<T[key]>;
6
- }>;
7
-
8
- export const pojo: Decoder<{ [key: string]: unknown }>;
9
-
10
- export function object<O extends { [key: string]: Decoder<any> }>(
11
- mapping: O,
12
- ): Decoder<{ [K in keyof ObjectDecoderType<O>]: ObjectDecoderType<O>[K] }>;
13
- // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14
- // This is basically just equivalent to:
15
- // ObjectDecoderType<O>
16
- //
17
- // But by "resolving" this with a mapped type, we remove the helper
18
- // type names from the inferred type here, making this much easier to
19
- // work with while developing.
20
-
21
- export function exact<O extends { [key: string]: Decoder<any> }>(
22
- mapping: O,
23
- ): Decoder<{ [K in keyof ObjectDecoderType<O>]: ObjectDecoderType<O>[K] }>;
24
- // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25
- // Ditto (see above)
26
-
27
- export function inexact<O extends { [key: string]: Decoder<any> }>(
28
- mapping: O,
29
- ): Decoder<
30
- { [K in keyof ObjectDecoderType<O>]: ObjectDecoderType<O>[K] } & {
31
- [extra: string]: unknown;
32
- }
33
- >;
package/ts/optional.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import { Decoder } from '../_types';
2
-
3
- export function optional<T>(decoder: Decoder<T>): Decoder<T | undefined>;
4
- export function nullable<T>(decoder: Decoder<T>): Decoder<T | null>;
5
- export function maybe<T>(decoder: Decoder<T>): Decoder<T | null | undefined>;