decoders 1.25.5 → 2.0.0-beta2

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 (151) hide show
  1. package/CHANGELOG.md +23 -3
  2. package/_esm/_guard.js +15 -0
  3. package/_esm/_guard.js.flow +20 -0
  4. package/_esm/_types.js +0 -0
  5. package/_esm/_types.js.flow +20 -0
  6. package/_esm/_utils.js +93 -0
  7. package/_esm/_utils.js.flow +97 -0
  8. package/_esm/annotate.js +144 -0
  9. package/_esm/annotate.js.flow +218 -0
  10. package/_esm/core/array.js +91 -0
  11. package/{array.js.flow → _esm/core/array.js.flow} +22 -25
  12. package/_esm/core/boolean.js +28 -0
  13. package/{boolean.js.flow → _esm/core/boolean.js.flow} +8 -7
  14. package/_esm/core/composition.js +42 -0
  15. package/{utils.js.flow → _esm/core/composition.js.flow} +7 -22
  16. package/_esm/core/constants.js +46 -0
  17. package/{constants.js.flow → _esm/core/constants.js.flow} +13 -12
  18. package/_esm/core/date.js +28 -0
  19. package/{date.js.flow → _esm/core/date.js.flow} +9 -7
  20. package/{describe.js → _esm/core/describe.js} +5 -11
  21. package/{describe.js.flow → _esm/core/describe.js.flow} +4 -4
  22. package/{dispatch.js → _esm/core/dispatch.js} +8 -15
  23. package/{dispatch.js.flow → _esm/core/dispatch.js.flow} +6 -5
  24. package/_esm/core/either.js +90 -0
  25. package/{either.js.flow → _esm/core/either.js.flow} +55 -35
  26. package/_esm/core/fail.js +11 -0
  27. package/_esm/core/fail.js.flow +12 -0
  28. package/_esm/core/instanceOf.js +8 -0
  29. package/{instanceOf.js.flow → _esm/core/instanceOf.js.flow} +7 -8
  30. package/_esm/core/json.js +15 -0
  31. package/{json.js.flow → _esm/core/json.js.flow} +4 -4
  32. package/_esm/core/lazy.js +11 -0
  33. package/{lazy.js.flow → _esm/core/lazy.js.flow} +1 -1
  34. package/_esm/core/mapping.js +54 -0
  35. package/_esm/core/mapping.js.flow +54 -0
  36. package/_esm/core/number.js +25 -0
  37. package/{number.js.flow → _esm/core/number.js.flow} +10 -11
  38. package/_esm/core/object.js +175 -0
  39. package/{object.js.flow → _esm/core/object.js.flow} +44 -52
  40. package/_esm/core/optional.js +38 -0
  41. package/{optional.js.flow → _esm/core/optional.js.flow} +6 -7
  42. package/{string.js → _esm/core/string.js} +18 -35
  43. package/{string.js.flow → _esm/core/string.js.flow} +13 -12
  44. package/_esm/core/tuple.js +155 -0
  45. package/{tuple.js.flow → _esm/core/tuple.js.flow} +62 -63
  46. package/_esm/format/index.js +2 -0
  47. package/_esm/format/index.js.flow +4 -0
  48. package/_esm/format/inline.js +137 -0
  49. package/_esm/format/inline.js.flow +122 -0
  50. package/_esm/format/short.js +4 -0
  51. package/_esm/format/short.js.flow +8 -0
  52. package/_esm/index.js +37 -0
  53. package/_esm/index.js.flow +56 -0
  54. package/_esm/result.js +139 -0
  55. package/_esm/result.js.flow +166 -0
  56. package/_guard.js +26 -0
  57. package/_guard.js.flow +20 -0
  58. package/_types.js +1 -0
  59. package/_types.js.flow +20 -0
  60. package/_utils.js +108 -0
  61. package/_utils.js.flow +97 -0
  62. package/annotate.js +161 -0
  63. package/annotate.js.flow +218 -0
  64. package/core/array.js +108 -0
  65. package/core/array.js.flow +103 -0
  66. package/core/boolean.js +44 -0
  67. package/core/boolean.js.flow +29 -0
  68. package/core/composition.js +56 -0
  69. package/core/composition.js.flow +43 -0
  70. package/core/constants.js +69 -0
  71. package/core/constants.js.flow +46 -0
  72. package/core/date.js +46 -0
  73. package/core/date.js.flow +40 -0
  74. package/core/describe.js +26 -0
  75. package/core/describe.js.flow +17 -0
  76. package/core/dispatch.js +62 -0
  77. package/core/dispatch.js.flow +58 -0
  78. package/core/either.js +117 -0
  79. package/core/either.js.flow +151 -0
  80. package/core/fail.js +21 -0
  81. package/core/fail.js.flow +12 -0
  82. package/core/instanceOf.js +19 -0
  83. package/core/instanceOf.js.flow +20 -0
  84. package/{json.js → core/json.js} +3 -5
  85. package/core/json.js.flow +28 -0
  86. package/{lazy.js → core/lazy.js} +1 -3
  87. package/core/lazy.js.flow +15 -0
  88. package/core/mapping.js +67 -0
  89. package/core/mapping.js.flow +54 -0
  90. package/core/number.js +40 -0
  91. package/core/number.js.flow +34 -0
  92. package/core/object.js +194 -0
  93. package/core/object.js.flow +203 -0
  94. package/core/optional.js +54 -0
  95. package/core/optional.js.flow +41 -0
  96. package/core/string.js +98 -0
  97. package/core/string.js.flow +82 -0
  98. package/core/tuple.js +173 -0
  99. package/core/tuple.js.flow +220 -0
  100. package/format/index.js +12 -0
  101. package/format/index.js.flow +4 -0
  102. package/format/inline.js +146 -0
  103. package/format/inline.js.flow +122 -0
  104. package/format/short.js +10 -0
  105. package/format/short.js.flow +8 -0
  106. package/index.js +118 -395
  107. package/index.js.flow +24 -24
  108. package/package.json +2 -6
  109. package/result.js +172 -0
  110. package/result.js.flow +166 -0
  111. package/array.d.ts +0 -5
  112. package/array.js +0 -133
  113. package/boolean.d.ts +0 -5
  114. package/boolean.js +0 -42
  115. package/constants.d.ts +0 -11
  116. package/constants.js +0 -67
  117. package/date.d.ts +0 -4
  118. package/date.js +0 -42
  119. package/describe.d.ts +0 -3
  120. package/dispatch.d.ts +0 -8
  121. package/either.d.ts +0 -61
  122. package/either.js +0 -85
  123. package/fail.d.ts +0 -3
  124. package/fail.js +0 -19
  125. package/fail.js.flow +0 -13
  126. package/guard.d.ts +0 -7
  127. package/guard.js +0 -30
  128. package/guard.js.flow +0 -36
  129. package/helpers.d.ts +0 -79
  130. package/index.d.ts +0 -38
  131. package/instanceOf.d.ts +0 -3
  132. package/instanceOf.js +0 -17
  133. package/json.d.ts +0 -11
  134. package/lazy.d.ts +0 -3
  135. package/mapping.d.ts +0 -4
  136. package/mapping.js +0 -113
  137. package/mapping.js.flow +0 -71
  138. package/number.d.ts +0 -6
  139. package/number.js +0 -38
  140. package/object.d.ts +0 -33
  141. package/object.js +0 -254
  142. package/optional.d.ts +0 -5
  143. package/optional.js +0 -52
  144. package/string.d.ts +0 -7
  145. package/tuple.d.ts +0 -30
  146. package/tuple.js +0 -199
  147. package/types.d.ts +0 -18
  148. package/types.js +0 -5
  149. package/types.js.flow +0 -26
  150. package/utils.d.ts +0 -13
  151. package/utils.js +0 -70
