@fgv/ts-utils 1.9.4 → 2.0.1-alpha.0

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 (211) hide show
  1. package/CHANGELOG.json +26 -0
  2. package/CHANGELOG.md +14 -0
  3. package/dist/ts-utils.d.ts +3007 -0
  4. package/dist/tsdoc-metadata.json +11 -0
  5. package/lib/index.d.ts +12 -0
  6. package/lib/index.d.ts.map +1 -0
  7. package/lib/index.js +68 -0
  8. package/lib/index.js.map +1 -0
  9. package/lib/packlets/base/brand.d.ts.map +1 -0
  10. package/lib/packlets/base/brand.js +24 -0
  11. package/lib/packlets/base/brand.js.map +1 -0
  12. package/lib/packlets/base/index.d.ts +7 -0
  13. package/lib/packlets/base/index.d.ts.map +1 -0
  14. package/lib/packlets/base/index.js +58 -0
  15. package/lib/packlets/base/index.js.map +1 -0
  16. package/{logger.d.ts → lib/packlets/base/logger.d.ts} +16 -1
  17. package/lib/packlets/base/logger.d.ts.map +1 -0
  18. package/lib/packlets/base/logger.js +128 -0
  19. package/lib/packlets/base/logger.js.map +1 -0
  20. package/{normalize.d.ts → lib/packlets/base/normalize.d.ts} +6 -0
  21. package/lib/packlets/base/normalize.d.ts.map +1 -0
  22. package/lib/packlets/base/normalize.js +139 -0
  23. package/lib/packlets/base/normalize.js.map +1 -0
  24. package/{result.d.ts → lib/packlets/base/result.d.ts} +16 -15
  25. package/lib/packlets/base/result.d.ts.map +1 -0
  26. package/lib/packlets/base/result.js +571 -0
  27. package/lib/packlets/base/result.js.map +1 -0
  28. package/lib/packlets/base/utils.d.ts.map +1 -0
  29. package/lib/packlets/base/utils.js +200 -0
  30. package/lib/packlets/base/utils.js.map +1 -0
  31. package/{converter.d.ts → lib/packlets/conversion/converter.d.ts} +11 -12
  32. package/lib/packlets/conversion/converter.d.ts.map +1 -0
  33. package/lib/packlets/conversion/converter.js +218 -0
  34. package/lib/packlets/conversion/converter.js.map +1 -0
  35. package/{converters.d.ts → lib/packlets/conversion/converters.d.ts} +52 -216
  36. package/lib/packlets/conversion/converters.d.ts.map +1 -0
  37. package/lib/packlets/conversion/converters.js +739 -0
  38. package/lib/packlets/conversion/converters.js.map +1 -0
  39. package/lib/packlets/conversion/index.d.ts +6 -0
  40. package/lib/packlets/conversion/index.d.ts.map +1 -0
  41. package/lib/packlets/conversion/index.js +56 -0
  42. package/lib/packlets/conversion/index.js.map +1 -0
  43. package/lib/packlets/conversion/objectConverter.d.ts +94 -0
  44. package/lib/packlets/conversion/objectConverter.d.ts.map +1 -0
  45. package/lib/packlets/conversion/objectConverter.js +110 -0
  46. package/lib/packlets/conversion/objectConverter.js.map +1 -0
  47. package/lib/packlets/conversion/stringConverter.d.ts +78 -0
  48. package/lib/packlets/conversion/stringConverter.d.ts.map +1 -0
  49. package/lib/packlets/conversion/stringConverter.js +97 -0
  50. package/lib/packlets/conversion/stringConverter.js.map +1 -0
  51. package/{csvHelpers.d.ts → lib/packlets/csv/csvHelpers.d.ts} +1 -1
  52. package/lib/packlets/csv/csvHelpers.d.ts.map +1 -0
  53. package/lib/packlets/csv/csvHelpers.js +69 -0
  54. package/lib/packlets/csv/csvHelpers.js.map +1 -0
  55. package/lib/packlets/csv/index.d.ts +2 -0
  56. package/lib/packlets/csv/index.d.ts.map +1 -0
  57. package/lib/packlets/csv/index.js +39 -0
  58. package/lib/packlets/csv/index.js.map +1 -0
  59. package/{extendedArray.d.ts → lib/packlets/experimental/extendedArray.d.ts} +7 -7
  60. package/lib/packlets/experimental/extendedArray.d.ts.map +1 -0
  61. package/lib/packlets/experimental/extendedArray.js +106 -0
  62. package/lib/packlets/experimental/extendedArray.js.map +1 -0
  63. package/{formatter.d.ts → lib/packlets/experimental/formatter.d.ts} +6 -6
  64. package/lib/packlets/experimental/formatter.d.ts.map +1 -0
  65. package/lib/packlets/experimental/formatter.js +75 -0
  66. package/lib/packlets/experimental/formatter.js.map +1 -0
  67. package/lib/packlets/experimental/index.d.ts +4 -0
  68. package/lib/packlets/experimental/index.d.ts.map +1 -0
  69. package/lib/packlets/experimental/index.js +41 -0
  70. package/lib/packlets/experimental/index.js.map +1 -0
  71. package/{rangeOf.d.ts → lib/packlets/experimental/rangeOf.d.ts} +21 -24
  72. package/lib/packlets/experimental/rangeOf.d.ts.map +1 -0
  73. package/lib/packlets/experimental/rangeOf.js +185 -0
  74. package/lib/packlets/experimental/rangeOf.js.map +1 -0
  75. package/{hash.d.ts → lib/packlets/hash/hash.d.ts} +1 -1
  76. package/lib/packlets/hash/hash.d.ts.map +1 -0
  77. package/lib/packlets/hash/hash.js +168 -0
  78. package/lib/packlets/hash/hash.js.map +1 -0
  79. package/lib/packlets/hash/index.d.ts +2 -0
  80. package/lib/packlets/hash/index.d.ts.map +1 -0
  81. package/lib/packlets/hash/index.js +39 -0
  82. package/lib/packlets/hash/index.js.map +1 -0
  83. package/lib/packlets/record-jar/index.d.ts +2 -0
  84. package/lib/packlets/record-jar/index.d.ts.map +1 -0
  85. package/lib/packlets/record-jar/index.js +39 -0
  86. package/lib/packlets/record-jar/index.js.map +1 -0
  87. package/{recordJarHelpers.d.ts → lib/packlets/record-jar/recordJarHelpers.d.ts} +1 -1
  88. package/lib/packlets/record-jar/recordJarHelpers.d.ts.map +1 -0
  89. package/lib/packlets/record-jar/recordJarHelpers.js +263 -0
  90. package/lib/packlets/record-jar/recordJarHelpers.js.map +1 -0
  91. package/{validation → lib/packlets/validation}/array.d.ts +2 -2
  92. package/lib/packlets/validation/array.d.ts.map +1 -0
  93. package/lib/packlets/validation/array.js +67 -0
  94. package/lib/packlets/validation/array.js.map +1 -0
  95. package/{validation → lib/packlets/validation}/boolean.d.ts +1 -1
  96. package/lib/packlets/validation/boolean.d.ts.map +1 -0
  97. package/lib/packlets/validation/boolean.js +56 -0
  98. package/lib/packlets/validation/boolean.js.map +1 -0
  99. package/lib/packlets/validation/classes.d.ts.map +1 -0
  100. package/lib/packlets/validation/classes.js +38 -0
  101. package/lib/packlets/validation/classes.js.map +1 -0
  102. package/lib/packlets/validation/common.d.ts.map +1 -0
  103. package/lib/packlets/validation/common.js +24 -0
  104. package/lib/packlets/validation/common.js.map +1 -0
  105. package/{validation → lib/packlets/validation}/field.d.ts +1 -1
  106. package/lib/packlets/validation/field.d.ts.map +1 -0
  107. package/lib/packlets/validation/field.js +71 -0
  108. package/lib/packlets/validation/field.js.map +1 -0
  109. package/{validation → lib/packlets/validation}/genericValidator.d.ts +2 -3
  110. package/lib/packlets/validation/genericValidator.d.ts.map +1 -0
  111. package/lib/packlets/validation/genericValidator.js +137 -0
  112. package/lib/packlets/validation/genericValidator.js.map +1 -0
  113. package/lib/packlets/validation/index.d.ts.map +1 -0
  114. package/{validation → lib/packlets/validation}/index.js +1 -1
  115. package/lib/packlets/validation/index.js.map +1 -0
  116. package/{validation → lib/packlets/validation}/number.d.ts +1 -1
  117. package/lib/packlets/validation/number.d.ts.map +1 -0
  118. package/lib/packlets/validation/number.js +54 -0
  119. package/lib/packlets/validation/number.js.map +1 -0
  120. package/{validation → lib/packlets/validation}/object.d.ts +1 -1
  121. package/lib/packlets/validation/object.d.ts.map +1 -0
  122. package/lib/packlets/validation/object.js +139 -0
  123. package/lib/packlets/validation/object.js.map +1 -0
  124. package/{validation → lib/packlets/validation}/string.d.ts +1 -1
  125. package/lib/packlets/validation/string.d.ts.map +1 -0
  126. package/lib/packlets/validation/string.js +54 -0
  127. package/lib/packlets/validation/string.js.map +1 -0
  128. package/lib/packlets/validation/traits.d.ts.map +1 -0
  129. package/lib/packlets/validation/traits.js +58 -0
  130. package/lib/packlets/validation/traits.js.map +1 -0
  131. package/{validation → lib/packlets/validation}/typeGuard.d.ts +1 -1
  132. package/lib/packlets/validation/typeGuard.d.ts.map +1 -0
  133. package/lib/packlets/validation/typeGuard.js +62 -0
  134. package/lib/packlets/validation/typeGuard.js.map +1 -0
  135. package/{validation → lib/packlets/validation}/validator.d.ts +15 -16
  136. package/lib/packlets/validation/validator.d.ts.map +1 -0
  137. package/lib/packlets/validation/validator.js +24 -0
  138. package/lib/packlets/validation/validator.js.map +1 -0
  139. package/{validation → lib/packlets/validation}/validatorBase.d.ts +1 -1
  140. package/lib/packlets/validation/validatorBase.d.ts.map +1 -0
  141. package/lib/packlets/validation/validatorBase.js +41 -0
  142. package/lib/packlets/validation/validatorBase.js.map +1 -0
  143. package/{validation → lib/packlets/validation}/validators.d.ts +3 -6
  144. package/lib/packlets/validation/validators.d.ts.map +1 -0
  145. package/lib/packlets/validation/validators.js +121 -0
  146. package/lib/packlets/validation/validators.js.map +1 -0
  147. package/package.json +21 -20
  148. package/brand.d.ts.map +0 -1
  149. package/brand.js +0 -24
  150. package/converter.d.ts.map +0 -1
  151. package/converter.js +0 -222
  152. package/converters.d.ts.map +0 -1
  153. package/converters.js +0 -896
  154. package/csvHelpers.d.ts.map +0 -1
  155. package/csvHelpers.js +0 -69
  156. package/extendedArray.d.ts.map +0 -1
  157. package/extendedArray.js +0 -106
  158. package/formatter.d.ts.map +0 -1
  159. package/formatter.js +0 -75
  160. package/hash.d.ts.map +0 -1
  161. package/hash.js +0 -168
  162. package/index.d.ts +0 -15
  163. package/index.d.ts.map +0 -1
  164. package/index.js +0 -70
  165. package/logger.d.ts.map +0 -1
  166. package/logger.js +0 -115
  167. package/normalize.d.ts.map +0 -1
  168. package/normalize.js +0 -139
  169. package/rangeOf.d.ts.map +0 -1
  170. package/rangeOf.js +0 -185
  171. package/recordJarHelpers.d.ts.map +0 -1
  172. package/recordJarHelpers.js +0 -262
  173. package/result.d.ts.map +0 -1
  174. package/result.js +0 -569
  175. package/utils.d.ts.map +0 -1
  176. package/utils.js +0 -200
  177. package/validation/array.d.ts.map +0 -1
  178. package/validation/array.js +0 -67
  179. package/validation/boolean.d.ts.map +0 -1
  180. package/validation/boolean.js +0 -59
  181. package/validation/classes.d.ts.map +0 -1
  182. package/validation/classes.js +0 -38
  183. package/validation/common.d.ts.map +0 -1
  184. package/validation/common.js +0 -24
  185. package/validation/field.d.ts.map +0 -1
  186. package/validation/field.js +0 -72
  187. package/validation/genericValidator.d.ts.map +0 -1
  188. package/validation/genericValidator.js +0 -138
  189. package/validation/index.d.ts.map +0 -1
  190. package/validation/number.d.ts.map +0 -1
  191. package/validation/number.js +0 -57
  192. package/validation/object.d.ts.map +0 -1
  193. package/validation/object.js +0 -143
  194. package/validation/string.d.ts.map +0 -1
  195. package/validation/string.js +0 -57
  196. package/validation/traits.d.ts.map +0 -1
  197. package/validation/traits.js +0 -58
  198. package/validation/typeGuard.d.ts.map +0 -1
  199. package/validation/typeGuard.js +0 -62
  200. package/validation/validator.d.ts.map +0 -1
  201. package/validation/validator.js +0 -24
  202. package/validation/validatorBase.d.ts.map +0 -1
  203. package/validation/validatorBase.js +0 -44
  204. package/validation/validators.d.ts.map +0 -1
  205. package/validation/validators.js +0 -119
  206. /package/{brand.d.ts → lib/packlets/base/brand.d.ts} +0 -0
  207. /package/{utils.d.ts → lib/packlets/base/utils.d.ts} +0 -0
  208. /package/{validation → lib/packlets/validation}/classes.d.ts +0 -0
  209. /package/{validation → lib/packlets/validation}/common.d.ts +0 -0
  210. /package/{validation → lib/packlets/validation}/index.d.ts +0 -0
  211. /package/{validation → lib/packlets/validation}/traits.d.ts +0 -0
