decoders 2.0.0-beta4 → 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.
package/_esm/result.js CHANGED
@@ -10,7 +10,8 @@
10
10
  export function ok(value) {
11
11
  return {
12
12
  type: 'ok',
13
- value: value
13
+ value: value,
14
+ error: undefined
14
15
  };
15
16
  }
16
17
  /**
@@ -20,6 +21,7 @@ export function ok(value) {
20
21
  export function err(error) {
21
22
  return {
22
23
  type: 'err',
24
+ value: undefined,
23
25
  error: error
24
26
  };
25
27
  }
@@ -34,10 +36,14 @@ export function isErr(result) {
34
36
  }
35
37
  export function withDefault(result, defaultValue) {
36
38
  return result.type === 'ok' ? result.value : defaultValue;
37
- }
39
+ } // TODO: Remove this from the public API? The same can be achieved now with
40
+ // TODO: const { value } = result;
41
+
38
42
  export function okValue(result) {
39
43
  return result.type === 'ok' ? result.value : undefined;
40
- }
44
+ } // TODO: Remove this from the public API? The same can be achieved now with
45
+ // TODO: const { error } = result;
46
+
41
47
  export function errValue(result) {
42
48
  return result.type === 'err' ? result.error : undefined;
43
49
  }
@@ -6,8 +6,8 @@
6
6
  * | Err <error>
7
7
  */
8
8
 
9
- type Ok<+T> = {| +type: 'ok', +value: T |};
10
- type Err<+E> = {| +type: 'err', +error: E |};
9
+ type Ok<+T> = {| +type: 'ok', +value: T, +error: void |};
10
+ type Err<+E> = {| +type: 'err', +value: void, +error: E |};
11
11
 
12
12
  export type Result<+T, +E> = Ok<T> | Err<E>;
13
13
 
@@ -15,14 +15,14 @@ export type Result<+T, +E> = Ok<T> | Err<E>;
15
15
  * Create a new Result instance representing a successful computation.
16
16
  */
17
17
  export function ok<T>(value: T): Ok<T> {
18
- return { type: 'ok', value };
18
+ return { type: 'ok', value, error: undefined };
19
19
  }
20
20
 
21
21
  /**
22
22
  * Create a new Result instance representing a failed computation.
23
23
  */
24
24
  export function err<E>(error: E): Err<E> {
25
- return { type: 'err', error };
25
+ return { type: 'err', value: undefined, error };
26
26
  }
27
27
 
28
28
  export function toString(result: Result<mixed, mixed>): string {
@@ -43,10 +43,14 @@ export function withDefault<T>(result: Result<T, mixed>, defaultValue: T): T {
43
43
  return result.type === 'ok' ? result.value : defaultValue;
44
44
  }
45
45
 
46
+ // TODO: Remove this from the public API? The same can be achieved now with
47
+ // TODO: const { value } = result;
46
48
  export function okValue<T>(result: Result<T, mixed>): void | T {
47
49
  return result.type === 'ok' ? result.value : undefined;
48
50
  }
49
51
 
52
+ // TODO: Remove this from the public API? The same can be achieved now with
53
+ // TODO: const { error } = result;
50
54
  export function errValue<E>(result: Result<mixed, E>): void | E {
51
55
  return result.type === 'err' ? result.error : undefined;
52
56
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "decoders",
3
- "version": "2.0.0-beta4",
3
+ "version": "2.0.0-beta5",
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": {
package/result.js CHANGED
@@ -30,7 +30,8 @@ exports.withDefault = withDefault;
30
30
  function ok(value) {
31
31
  return {
32
32
  type: 'ok',
33
- value: value
33
+ value: value,
34
+ error: undefined
34
35
  };
35
36
  }
36
37
  /**
@@ -41,6 +42,7 @@ function ok(value) {
41
42
  function err(error) {
42
43
  return {
43
44
  type: 'err',
45
+ value: undefined,
44
46
  error: error
45
47
  };
46
48
  }
@@ -59,11 +61,15 @@ function isErr(result) {
59
61
 
60
62
  function withDefault(result, defaultValue) {
61
63
  return result.type === 'ok' ? result.value : defaultValue;
62
- }
64
+ } // TODO: Remove this from the public API? The same can be achieved now with
65
+ // TODO: const { value } = result;
66
+
63
67
 
64
68
  function okValue(result) {
65
69
  return result.type === 'ok' ? result.value : undefined;
66
- }
70
+ } // TODO: Remove this from the public API? The same can be achieved now with
71
+ // TODO: const { error } = result;
72
+
67
73
 
68
74
  function errValue(result) {
69
75
  return result.type === 'err' ? result.error : undefined;
package/result.js.flow CHANGED
@@ -6,8 +6,8 @@
6
6
  * | Err <error>
7
7
  */
8
8
 
9
- type Ok<+T> = {| +type: 'ok', +value: T |};
10
- type Err<+E> = {| +type: 'err', +error: E |};
9
+ type Ok<+T> = {| +type: 'ok', +value: T, +error: void |};
10
+ type Err<+E> = {| +type: 'err', +value: void, +error: E |};
11
11
 
12
12
  export type Result<+T, +E> = Ok<T> | Err<E>;
13
13
 
@@ -15,14 +15,14 @@ export type Result<+T, +E> = Ok<T> | Err<E>;
15
15
  * Create a new Result instance representing a successful computation.
16
16
  */
17
17
  export function ok<T>(value: T): Ok<T> {
18
- return { type: 'ok', value };
18
+ return { type: 'ok', value, error: undefined };
19
19
  }
20
20
 
21
21
  /**
22
22
  * Create a new Result instance representing a failed computation.
23
23
  */
24
24
  export function err<E>(error: E): Err<E> {
25
- return { type: 'err', error };
25
+ return { type: 'err', value: undefined, error };
26
26
  }
27
27
 
28
28
  export function toString(result: Result<mixed, mixed>): string {
@@ -43,10 +43,14 @@ export function withDefault<T>(result: Result<T, mixed>, defaultValue: T): T {
43
43
  return result.type === 'ok' ? result.value : defaultValue;
44
44
  }
45
45
 
46
+ // TODO: Remove this from the public API? The same can be achieved now with
47
+ // TODO: const { value } = result;
46
48
  export function okValue<T>(result: Result<T, mixed>): void | T {
47
49
  return result.type === 'ok' ? result.value : undefined;
48
50
  }
49
51
 
52
+ // TODO: Remove this from the public API? The same can be achieved now with
53
+ // TODO: const { error } = result;
50
54
  export function errValue<E>(result: Result<mixed, E>): void | E {
51
55
  return result.type === 'err' ? result.error : undefined;
52
56
  }