package/utils.js DELETED
@@ -1,70 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.compose = compose;
7
- exports.isDate = void 0;
8
- exports.map = map;
9
- exports.predicate = predicate;
10
-
11
- var _debrief = require("debrief");
12
-
13
- var _Result = require("lemons/Result");
14
-
15
- /**
16
- * `x instanceof Date` checks are unreliable across stack frames (that information
17
- * might get lost by the JS runtime), so we'll have to reside to more runtime
18
- * inspection checks.
19
- *
20
- * Taken from https://stackoverflow.com/a/44198641
21
- */
22
- var isDate = function isDate(value) {
23
- return value !== undefined && value !== null && // $FlowFixMe[method-unbinding]
24
- Object.prototype.toString.call(value) === '[object Date]' && !isNaN(value);
25
- };
26
- /**
27
- * Given a decoder T and a mapping function from T's to V's, returns a decoder
28
- * for V's. This is useful to change the original input data.
29
- */
30
-
31
-
32
- exports.isDate = isDate;
33
-
34
- function map(decoder, mapper) {
35
- return compose(decoder, function (x) {
36
- try {
37
- return (0, _Result.Ok)(mapper(x));
38
- } catch (e) {
39
- return (0, _Result.Err)((0, _debrief.annotate)(x, e instanceof Error ? e.message : String(e)));
40
- }
41
- });
42
- }
43
- /**
44
- * Compose two decoders by passing the result of the first into the second.
45
- * The second decoder may assume as its input type the output type of the first
46
- * decoder (so it's not necessary to accept the typical "mixed"). This is
47
- * useful for "narrowing down" the checks. For example, if you want to write
48
- * a decoder for positive numbers, you can compose it from an existing decoder
49
- * for any number, and a decoder that, assuming a number, checks if it's
50
- * positive. Very often combined with the predicate() helper as the second
51
- * argument.
52
- */
53
-
54
-
55
- function compose(decoder, next) {
56
- return function (blob) {
57
- return decoder(blob).andThen(next);
58
- };
59
- }
60
- /**
61
- * Factory function returning a Decoder<T>, given a predicate function that
62
- * accepts/rejects the input of type T.
63
- */
64
-
65
-
66
- function predicate(predicate, msg) {
67
- return function (value) {
68
- return predicate(value) ? (0, _Result.Ok)(value) : (0, _Result.Err)((0, _debrief.annotate)(value, msg));
69
- };
70
- }