@@ -0,0 +1,739 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2020 Erik Fortune
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in all
13
+ * copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+ var __importDefault = (this && this.__importDefault) || function (mod) {
24
+ return (mod && mod.__esModule) ? mod : { "default": mod };
25
+ };
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.rangeOf = exports.rangeTypeOf = exports.transformObject = exports.transform = exports.discriminatedObject = exports.strictObject = exports.object = exports.optionalField = exports.field = exports.optionalElement = exports.element = exports.validateWith = exports.mapOf = exports.recordOf = exports.numberArray = exports.stringArray = exports.extendedArrayOf = exports.arrayOf = exports.oneOf = exports.optionalBoolean = exports.optionalNumber = exports.isA = exports.validated = exports.isoDate = exports.delimitedString = exports.optionalString = exports.boolean = exports.number = exports.value = exports.literal = exports.mappedEnumeratedValue = exports.enumeratedValue = exports.templateString = exports.string = void 0;
28
+ const base_1 = require("../base");
29
+ const experimental_1 = require("../experimental");
30
+ const converter_1 = require("./converter");
31
+ const objectConverter_1 = require("./objectConverter");
32
+ const stringConverter_1 = require("./stringConverter");
33
+ const luxon_1 = require("luxon");
34
+ const mustache_1 = __importDefault(require("mustache"));
35
+ /**
36
+ * A converter to convert unknown to string. Values of type
37
+ * string succeed. Anything else fails.
38
+ * @public
39
+ */
40
+ exports.string = new stringConverter_1.StringConverter();
41
+ /**
42
+ * Helper function to create a {@link Conversion.StringConverter | StringConverter} which converts
43
+ * `unknown` to `string`, applying template conversions supplied at construction time or at
44
+ * runtime as context.
45
+ * @remarks
46
+ * Template conversions are applied using `mustache` syntax.
47
+ * @param defaultContext - Optional default context to use for template values.
48
+ * @returns A new {@link Converter} returning `string`.
49
+ * @public
50
+ */
51
+ function templateString(defaultContext) {
52
+ return new stringConverter_1.StringConverter(defaultContext, undefined, (from, __self, context) => {
53
+ if (typeof from !== 'string') {
54
+ return (0, base_1.fail)(`Not a string: ${JSON.stringify(from)}`);
55
+ }
56
+ return (0, base_1.captureResult)(() => mustache_1.default.render(from, context));
57
+ });
58
+ }
59
+ exports.templateString = templateString;
60
+ /**
61
+ * Helper function to create a {@link Converter} which converts `unknown` to one of a set of supplied
62
+ * enumerated values. Anything else fails.
63
+ *
64
+ * @remarks
65
+ * Allowed enumerated values can also be supplied as context at conversion time.
66
+ * @param values - Array of allowed values.
67
+ * @returns A new {@link Converter} returning `<T>`.
68
+ * @public
69
+ */
70
+ function enumeratedValue(values) {
71
+ return new converter_1.BaseConverter((from, __self, context) => {
72
+ const v = context !== null && context !== void 0 ? context : values;
73
+ const index = v.indexOf(from);
74
+ return index >= 0 ? (0, base_1.succeed)(v[index]) : (0, base_1.fail)(`Invalid enumerated value ${JSON.stringify(from)}`);
75
+ });
76
+ }
77
+ exports.enumeratedValue = enumeratedValue;
78
+ /**
79
+ * Helper function to create a {@link Converter} which converts `unknown` to one of a set of supplied enumerated
80
+ * values, mapping any of multiple supplied values to the enumeration.
81
+ * @remarks
82
+ * Enables mapping of multiple input values to a consistent internal representation (so e.g. `'y'`, `'yes'`,
83
+ * `'true'`, `1` and `true` can all map to boolean `true`)
84
+ * @param map - An array of tuples describing the mapping. The first element of each tuple is the result
85
+ * value, the second is the set of values that map to the result. Tuples are evaluated in the order
86
+ * supplied and are not checked for duplicates.
87
+ * @param message - An optional error message.
88
+ * @returns A {@link Converter} which applies the mapping and yields `<T>` on success.
89
+ * @public
90
+ */
91
+ function mappedEnumeratedValue(map, message) {
92
+ return new converter_1.BaseConverter((from, __self, __context) => {
93
+ for (const item of map) {
94
+ if (item[1].includes(from)) {
95
+ return (0, base_1.succeed)(item[0]);
96
+ }
97
+ }
98
+ return (0, base_1.fail)(message
99
+ ? `${JSON.stringify(from)}: ${message}`
100
+ : `Cannot map '${JSON.stringify(from)}' to a supported value`);
101
+ });
102
+ }
103
+ exports.mappedEnumeratedValue = mappedEnumeratedValue;
104
+ /**
105
+ * Helper function to create a {@link Converter} which converts `unknown` to some supplied literal value. Succeeds with
106
+ * the supplied value if an identity comparison succeeds, fails otherwise.
107
+ * @param value - The value to be compared.
108
+ * @returns A {@link Converter} which returns the supplied value on success.
109
+ * @public
110
+ */
111
+ function literal(value) {
112
+ return new converter_1.BaseConverter((from, __self, __context) => {
113
+ return from === value
114
+ ? (0, base_1.succeed)(value)
115
+ : (0, base_1.fail)(`${JSON.stringify(from)}: does not match ${JSON.stringify(value)}`);
116
+ });
117
+ }
118
+ exports.literal = literal;
119
+ /**
120
+ * Deprecated alias for @see literal
121
+ * @param value - The value to be compared.
122
+ * @deprecated Use {@link Converters.literal} instead.
123
+ * @internal
124
+ */
125
+ // eslint-disable-next-line @rushstack/typedef-var
126
+ exports.value = literal;
127
+ /**
128
+ * A {@link Converter} which converts `unknown` to a `number`.
129
+ * @remarks
130
+ * Numbers and strings with a numeric format succeed. Anything else fails.
131
+ * @public
132
+ */
133
+ exports.number = new converter_1.BaseConverter((from) => {
134
+ if (typeof from !== 'number') {
135
+ const num = typeof from === 'string' ? Number(from) : NaN;
136
+ return isNaN(num) ? (0, base_1.fail)(`Not a number: ${JSON.stringify(from)}`) : (0, base_1.succeed)(num);
137
+ }
138
+ return (0, base_1.succeed)(from);
139
+ });
140
+ /**
141
+ * A {@link Converter} which converts `unknown` to `boolean`.
142
+ * @remarks
143
+ * Boolean values or the case-insensitive strings `'true'` and `'false'` succeed.
144
+ * Anything else fails.
145
+ * @public
146
+ */
147
+ exports.boolean = new converter_1.BaseConverter((from) => {
148
+ if (typeof from === 'boolean') {
149
+ return (0, base_1.succeed)(from);
150
+ }
151
+ else if (typeof from === 'string') {
152
+ switch (from.toLowerCase()) {
153
+ case 'true':
154
+ return (0, base_1.succeed)(true);
155
+ case 'false':
156
+ return (0, base_1.succeed)(false);
157
+ }
158
+ }
159
+ return (0, base_1.fail)(`Not a boolean: ${JSON.stringify(from)}`);
160
+ });
161
+ /**
162
+ * A {@link Converter} which converts an optional `string` value. Values of type
163
+ * `string` are returned. Anything else returns {@link Success} with value `undefined`.
164
+ * @public
165
+ */
166
+ exports.optionalString = exports.string.optional();
167
+ /**
168
+ * Helper function to create a {@link Converter} which converts any `string` into an
169
+ * array of `string`, by separating at a supplied delimiter.
170
+ * @remarks
171
+ * Delimiter may also be supplied as context at conversion time.
172
+ * @param delimiter - The delimiter at which to split.
173
+ * @returns A new {@link Converter} returning `string[]`.
174
+ * @public
175
+ */
176
+ function delimitedString(delimiter, options = 'filtered') {
177
+ return new converter_1.BaseConverter((from, __self, context) => {
178
+ const result = exports.string.convert(from);
179
+ if (result.isSuccess()) {
180
+ let strings = result.value.split(context !== null && context !== void 0 ? context : delimiter);
181
+ if (options !== 'all') {
182
+ strings = strings.filter((s) => s.trim().length > 0);
183
+ }
184
+ return (0, base_1.succeed)(strings);
185
+ }
186
+ return (0, base_1.fail)(result.message);
187
+ });
188
+ }
189
+ exports.delimitedString = delimitedString;
190
+ /**
191
+ * A {@link Converter} which converts an iso formatted string, a number or a `Date` object to
192
+ * a `Date` object.
193
+ * @public
194
+ */
195
+ exports.isoDate = new converter_1.BaseConverter((from) => {
196
+ if (typeof from === 'string') {
197
+ const dt = luxon_1.DateTime.fromISO(from);
198
+ if (dt.isValid) {
199
+ return (0, base_1.succeed)(dt.toJSDate());
200
+ }
201
+ return (0, base_1.fail)(`Invalid date: ${dt.invalidExplanation}`);
202
+ }
203
+ else if (typeof from === 'number') {
204
+ return (0, base_1.succeed)(new Date(from));
205
+ }
206
+ else if (from instanceof Date) {
207
+ return (0, base_1.succeed)(from);
208
+ }
209
+ return (0, base_1.fail)(`Cannot convert ${JSON.stringify(from)} to Date`);
210
+ });
211
+ /**
212
+ * Helper function to create a {@link Converter} from any {@link Validation.Validator}
213
+ * @param validator - the validator to be wrapped
214
+ * @returns A {@link Converter} which uses the supplied validator.
215
+ * @public
216
+ */
217
+ function validated(validator) {
218
+ return new converter_1.BaseConverter((from, __self, context) => {
219
+ return validator.validate(from, context);
220
+ });
221
+ }
222
+ exports.validated = validated;
223
+ /**
224
+ * Helper function to create a {@link Converter} from a supplied type guard function.
225
+ * @param description - a description of the thing to be validated for use in error messages
226
+ * @param guard - a {@link Validation.TypeGuardWithContext} which performs the validation.
227
+ * @returns A new {@link Converter} which validates the values using the supplied type guard
228
+ * and returns them in place.
229
+ * @public
230
+ */
231
+ function isA(description, guard) {
232
+ return new converter_1.BaseConverter((from, __self, context) => {
233
+ if (guard(from, context)) {
234
+ return (0, base_1.succeed)(from);
235
+ }
236
+ return (0, base_1.fail)(`invalid ${description} (${JSON.stringify(from)})`);
237
+ });
238
+ }
239
+ exports.isA = isA;
240
+ /**
241
+ * A {@link Converter} which converts an optional `number` value.
242
+ * @remarks
243
+ * Values of type `number` or numeric strings are converted and returned.
244
+ * Anything else returns {@link Success} with value `undefined`.
245
+ * @public
246
+ */
247
+ exports.optionalNumber = exports.number.optional();
248
+ /**
249
+ * A {@link Converter} to convert an optional `boolean` value.
250
+ * @remarks
251
+ * Values of type `boolean` or strings that match (case-insensitive) `'true'`
252
+ * or `'false'` are converted and returned. Anything else returns {@link Success}
253
+ * with value `undefined`.
254
+ * @public
255
+ */
256
+ exports.optionalBoolean = exports.boolean.optional();
257
+ /**
258
+ * A helper function to create a {@link Converter} for polymorphic values. Returns a
259
+ * converter which Invokes the wrapped converters in sequence, returning the first successful
260
+ * result. Returns an error if none of the supplied converters can convert the value.
261
+ * @remarks
262
+ * If `onError` is `ignoreErrors` (default), then errors from any of the
263
+ * converters are ignored provided that some converter succeeds. If
264
+ * onError is `failOnError`, then an error from any converter fails the entire
265
+ * conversion.
266
+ *
267
+ * @param converters - An ordered list of {@link Converter | converters} to be considered.
268
+ * @param onError - Specifies treatment of unconvertible elements.
269
+ * @returns A new {@link Converter} which yields a value from the union of the types returned
270
+ * by the wrapped converters.
271
+ * @public
272
+ */
273
+ function oneOf(converters, onError = 'ignoreErrors') {
274
+ return new converter_1.BaseConverter((from, __self, context) => {
275
+ const errors = [];
276
+ for (const converter of converters) {
277
+ const result = converter.convert(from, context);
278
+ if (result.isSuccess() && result.value !== undefined) {
279
+ return result;
280
+ }
281
+ if (result.isFailure()) {
282
+ if (onError === 'failOnError') {
283
+ return result;
284
+ }
285
+ errors.push(result.message);
286
+ }
287
+ }
288
+ return (0, base_1.fail)(`No matching converter for ${JSON.stringify(from)}: ${errors.join('\n')}`);
289
+ });
290
+ }
291
+ exports.oneOf = oneOf;
292
+ /**
293
+ * A helper function to create a {@link Converter} which converts `unknown` to an array of `<T>`.
294
+ * @remarks
295
+ * If `onError` is `'failOnError'` (default), then the entire conversion fails if any element cannot
296
+ * be converted. If `onError` is `'ignoreErrors'`, then failing elements are silently ignored.
297
+ * @param converter - {@link Converter} used to convert each item in the array.
298
+ * @param ignoreErrors - Specifies treatment of unconvertible elements.
299
+ * @returns A {@link Converter} which returns an array of `<T>`.
300
+ * @public
301
+ */
302
+ function arrayOf(converter, onError = 'failOnError') {
303
+ return new converter_1.BaseConverter((from, __self, context) => {
304
+ if (!Array.isArray(from)) {
305
+ return (0, base_1.fail)(`Not an array: ${JSON.stringify(from)}`);
306
+ }
307
+ const successes = [];
308
+ const errors = [];
309
+ for (const item of from) {
310
+ const result = converter.convert(item, context);
311
+ if (result.isSuccess() && result.value !== undefined) {
312
+ successes.push(result.value);
313
+ }
314
+ else if (result.isFailure()) {
315
+ errors.push(result.message);
316
+ }
317
+ }
318
+ return errors.length === 0 || onError === 'ignoreErrors' ? (0, base_1.succeed)(successes) : (0, base_1.fail)(errors.join('\n'));
319
+ });
320
+ }
321
+ exports.arrayOf = arrayOf;
322
+ /**
323
+ * A helper function to create a {@link Converter} which converts `unknown` to {@link Experimental.ExtendedArray | ExtendedArray<T>}.
324
+ * @remarks
325
+ * If `onError` is `'failOnError'` (default), then the entire conversion fails if any element cannot
326
+ * be converted. If `onError` is `'ignoreErrors'`, then failing elements are silently ignored.
327
+ * @param converter - {@link Converter} used to convert each item in the array
328
+ * @param ignoreErrors - Specifies treatment of unconvertible elements
329
+ * @beta
330
+ */
331
+ function extendedArrayOf(label, converter, onError = 'failOnError') {
332
+ return arrayOf(converter, onError).map((items) => {
333
+ return (0, base_1.captureResult)(() => new experimental_1.ExtendedArray(label, ...items));
334
+ });
335
+ }
336
+ exports.extendedArrayOf = extendedArrayOf;
337
+ /**
338
+ * {@link Converter} to convert an `unknown` to an array of `string`.
339
+ * @remarks
340
+ * Returns {@link Success} with the the supplied value if it as an array
341
+ * of strings, returns {@link Failure} with an error message otherwise.
342
+ * @public
343
+ */
344
+ exports.stringArray = arrayOf(exports.string);
345
+ /**
346
+ * {@link Converter | Converter} to convert an `unknown` to an array of `number`.
347
+ * @remarks
348
+ * Returns {@link Success | Success} with the the supplied value if it as an array
349
+ * of numbers, returns {@link Failure | Failure} with an error message otherwise.
350
+ * @public
351
+ */
352
+ exports.numberArray = arrayOf(exports.number);
353
+ /**
354
+ * Concrete implementation of {@link Converters.(recordOf:1) | Converters.recordOf(Converter<T>)},
355
+ * {@link Converters.(recordOf:2) | Converters.recordOf(Converter<T>, 'fail' or 'ignore')}, and
356
+ * {@link Converters.(recordOf:3) | Converters.recordOf(Converter<T>, KeyedConverterOptions)}.
357
+ * @internal
358
+ */
359
+ function recordOf(converter, option = 'fail') {
360
+ const options = typeof option === 'string' ? { onError: option } : Object.assign({ onError: 'fail' }, option);
361
+ return new converter_1.BaseConverter((from, __self, context) => {
362
+ var _a, _b;
363
+ if (typeof from !== 'object' || from === null || Array.isArray(from)) {
364
+ return (0, base_1.fail)(`Not a string-keyed object: ${JSON.stringify(from)}`);
365
+ }
366
+ const record = {};
367
+ const errors = [];
368
+ for (const key in from) {
369
+ if ((0, base_1.isKeyOf)(key, from)) {
370
+ const writeKeyResult = (_b = (_a = options.keyConverter) === null || _a === void 0 ? void 0 : _a.convert(key, context)) !== null && _b !== void 0 ? _b : (0, base_1.succeed)(key);
371
+ writeKeyResult
372
+ .onSuccess((writeKey) => {
373
+ return converter.convert(from[key], context).onSuccess((value) => {
374
+ record[writeKey] = value;
375
+ return (0, base_1.succeed)(true);
376
+ });
377
+ })
378
+ .onFailure((message) => {
379
+ errors.push(message);
380
+ return (0, base_1.fail)(message);
381
+ });
382
+ }
383
+ }
384
+ return errors.length === 0 || options.onError === 'ignore' ? (0, base_1.succeed)(record) : (0, base_1.fail)(errors.join('\n'));
385
+ });
386
+ }
387
+ exports.recordOf = recordOf;
388
+ /**
389
+ * Concrete implementation of {@link Converters.(mapOf:1) | Converters.mapOf(Converter<T>)},
390
+ * {@link Converters.(mapOf:2) | Converters.mapOf(Converter<T>, 'fail' or 'ignore')}, and
391
+ * {@link Converters.(mapOf:3) | Converters.mapOf(Converter<T>, KeyedConverterOptions)}.
392
+ * @internal
393
+ */
394
+ function mapOf(converter, option = 'fail') {
395
+ const options = typeof option === 'string' ? { onError: option } : Object.assign({ onError: 'fail' }, option);
396
+ return new converter_1.BaseConverter((from, __self, context) => {
397
+ var _a, _b;
398
+ if (typeof from !== 'object' || from === null || Array.isArray(from)) {
399
+ return (0, base_1.fail)(`Not a string-keyed object: ${JSON.stringify(from)}`);
400
+ }
401
+ const map = new Map();
402
+ const errors = [];
403
+ for (const key in from) {
404
+ if ((0, base_1.isKeyOf)(key, from)) {
405
+ const writeKeyResult = (_b = (_a = options.keyConverter) === null || _a === void 0 ? void 0 : _a.convert(key, context)) !== null && _b !== void 0 ? _b : (0, base_1.succeed)(key);
406
+ writeKeyResult
407
+ .onSuccess((writeKey) => {
408
+ return converter.convert(from[key], context).onSuccess((value) => {
409
+ map.set(writeKey, value);
410
+ return (0, base_1.succeed)(true);
411
+ });
412
+ })
413
+ .onFailure((message) => {
414
+ errors.push(message);
415
+ return (0, base_1.fail)(message);
416
+ });
417
+ }
418
+ }
419
+ return errors.length === 0 || options.onError === 'ignore' ? (0, base_1.succeed)(map) : (0, base_1.fail)(errors.join('\n'));
420
+ });
421
+ }
422
+ exports.mapOf = mapOf;
423
+ /**
424
+ * Helper function to create a {@link Converter} which validates that a supplied value is
425
+ * of a type validated by a supplied validator function and returns it.
426
+ * @remarks
427
+ * If `validator` succeeds, this {@link Converter} returns {@link Success} with the supplied
428
+ * value of `from` coerced to type `<T>`. Returns a {@link Failure} with additional
429
+ * information otherwise.
430
+ * @param validator - A validator function to determine if the converted value is valid.
431
+ * @param description - A description of the validated type for use in error messages.
432
+ * @returns A new {@link Converter | Converter<T>} which applies the supplied validation.
433
+ * @public
434
+ */
435
+ function validateWith(validator, description) {
436
+ return new converter_1.BaseConverter((from, __self, __context) => {
437
+ if (validator(from)) {
438
+ return (0, base_1.succeed)(from);
439
+ }
440
+ return (0, base_1.fail)(`${JSON.stringify(from)}: invalid ${description !== null && description !== void 0 ? description : 'value'}`);
441
+ });
442
+ }
443
+ exports.validateWith = validateWith;
444
+ /**
445
+ * A helper function to create a {@link Converter} which extracts and converts an element from an array.
446
+ * @remarks
447
+ * The returned {@link Converter} returns {@link Success} with the converted value if the element exists
448
+ * in the supplied array and can be converted. Returns {@link Failure} with an error message otherwise.
449
+ * @param index - The index of the element to be extracted.
450
+ * @param converter - A {@link Converter} used to convert the extracted element.
451
+ * @returns A {@link Converter | Converter<T>} which extracts the specified element from an array.
452
+ * @public
453
+ */
454
+ function element(index, converter) {
455
+ return new converter_1.BaseConverter((from, __self, context) => {
456
+ if (index < 0) {
457
+ return (0, base_1.fail)(`${index}: cannot convert for a negative element index`);
458
+ }
459
+ else if (!Array.isArray(from)) {
460
+ return (0, base_1.fail)('element converter: source is not an array');
461
+ }
462
+ else if (index >= from.length) {
463
+ return (0, base_1.fail)(`${index}: element converter index out of range (0..${from.length - 1})`);
464
+ }
465
+ return converter.convert(from[index], context);
466
+ });
467
+ }
468
+ exports.element = element;
469
+ /**
470
+ * A helper function to create a {@link Converter} which extracts and converts an optional element from an array.
471
+ * @remarks
472
+ * The resulting {@link Converter} returns {@link Success} with the converted value if the element exists
473
+ * in the supplied array and can be converted. Returns {@link Success} with value `undefined` if the parameter
474
+ * is an array but the index is out of range. Returns {@link Failure} with a message if the supplied parameter
475
+ * is not an array, if the requested index is negative, or if the element cannot be converted.
476
+ * @param index - The index of the element to be extracted.
477
+ * @param converter - A {@link Converter} used to convert the extracted element.
478
+ * @returns A {@link Converter | Converter<T>} which extracts the specified element from an array.
479
+ * @public
480
+ */
481
+ function optionalElement(index, converter) {
482
+ return new converter_1.BaseConverter((from, __self, context) => {
483
+ if (index < 0) {
484
+ return (0, base_1.fail)(`${index}: cannot convert for a negative element index`);
485
+ }
486
+ else if (!Array.isArray(from)) {
487
+ return (0, base_1.fail)('element converter: source is not an array');
488
+ }
489
+ else if (index >= from.length) {
490
+ return (0, base_1.succeed)(undefined);
491
+ }
492
+ return converter.convert(from[index], context);
493
+ });
494
+ }
495
+ exports.optionalElement = optionalElement;
496
+ /**
497
+ * A helper function to create a {@link Converter} which extracts and convert a property specified
498
+ * by name from an object.
499
+ * @remarks
500
+ * The resulting {@link Converter} returns {@link Success} with the converted value of the corresponding
501
+ * object property if the field exists and can be converted. Returns {@link Failure} with an error message
502
+ * otherwise.
503
+ * @param name - The name of the field to be extracted.
504
+ * @param converter - {@link Converter} used to convert the extracted field.
505
+ * @public
506
+ */
507
+ function field(name, converter) {
508
+ return new converter_1.BaseConverter((from, __self, context) => {
509
+ if (typeof from === 'object' && !Array.isArray(from) && from !== null) {
510
+ if ((0, base_1.isKeyOf)(name, from)) {
511
+ return converter.convert(from[name], context).onFailure((message) => {
512
+ return (0, base_1.fail)(`Field ${name}: ${message}`);
513
+ });
514
+ }
515
+ return (0, base_1.fail)(`Field ${name} not found in: ${JSON.stringify(from)}`);
516
+ }
517
+ return (0, base_1.fail)(`Cannot convert field "${name}" from non-object ${JSON.stringify(from)}`);
518
+ });
519
+ }
520
+ exports.field = field;
521
+ /**
522
+ * A helper function to create a {@link Converter} which extracts and convert a property specified
523
+ * by name from an object.
524
+ * @remarks
525
+ * The resulting {@link Converter} returns {@link Success} with the converted value of the corresponding
526
+ * object property if the field exists and can be converted. Returns {@link Success} with value `undefined`
527
+ * if the supplied parameter is an object but the named field is not present. Returns {@link Failure} with
528
+ * an error message otherwise.
529
+ * @param name - The name of the field to be extracted.
530
+ * @param converter - {@link Converter} used to convert the extracted field.
531
+ * @public
532
+ */
533
+ function optionalField(name, converter) {
534
+ return new converter_1.BaseConverter((from, __self, context) => {
535
+ if (typeof from === 'object' && !Array.isArray(from) && from !== null) {
536
+ if ((0, base_1.isKeyOf)(name, from)) {
537
+ const result = converter.convert(from[name], context).onFailure((message) => {
538
+ return (0, base_1.fail)(`${name}: ${message}`);
539
+ });
540
+ // if conversion was successful or input was undefined we
541
+ // succeed with 'undefined', but we propagate actual
542
+ // failures.
543
+ if (result.isSuccess() || from[name] !== undefined) {
544
+ return result;
545
+ }
546
+ }
547
+ return (0, base_1.succeed)(undefined);
548
+ }
549
+ return (0, base_1.fail)(`Cannot convert field "${name}" from non-object ${JSON.stringify(from)}`);
550
+ }, undefined, { isOptional: true });
551
+ }
552
+ exports.optionalField = optionalField;
553
+ /**
554
+ * Concrete implementation of {@link Converters.(object:1) | Converters.object(fields, options)}
555
+ * and {@link Converters.(object:2) | Converters.objects(fields, optionalKeys)}.
556
+ * @internal
557
+ */
558
+ function object(properties, options) {
559
+ return new objectConverter_1.ObjectConverter(properties, options);
560
+ }
561
+ exports.object = object;
562
+ /**
563
+ * Concrete implementation for {@link Converters.(strictObject:1) | Converters.strictObject(fields, options)}
564
+ * and {@link Converters.strictObject | Converters.strictObject(fields, optional)}.
565
+ * @internal
566
+ */
567
+ function strictObject(properties, opt) {
568
+ const options = opt && Array.isArray(opt) ? { strict: true, optionalFields: opt } : Object.assign(Object.assign({}, (opt !== null && opt !== void 0 ? opt : {})), { strict: true });
569
+ return new objectConverter_1.ObjectConverter(properties, options);
570
+ }
571
+ exports.strictObject = strictObject;
572
+ /**
573
+ * Helper to create a {@link Converter} which converts a discriminated object without changing shape.
574
+ * @remarks
575
+ * Takes the name of the discriminator property and a
576
+ * {@link Converters.DiscriminatedObjectConverters | string-keyed Record of converters}. During conversion,
577
+ * the resulting {@link Converter} invokes the converter from `converters` that corresponds to the value of
578
+ * the discriminator property in the source object.
579
+ *
580
+ * If the source is not an object, the discriminator property is missing, or the discriminator has
581
+ * a value not present in the converters, conversion fails and returns {@link Failure} with more information.
582
+ * @param discriminatorProp - Name of the property used to discriminate types.
583
+ * @param converters - {@link Converters.DiscriminatedObjectConverters | String-keyed record of converters} to
584
+ * invoke, where each key corresponds to a value of the discriminator property.
585
+ * @returns A {@link Converter} which converts the corresponding discriminated object.
586
+ * @public
587
+ */
588
+ function discriminatedObject(discriminatorProp, converters) {
589
+ return new converter_1.BaseConverter((from) => {
590
+ if (typeof from !== 'object' || Array.isArray(from) || from === null) {
591
+ return (0, base_1.fail)(`Not a discriminated object: "${JSON.stringify(from)}"`);
592
+ }
593
+ if (!(0, base_1.isKeyOf)(discriminatorProp, from) || !from[discriminatorProp]) {
594
+ return (0, base_1.fail)(`Discriminator property ${discriminatorProp} not present in "${JSON.stringify(from)}"`);
595
+ }
596
+ const discriminatorValue = from[discriminatorProp];
597
+ const converter = converters[discriminatorValue];
598
+ if (converter === undefined) {
599
+ return (0, base_1.fail)(`No converter for discriminator ${discriminatorProp}="${discriminatorValue}"`);
600
+ }
601
+ return converter.convert(from);
602
+ });
603
+ }
604
+ exports.discriminatedObject = discriminatedObject;
605
+ /**
606
+ * Helper to create a {@link Converter} which converts a source object to a new object with a
607
+ * different shape.
608
+ *
609
+ * @remarks
610
+ * On successful conversion, the resulting {@link Converter} returns {@link Success} with a new
611
+ * object, which contains the converted values under the key names specified at initialization time.
612
+ * It returns {@link Failure} with an error message if any fields to be extracted do not exist
613
+ * or cannot be converted.
614
+ *
615
+ * Fields that succeed but convert to undefined are omitted from the result object but do not
616
+ * fail the conversion.
617
+ *
618
+ * @param properties - An object with key names that correspond to the target object and an
619
+ * appropriate {@link Conversion.FieldConverters | FieldConverter} which extracts and converts
620
+ * a single filed from the source object.
621
+ * @returns A {@link Converter} with the specified conversion behavior.
622
+ * @public
623
+ */
624
+ function transform(properties) {
625
+ return new converter_1.BaseConverter((from, __self, context) => {
626
+ // eslint bug thinks key is used before defined
627
+ // eslint-disable-next-line no-use-before-define
628
+ const converted = {};
629
+ const errors = [];
630
+ for (const key in properties) {
631
+ if (properties[key]) {
632
+ const result = properties[key].convert(from, context);
633
+ if (result.isSuccess() && result.value !== undefined) {
634
+ converted[key] = result.value;
635
+ }
636
+ else if (result.isFailure()) {
637
+ errors.push(result.message);
638
+ }
639
+ }
640
+ }
641
+ return errors.length === 0 ? (0, base_1.succeed)(converted) : (0, base_1.fail)(errors.join('\n'));
642
+ });
643
+ }
644
+ exports.transform = transform;
645
+ /**
646
+ * Helper to create a strongly-typed {@link Converter} which converts a source object to a
647
+ * new object with a different shape.
648
+ *
649
+ * @remarks
650
+ * On successful conversion, the resulting {@link Converter} returns {@link Success} with a new
651
+ * object, which contains the converted values under the key names specified at initialization time.
652
+ *
653
+ * It returns {@link Failure} with an error message if any fields to be extracted do not exist
654
+ * or cannot be converted.
655
+ *
656
+ * @param destinationFields - An object with key names that correspond to the target object and an
657
+ * appropriate {@link Converters.FieldTransformers | FieldTransformers} which specifies the name
658
+ * of the corresponding property in the source object, the converter used to convert the source
659
+ * property and any configuration to guide the conversion.
660
+ * @param options - Options which affect the transformation.
661
+ *
662
+ * @returns A {@link Converter} with the specified conversion behavior.
663
+ * @public
664
+ */
665
+ function transformObject(destinationFields, options) {
666
+ return new converter_1.BaseConverter((from, __self, context) => {
667
+ // eslint bug thinks key is used before defined
668
+ // eslint-disable-next-line no-use-before-define
669
+ const converted = {};
670
+ const errors = [];
671
+ const used = new Set(options === null || options === void 0 ? void 0 : options.ignore);
672
+ if (typeof from === 'object' && !Array.isArray(from) && from !== null) {
673
+ for (const destinationKey in destinationFields) {
674
+ if (destinationFields[destinationKey]) {
675
+ const srcKey = destinationFields[destinationKey].from;
676
+ const converter = destinationFields[destinationKey].converter;
677
+ if ((0, base_1.isKeyOf)(srcKey, from)) {
678
+ const result = converter.convert(from[srcKey], context);
679
+ if (result.isSuccess() && result.value !== undefined) {
680
+ converted[destinationKey] = result.value;
681
+ }
682
+ else if (result.isFailure()) {
683
+ errors.push(`${srcKey}->${destinationKey}: ${result.message}`);
684
+ }
685
+ used.add(srcKey);
686
+ }
687
+ else if (destinationFields[destinationKey].optional !== true) {
688
+ errors.push(`${String(srcKey)}: required property missing in source object.`);
689
+ }
690
+ }
691
+ }
692
+ if ((options === null || options === void 0 ? void 0 : options.strict) === true) {
693
+ for (const key in from) {
694
+ if ((0, base_1.isKeyOf)(key, from) && !used.has(key)) {
695
+ errors.push(`${key}: unexpected property in source object`);
696
+ }
697
+ }
698
+ }
699
+ }
700
+ else {
701
+ errors.push('source is not an object');
702
+ }
703
+ return errors.length === 0
704
+ ? (0, base_1.succeed)(converted)
705
+ : (0, base_1.fail)((options === null || options === void 0 ? void 0 : options.description) ? `${options.description}:\n ${errors.join('\n ')}` : errors.join('\n'));
706
+ });
707
+ }
708
+ exports.transformObject = transformObject;
709
+ /**
710
+ * A helper wrapper to construct a {@link Converter} which converts to an arbitrary strongly-typed
711
+ * range of some comparable type.
712
+ * @param converter - {@link Converter} used to convert `min` and `max` extent of the range.
713
+ * @param constructor - Static constructor to instantiate the object.
714
+ * @public
715
+ */
716
+ function rangeTypeOf(converter, constructor) {
717
+ return new converter_1.BaseConverter((from, __self, context) => {
718
+ const result = object({
719
+ min: converter,
720
+ max: converter
721
+ }, { optionalFields: ['min', 'max'] }).convert(from, context);
722
+ if (result.isSuccess()) {
723
+ return constructor({ min: result.value.min, max: result.value.max });
724
+ }
725
+ return (0, base_1.fail)(result.message);
726
+ });
727
+ }
728
+ exports.rangeTypeOf = rangeTypeOf;
729
+ /**
730
+ * A helper wrapper to construct a {@link Converter} which converts to {@link Experimental.RangeOf | RangeOf<T>}
731
+ * where `<T>` is some comparable type.
732
+ * @param converter - {@link Converter} used to convert `min` and `max` extent of the range.
733
+ * @public
734
+ */
735
+ function rangeOf(converter) {
736
+ return rangeTypeOf(converter, experimental_1.RangeOf.createRange);
737
+ }
738
+ exports.rangeOf = rangeOf;
739
+ //# sourceMappingURL=converters.js.map