@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,58 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2021 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
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.ValidatorTraits = exports.defaultValidatorTraits = void 0;
25
+ /**
26
+ * Default {@link Validation.ValidatorTraitValues | validation traits}.
27
+ * @public
28
+ */
29
+ exports.defaultValidatorTraits = {
30
+ isOptional: false,
31
+ constraints: []
32
+ };
33
+ /**
34
+ * Generic implementation of {@link Validation.ValidatorTraitValues | ValidatorTraitValues}.
35
+ * @public
36
+ */
37
+ class ValidatorTraits {
38
+ /**
39
+ * Constructs a new {@link Validation.ValidatorTraits | ValidatorTraits} optionally
40
+ * initialized with the supplied base and initial values.
41
+ * @remarks
42
+ * Initial values take priority over base values, which fall back to the global default values.
43
+ * @param init - Partial initial values to be set in the resulting {@link Validation.Validator | Validator}.
44
+ * @param base - Base values to be used when no initial values are present.
45
+ */
46
+ constructor(init, base) {
47
+ var _a, _b, _c, _d, _e, _f;
48
+ this.isOptional = (_b = (_a = init === null || init === void 0 ? void 0 : init.isOptional) !== null && _a !== void 0 ? _a : base === null || base === void 0 ? void 0 : base.isOptional) !== null && _b !== void 0 ? _b : exports.defaultValidatorTraits.isOptional;
49
+ this.brand = (_d = (_c = init === null || init === void 0 ? void 0 : init.brand) !== null && _c !== void 0 ? _c : base === null || base === void 0 ? void 0 : base.brand) !== null && _d !== void 0 ? _d : exports.defaultValidatorTraits.brand;
50
+ this.constraints = [
51
+ ...exports.defaultValidatorTraits.constraints,
52
+ ...((_e = base === null || base === void 0 ? void 0 : base.constraints) !== null && _e !== void 0 ? _e : []),
53
+ ...((_f = init === null || init === void 0 ? void 0 : init.constraints) !== null && _f !== void 0 ? _f : [])
54
+ ];
55
+ }
56
+ }
57
+ exports.ValidatorTraits = ValidatorTraits;
58
+ //# sourceMappingURL=traits.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traits.js","sourceRoot":"","sources":["../../../src/packlets/validation/traits.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AA4CH;;;GAGG;AACU,QAAA,sBAAsB,GAAyB;IAC1D,UAAU,EAAE,KAAK;IACjB,WAAW,EAAE,EAAE;CAChB,CAAC;AAEF;;;GAGG;AACH,MAAa,eAAe;IAgB1B;;;;;;;OAOG;IACH,YAAmB,IAAoC,EAAE,IAA2B;;QAClF,IAAI,CAAC,UAAU,GAAG,MAAA,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,UAAU,mCAAI,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,UAAU,mCAAI,8BAAsB,CAAC,UAAU,CAAC;QAC5F,IAAI,CAAC,KAAK,GAAG,MAAA,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK,mCAAI,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK,mCAAI,8BAAsB,CAAC,KAAK,CAAC;QACxE,IAAI,CAAC,WAAW,GAAG;YACjB,GAAG,8BAAsB,CAAC,WAAW;YACrC,GAAG,CAAC,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,mCAAI,EAAE,CAAC;YAC5B,GAAG,CAAC,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,mCAAI,EAAE,CAAC;SAC7B,CAAC;IACJ,CAAC;CACF;AAjCD,0CAiCC","sourcesContent":["/*\n * Copyright (c) 2021 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n/**\n * A {@link Validation.ConstraintTrait | ConstraintTrait} indicating that\n * a {@link Validation.Constraint | Constraint<T>} function provides an\n * additional constraint implementation.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface FunctionConstraintTrait {\n type: 'function';\n}\n\n/**\n * Union of all supported constraint traits.\n * @public\n */\nexport type ConstraintTrait = FunctionConstraintTrait;\n\n/**\n * Interface describing the supported validator traits.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface ValidatorTraitValues {\n /**\n * Indicates whether the validator accepts `undefined` as\n * a valid value.\n */\n readonly isOptional: boolean;\n\n /**\n * If present, indicates that the result will be branded\n * with the corresponding brand.\n */\n readonly brand?: string;\n\n /**\n * Zero or more additional {@link Validation.ConstraintTrait | ConstraintTrait}s\n * describing additional constraints applied by this {@link Validation.Validator | Validator}.\n */\n readonly constraints: ConstraintTrait[];\n}\n\n/**\n * Default {@link Validation.ValidatorTraitValues | validation traits}.\n * @public\n */\nexport const defaultValidatorTraits: ValidatorTraitValues = {\n isOptional: false,\n constraints: []\n};\n\n/**\n * Generic implementation of {@link Validation.ValidatorTraitValues | ValidatorTraitValues}.\n * @public\n */\nexport class ValidatorTraits implements ValidatorTraitValues {\n /**\n * {@inheritdoc Validation.ValidatorTraitValues.isOptional}\n */\n public readonly isOptional: boolean;\n\n /**\n * {@inheritdoc Validation.ValidatorTraitValues.brand}\n */\n public readonly brand?: string;\n\n /**\n * {@inheritdoc Validation.ValidatorTraitValues.constraints}\n */\n public readonly constraints: ConstraintTrait[];\n\n /**\n * Constructs a new {@link Validation.ValidatorTraits | ValidatorTraits} optionally\n * initialized with the supplied base and initial values.\n * @remarks\n * Initial values take priority over base values, which fall back to the global default values.\n * @param init - Partial initial values to be set in the resulting {@link Validation.Validator | Validator}.\n * @param base - Base values to be used when no initial values are present.\n */\n public constructor(init?: Partial<ValidatorTraitValues>, base?: ValidatorTraitValues) {\n this.isOptional = init?.isOptional ?? base?.isOptional ?? defaultValidatorTraits.isOptional;\n this.brand = init?.brand ?? base?.brand ?? defaultValidatorTraits.brand;\n this.constraints = [\n ...defaultValidatorTraits.constraints,\n ...(base?.constraints ?? []),\n ...(init?.constraints ?? [])\n ];\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { Failure } from '../result';
1
+ import { Failure } from '../base';
2
2
  import { ValidatorBase, ValidatorBaseConstructorParams } from './validatorBase';
3
3
  import { TypeGuardWithContext } from './common';
4
4
  import { ValidatorOptions } from './validator';
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typeGuard.d.ts","sourceRoot":"","sources":["../../../src/packlets/validation/typeGuard.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,OAAO,EAAQ,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,8BAA8B,EAAE,MAAM,iBAAiB,CAAC;AAEhF,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C;;;GAGG;AAEH,MAAM,WAAW,mCAAmC,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,CAClE,SAAQ,8BAA8B,CAAC,CAAC,EAAE,EAAE,CAAC;IAC7C,KAAK,EAAE,oBAAoB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACnC,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AACH,qBAAa,kBAAkB,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,CAAE,SAAQ,aAAa,CAAC,CAAC,EAAE,EAAE,CAAC;IAC3E;;;OAGG;IACH,SAAgB,OAAO,EAAE,gBAAgB,CAAC,EAAE,CAAC,CAAC;IAC9C,SAAgB,WAAW,EAAE,MAAM,CAAC;IAEpC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEvD;;;;OAIG;gBACgB,MAAM,EAAE,mCAAmC,CAAC,CAAC,EAAE,EAAE,CAAC;IAOrE;;;;;;;;OAQG;IACH,SAAS,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,EAAE,GAAG,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;CAMvE"}
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2021 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
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.TypeGuardValidator = void 0;
25
+ const base_1 = require("../base");
26
+ const validatorBase_1 = require("./validatorBase");
27
+ /**
28
+ * An in-place {@link Validation.Validator | Validator} that can be instantiated using a type guard
29
+ * function.
30
+ * @public
31
+ */
32
+ class TypeGuardValidator extends validatorBase_1.ValidatorBase {
33
+ /**
34
+ * Constructs a new {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator}.
35
+ * @param params - Optional {@link Validation.Classes.TypeGuardValidatorConstructorParams | init params} for the
36
+ * new {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator}.
37
+ */
38
+ constructor(params) {
39
+ var _a;
40
+ super(params);
41
+ this.description = params.description;
42
+ this._guard = params.guard;
43
+ this.options = (_a = params.options) !== null && _a !== void 0 ? _a : {};
44
+ }
45
+ /**
46
+ * Static method which validates that a supplied `unknown` value matches the supplied
47
+ * type guard, returning a `Failure<T>` containing more information about a failure.
48
+ * @param from - Value to be converted.
49
+ * @param context - Optional validation context.
50
+ * @returns `true` if `from` is valid, {@link Failure | Failure<T>}
51
+ * with an error message if `from` is invalid.
52
+ * @internal
53
+ */
54
+ _validate(from, context) {
55
+ if (this._guard(from, context)) {
56
+ return true;
57
+ }
58
+ return (0, base_1.fail)(`invalid ${this.description} (${JSON.stringify(from)})`);
59
+ }
60
+ }
61
+ exports.TypeGuardValidator = TypeGuardValidator;
62
+ //# sourceMappingURL=typeGuard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typeGuard.js","sourceRoot":"","sources":["../../../src/packlets/validation/typeGuard.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAAwC;AACxC,mDAAgF;AAgBhF;;;;GAIG;AACH,MAAa,kBAAoC,SAAQ,6BAAoB;IAU3E;;;;OAIG;IACH,YAAmB,MAAkD;;QACnE,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;QACtC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,MAAA,MAAM,CAAC,OAAO,mCAAI,EAAE,CAAC;IACtC,CAAC;IAED;;;;;;;;OAQG;IACO,SAAS,CAAC,IAAa,EAAE,OAAY;QAC7C,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE;YAC9B,OAAO,IAAI,CAAC;SACb;QACD,OAAO,IAAA,WAAI,EAAC,WAAW,IAAI,CAAC,WAAW,KAAK,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACvE,CAAC;CACF;AArCD,gDAqCC","sourcesContent":["/*\n * Copyright (c) 2021 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Failure, fail } from '../base';\nimport { ValidatorBase, ValidatorBaseConstructorParams } from './validatorBase';\n\nimport { TypeGuardWithContext } from './common';\nimport { ValidatorOptions } from './validator';\n\n/**\n * Parameters used to construct a {@link Validation.Classes.TypeGuardValidator}.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface TypeGuardValidatorConstructorParams<T, TC = unknown>\n extends ValidatorBaseConstructorParams<T, TC> {\n guard: TypeGuardWithContext<T, TC>;\n description: string;\n}\n\n/**\n * An in-place {@link Validation.Validator | Validator} that can be instantiated using a type guard\n * function.\n * @public\n */\nexport class TypeGuardValidator<T, TC = unknown> extends ValidatorBase<T, TC> {\n /**\n * {@link Validation.ValidatorOptions | Options} which apply to this\n * validator.\n */\n public readonly options: ValidatorOptions<TC>;\n public readonly description: string;\n\n protected readonly _guard: TypeGuardWithContext<T, TC>;\n\n /**\n * Constructs a new {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator}.\n * @param params - Optional {@link Validation.Classes.TypeGuardValidatorConstructorParams | init params} for the\n * new {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator}.\n */\n public constructor(params: TypeGuardValidatorConstructorParams<T, TC>) {\n super(params);\n this.description = params.description;\n this._guard = params.guard;\n this.options = params.options ?? {};\n }\n\n /**\n * Static method which validates that a supplied `unknown` value matches the supplied\n * type guard, returning a `Failure<T>` containing more information about a failure.\n * @param from - Value to be converted.\n * @param context - Optional validation context.\n * @returns `true` if `from` is valid, {@link Failure | Failure<T>}\n * with an error message if `from` is invalid.\n * @internal\n */\n protected _validate(from: unknown, context?: TC): boolean | Failure<T> {\n if (this._guard(from, context)) {\n return true;\n }\n return fail(`invalid ${this.description} (${JSON.stringify(from)})`);\n }\n}\n"]}
@@ -1,6 +1,5 @@
1
+ import { Brand, Failure, Result } from '../base';
1
2
  import { ConstraintTrait, ValidatorTraits } from './traits';
2
- import { Failure, Result } from '../result';
3
- import { Brand } from '../brand';
4
3
  /**
5
4
  * Options that apply to any {@link Validation.Validator | Validator}.
6
5
  * @public
@@ -35,22 +34,22 @@ export interface Validator<T, TC = undefined> {
35
34
  */
36
35
  readonly brand: string | undefined;
37
36
  /**
38
- * Tests to see if a supplied `unknown` value matches this
39
- * validation.
40
- * @param from - The `unknown` value to be tested.
41
- * @param context - Optional validation context.
42
- * @returns {@link Success} with the typed, validated value,
43
- * or {@link Failure} with an error message if validation fails.
44
- */
37
+ * Tests to see if a supplied `unknown` value matches this
38
+ * validation.
39
+ * @param from - The `unknown` value to be tested.
40
+ * @param context - Optional validation context.
41
+ * @returns {@link Success} with the typed, validated value,
42
+ * or {@link Failure} with an error message if validation fails.
43
+ */
45
44
  validate(from: unknown, context?: TC): Result<T>;
46
45
  /**
47
- * Tests to see if a supplied `unknown` value matches this
48
- * validation. Accepts `undefined`.
49
- * @param from - The `unknown` value to be tested.
50
- * @param context - Optional validation context.
51
- * @returns {@link Success} with the typed, validated value,
52
- * or {@link Failure} with an error message if validation fails.
53
- */
46
+ * Tests to see if a supplied `unknown` value matches this
47
+ * validation. Accepts `undefined`.
48
+ * @param from - The `unknown` value to be tested.
49
+ * @param context - Optional validation context.
50
+ * @returns {@link Success} with the typed, validated value,
51
+ * or {@link Failure} with an error message if validation fails.
52
+ */
54
53
  validateOptional(from: unknown, context?: TC): Result<T | undefined>;
55
54
  /**
56
55
  * Non-throwing type guard
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../../src/packlets/validation/validator.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE5D;;;GAGG;AAEH,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
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2021 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
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ //# sourceMappingURL=validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validator.js","sourceRoot":"","sources":["../../../src/packlets/validation/validator.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG","sourcesContent":["/*\n * Copyright (c) 2021 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Brand, Failure, Result } from '../base';\nimport { ConstraintTrait, ValidatorTraits } from './traits';\n\n/**\n * Options that apply to any {@link Validation.Validator | Validator}.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface ValidatorOptions<TC> {\n defaultContext?: TC;\n}\n\n/**\n * A {@link Validation.Constraint | Constraint<T>} function returns\n * `true` if the supplied value meets the constraint. Can return\n * {@link Failure} with an error message or simply return `false`\n * for a default message.\n * @public\n */\nexport type Constraint<T> = (val: T) => boolean | Failure<T>;\n\n/**\n * In-place validation that a supplied unknown matches some\n * required characteristics (type, values, etc).\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface Validator<T, TC = undefined> {\n /**\n * {@link Validation.ValidatorTraits | Traits} describing this validation.\n */\n readonly traits: ValidatorTraits;\n\n /**\n * Indicates whether this element is explicitly optional.\n */\n readonly isOptional: boolean;\n\n /**\n * The brand for a branded type.\n */\n readonly brand: string | undefined;\n\n /**\n * Tests to see if a supplied `unknown` value matches this\n * validation.\n * @param from - The `unknown` value to be tested.\n * @param context - Optional validation context.\n * @returns {@link Success} with the typed, validated value,\n * or {@link Failure} with an error message if validation fails.\n */\n validate(from: unknown, context?: TC): Result<T>;\n\n /**\n * Tests to see if a supplied `unknown` value matches this\n * validation. Accepts `undefined`.\n * @param from - The `unknown` value to be tested.\n * @param context - Optional validation context.\n * @returns {@link Success} with the typed, validated value,\n * or {@link Failure} with an error message if validation fails.\n */\n validateOptional(from: unknown, context?: TC): Result<T | undefined>;\n\n /**\n * Non-throwing type guard\n * @param from - The value to be tested.\n * @param context - Optional validation context.\n */\n guard(from: unknown, context?: TC): from is T;\n\n /**\n * Creates an {@link Validation.Validator | in-place validator}\n * which is derived from this one but which also matches `undefined`.\n */\n optional(): Validator<T | undefined, TC>;\n\n /**\n * Creates an {@link Validation.Validator | in-place validator}\n * which is derived from this one but which applies additional constraints.\n * @param constraint - the constraint to be applied\n * @param trait - As optional {@link Validation.ConstraintTrait | ConstraintTrait}\n * to be applied to the resulting {@link Validation.Validator | Validator}.\n * @returns A new {@link Validation.Validator | Validator}.\n */\n withConstraint(constraint: Constraint<T>, trait?: ConstraintTrait): Validator<T, TC>;\n\n /**\n * Creates a new {@link Validation.Validator | in-place validator} which\n * is derived from this one but which matches a branded result.\n * @param brand - The brand to be applied.\n */\n withBrand<B extends string>(brand: B): Validator<Brand<T, B>, TC>;\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { GenericValidator, GenericValidatorConstructorParams } from './genericValidator';
2
- import { Failure } from '../result';
2
+ import { Failure } from '../base';
3
3
  /**
4
4
  * @internal
5
5
  */
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validatorBase.d.ts","sourceRoot":"","sources":["../../../src/packlets/validation/validatorBase.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,gBAAgB,EAAE,iCAAiC,EAAE,MAAM,oBAAoB,CAAC;AAEzF,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC;;GAEG;AACH,MAAM,MAAM,8BAA8B,CAAC,CAAC,EAAE,EAAE,IAAI,IAAI,CACtD,iCAAiC,CAAC,CAAC,EAAE,EAAE,CAAC,EACxC,WAAW,CACZ,CAAC;AAEF;;;GAGG;AACH,8BAAsB,aAAa,CAAC,CAAC,EAAE,EAAE,GAAG,SAAS,CAAE,SAAQ,gBAAgB,CAAC,CAAC,EAAE,EAAE,CAAC;IACpF;;;;OAIG;IACH,SAAS,aAAa,MAAM,EAAE,OAAO,CAAC,8BAA8B,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAO5E;;;;;;;OAOG;IACH,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,EAAE,GAAG,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;CAChF"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2021 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
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.ValidatorBase = void 0;
25
+ const genericValidator_1 = require("./genericValidator");
26
+ /**
27
+ * Abstract base helper class for specific validator implementations
28
+ * @internal
29
+ */
30
+ class ValidatorBase extends genericValidator_1.GenericValidator {
31
+ /**
32
+ * Inner constructor
33
+ * @param params - Initialization params.
34
+ * @internal
35
+ */
36
+ constructor(params) {
37
+ super(Object.assign({ validator: (from, context) => this._validate(from, context) }, params));
38
+ }
39
+ }
40
+ exports.ValidatorBase = ValidatorBase;
41
+ //# sourceMappingURL=validatorBase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validatorBase.js","sourceRoot":"","sources":["../../../src/packlets/validation/validatorBase.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,yDAAyF;AAYzF;;;GAGG;AACH,MAAsB,aAAiC,SAAQ,mCAAuB;IACpF;;;;OAIG;IACH,YAAsB,MAAsD;QAC1E,KAAK,iBACH,SAAS,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,IACxD,MAAM,EACT,CAAC;IACL,CAAC;CAWF;AAtBD,sCAsBC","sourcesContent":["/*\n * Copyright (c) 2021 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { GenericValidator, GenericValidatorConstructorParams } from './genericValidator';\n\nimport { Failure } from '../base';\n\n/**\n * @internal\n */\nexport type ValidatorBaseConstructorParams<T, TC> = Omit<\n GenericValidatorConstructorParams<T, TC>,\n 'validator'\n>;\n\n/**\n * Abstract base helper class for specific validator implementations\n * @internal\n */\nexport abstract class ValidatorBase<T, TC = undefined> extends GenericValidator<T, TC> {\n /**\n * Inner constructor\n * @param params - Initialization params.\n * @internal\n */\n protected constructor(params: Partial<ValidatorBaseConstructorParams<T, TC>>) {\n super({\n validator: (from, context) => this._validate(from, context),\n ...params\n });\n }\n\n /**\n * Abstract validation method to me implemented by derived classes.\n * @param from - Value to be converted.\n * @param context - Optional validation context.\n * @returns `true` if `from` is valid, {@link Failure | Failure<T>}\n * with an error message if `from` is invalid.\n * @internal\n */\n protected abstract _validate(from: unknown, context?: TC): boolean | Failure<T>;\n}\n"]}
@@ -1,26 +1,23 @@
1
1
  import { ArrayValidator, ArrayValidatorConstructorParams } from './array';
2
2
  import { FieldValidators, ObjectValidator, ObjectValidatorConstructorParams } from './object';
3
3
  import { TypeGuardValidator, TypeGuardValidatorConstructorParams } from './typeGuard';
4
- import { BooleanValidator } from './boolean';
5
- import { NumberValidator } from './number';
6
- import { StringValidator } from './string';
7
4
  import { TypeGuardWithContext } from './common';
8
5
  import { Validator } from './validator';
9
6
  /**
10
7
  * A {@link Validation.Classes.StringValidator | StringValidator} which validates a string in place.
11
8
  * @public
12
9
  */
13
- export declare const string: StringValidator<string, unknown>;
10
+ export declare const string: Validator<string>;
14
11
  /**
15
12
  * A {@link Validation.Classes.NumberValidator | NumberValidator} which validates a number in place.
16
13
  * @public
17
14
  */
18
- export declare const number: NumberValidator<number, unknown>;
15
+ export declare const number: Validator<number>;
19
16
  /**
20
17
  * A {@link Validation.Classes.BooleanValidator | BooleanValidator} which validates a boolean in place.
21
18
  * @public
22
19
  */
23
- export declare const boolean: BooleanValidator<unknown>;
20
+ export declare const boolean: Validator<boolean>;
24
21
  /**
25
22
  * Helper function to create a {@link Validation.Classes.ObjectValidator | ObjectValidator} which validates
26
23
  * an object in place.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../../src/packlets/validation/validators.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,cAAc,EAAE,+BAA+B,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AAC9F,OAAO,EAAE,kBAAkB,EAAE,mCAAmC,EAAE,MAAM,aAAa,CAAC;AAGtF,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAIhD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;GAGG;AACH,eAAO,MAAM,MAAM,EAAE,SAAS,CAAC,MAAM,CAAyB,CAAC;AAE/D;;;GAGG;AACH,eAAO,MAAM,MAAM,EAAE,SAAS,CAAC,MAAM,CAAyB,CAAC;AAE/D;;;GAGG;AACH,eAAO,MAAM,OAAO,EAAE,SAAS,CAAC,OAAO,CAA0B,CAAC;AAElE;;;;;;;;;;GAUG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,EACpC,MAAM,EAAE,eAAe,CAAC,CAAC,EAAE,EAAE,CAAC,EAC9B,MAAM,CAAC,EAAE,IAAI,CAAC,gCAAgC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,QAAQ,CAAC,GAC/D,eAAe,CAAC,CAAC,EAAE,EAAE,CAAC,CAExB;AAED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,EAAE,EAC3B,eAAe,EAAE,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,EACjC,MAAM,CAAC,EAAE,IAAI,CAAC,+BAA+B,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,iBAAiB,CAAC,GACvE,cAAc,CAAC,CAAC,EAAE,EAAE,CAAC,CAEvB;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAWhF;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,EACrF,KAAK,EAAE,CAAC,GACP,SAAS,CAAC,CAAC,CAAC,CAQd;AAED;;;;;;;;GAQG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,EAAE,EACvB,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,oBAAoB,CAAC,CAAC,EAAE,EAAE,CAAC,EAClC,MAAM,CAAC,EAAE,IAAI,CAAC,mCAAmC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,GACjF,kBAAkB,CAAC,CAAC,EAAE,EAAE,CAAC,CAE3B"}
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2023 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
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.isA = exports.literal = exports.enumeratedValue = exports.arrayOf = exports.object = exports.boolean = exports.number = exports.string = void 0;
25
+ const base_1 = require("../base");
26
+ const array_1 = require("./array");
27
+ const object_1 = require("./object");
28
+ const typeGuard_1 = require("./typeGuard");
29
+ const boolean_1 = require("./boolean");
30
+ const genericValidator_1 = require("./genericValidator");
31
+ const number_1 = require("./number");
32
+ const string_1 = require("./string");
33
+ /**
34
+ * A {@link Validation.Classes.StringValidator | StringValidator} which validates a string in place.
35
+ * @public
36
+ */
37
+ exports.string = new string_1.StringValidator();
38
+ /**
39
+ * A {@link Validation.Classes.NumberValidator | NumberValidator} which validates a number in place.
40
+ * @public
41
+ */
42
+ exports.number = new number_1.NumberValidator();
43
+ /**
44
+ * A {@link Validation.Classes.BooleanValidator | BooleanValidator} which validates a boolean in place.
45
+ * @public
46
+ */
47
+ exports.boolean = new boolean_1.BooleanValidator();
48
+ /**
49
+ * Helper function to create a {@link Validation.Classes.ObjectValidator | ObjectValidator} which validates
50
+ * an object in place.
51
+ * @param fields - A {@link Validation.Classes.FieldValidators | field validator definition}
52
+ * describing the validations to be applied.
53
+ * @param params - Optional {@link Validation.Classes.ObjectValidatorConstructorParams | parameters}
54
+ * to refine the behavior of the resulting {@link Validation.Validator | validator}.
55
+ * @returns A new {@link Validation.Validator | Validator} which validates the desired
56
+ * object in place.
57
+ * @public
58
+ */
59
+ function object(fields, params) {
60
+ return new object_1.ObjectValidator(Object.assign({ fields }, (params !== null && params !== void 0 ? params : {})));
61
+ }
62
+ exports.object = object;
63
+ /**
64
+ * Helper function to create a {@link Validation.Classes.ArrayValidator | ArrayValidator} which
65
+ * validates an array in place.
66
+ * @param validateElement - A {@link Validation.Validator | validator} which validates each element.
67
+ * @returns A new {@link Validation.Classes.ArrayValidator | ArrayValidator } which validates the desired
68
+ * array in place.
69
+ * @public
70
+ */
71
+ function arrayOf(validateElement, params) {
72
+ return new array_1.ArrayValidator(Object.assign({ validateElement }, (params !== null && params !== void 0 ? params : {})));
73
+ }
74
+ exports.arrayOf = arrayOf;
75
+ /**
76
+ * Helper function to create a {@link Validation.Validator} which validates an enumerated
77
+ * value in place.
78
+ * @public
79
+ */
80
+ function enumeratedValue(values) {
81
+ return new genericValidator_1.GenericValidator({
82
+ validator: (from, context) => {
83
+ if (typeof from === 'string') {
84
+ const v = context !== null && context !== void 0 ? context : values;
85
+ const index = v.indexOf(from);
86
+ return index >= 0 ? true : (0, base_1.fail)(`Invalid enumerated value "${from}" - expected: (${v.join(', ')})`);
87
+ }
88
+ return (0, base_1.fail)(`Not a string: "${JSON.stringify(from, undefined, 2)}`);
89
+ }
90
+ });
91
+ }
92
+ exports.enumeratedValue = enumeratedValue;
93
+ /**
94
+ * Helper function to create a {@link Validation.Validator} which validates a literal value.
95
+ * @param value - the literal value to be validated
96
+ * @public
97
+ */
98
+ function literal(value) {
99
+ return new genericValidator_1.GenericValidator({
100
+ validator: (from) => {
101
+ return from === value
102
+ ? true
103
+ : (0, base_1.fail)(`Expected literal ${String(value)}, found "${JSON.stringify(from, undefined, 2)}`);
104
+ }
105
+ });
106
+ }
107
+ exports.literal = literal;
108
+ /**
109
+ * Helper function to create a {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator} which
110
+ * validates a value or object in place.
111
+ * @param description - a description of the thing to be validated for use in error messages
112
+ * @param guard - a {@link Validation.TypeGuardWithContext} which performs the validation.
113
+ * @returns A new {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator } which validates
114
+ * the values using the supplied type guard.
115
+ * @public
116
+ */
117
+ function isA(description, guard, params) {
118
+ return new typeGuard_1.TypeGuardValidator(Object.assign({ description, guard }, (params !== null && params !== void 0 ? params : {})));
119
+ }
120
+ exports.isA = isA;
121
+ //# sourceMappingURL=validators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.js","sourceRoot":"","sources":["../../../src/packlets/validation/validators.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAAwC;AACxC,mCAA0E;AAC1E,qCAA8F;AAC9F,2CAAsF;AAEtF,uCAA6C;AAE7C,yDAAsD;AACtD,qCAA2C;AAC3C,qCAA2C;AAG3C;;;GAGG;AACU,QAAA,MAAM,GAAsB,IAAI,wBAAe,EAAE,CAAC;AAE/D;;;GAGG;AACU,QAAA,MAAM,GAAsB,IAAI,wBAAe,EAAE,CAAC;AAE/D;;;GAGG;AACU,QAAA,OAAO,GAAuB,IAAI,0BAAgB,EAAE,CAAC;AAElE;;;;;;;;;;GAUG;AACH,SAAgB,MAAM,CACpB,MAA8B,EAC9B,MAAgE;IAEhE,OAAO,IAAI,wBAAe,iBAAG,MAAM,IAAK,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,EAAG,CAAC;AAC5D,CAAC;AALD,wBAKC;AAED;;;;;;;GAOG;AACH,SAAgB,OAAO,CACrB,eAAiC,EACjC,MAAwE;IAExE,OAAO,IAAI,sBAAc,iBAAG,eAAe,IAAK,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,EAAG,CAAC;AACpE,CAAC;AALD,0BAKC;AAED;;;;GAIG;AACH,SAAgB,eAAe,CAAmB,MAAW;IAC3D,OAAO,IAAI,mCAAgB,CAAC;QAC1B,SAAS,EAAE,CAAC,IAAa,EAAE,OAAa,EAAwB,EAAE;YAChE,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;gBAC5B,MAAM,CAAC,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,MAAM,CAAC;gBAC5B,MAAM,KAAK,GAAG,CAAC,CAAC,OAAO,CAAC,IAAS,CAAC,CAAC;gBACnC,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAA,WAAI,EAAC,6BAA6B,IAAI,mBAAmB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;aACtG;YACD,OAAO,IAAA,WAAI,EAAC,kBAAkB,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;QACtE,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAXD,0CAWC;AAED;;;;GAIG;AACH,SAAgB,OAAO,CACrB,KAAQ;IAER,OAAO,IAAI,mCAAgB,CAAC;QAC1B,SAAS,EAAE,CAAC,IAAa,EAAwB,EAAE;YACjD,OAAO,IAAI,KAAK,KAAK;gBACnB,CAAC,CAAC,IAAI;gBACN,CAAC,CAAC,IAAA,WAAI,EAAC,oBAAoB,MAAM,CAAC,KAAK,CAAC,YAAY,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;QAC9F,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAVD,0BAUC;AAED;;;;;;;;GAQG;AACH,SAAgB,GAAG,CACjB,WAAmB,EACnB,KAAkC,EAClC,MAAkF;IAElF,OAAO,IAAI,8BAAkB,iBAAG,WAAW,EAAE,KAAK,IAAK,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,EAAG,CAAC;AAC3E,CAAC;AAND,kBAMC","sourcesContent":["/*\n * Copyright (c) 2023 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Failure, fail } from '../base';\nimport { ArrayValidator, ArrayValidatorConstructorParams } from './array';\nimport { FieldValidators, ObjectValidator, ObjectValidatorConstructorParams } from './object';\nimport { TypeGuardValidator, TypeGuardValidatorConstructorParams } from './typeGuard';\n\nimport { BooleanValidator } from './boolean';\nimport { TypeGuardWithContext } from './common';\nimport { GenericValidator } from './genericValidator';\nimport { NumberValidator } from './number';\nimport { StringValidator } from './string';\nimport { Validator } from './validator';\n\n/**\n * A {@link Validation.Classes.StringValidator | StringValidator} which validates a string in place.\n * @public\n */\nexport const string: Validator<string> = new StringValidator();\n\n/**\n * A {@link Validation.Classes.NumberValidator | NumberValidator} which validates a number in place.\n * @public\n */\nexport const number: Validator<number> = new NumberValidator();\n\n/**\n * A {@link Validation.Classes.BooleanValidator | BooleanValidator} which validates a boolean in place.\n * @public\n */\nexport const boolean: Validator<boolean> = new BooleanValidator();\n\n/**\n * Helper function to create a {@link Validation.Classes.ObjectValidator | ObjectValidator} which validates\n * an object in place.\n * @param fields - A {@link Validation.Classes.FieldValidators | field validator definition}\n * describing the validations to be applied.\n * @param params - Optional {@link Validation.Classes.ObjectValidatorConstructorParams | parameters}\n * to refine the behavior of the resulting {@link Validation.Validator | validator}.\n * @returns A new {@link Validation.Validator | Validator} which validates the desired\n * object in place.\n * @public\n */\nexport function object<T, TC = unknown>(\n fields: FieldValidators<T, TC>,\n params?: Omit<ObjectValidatorConstructorParams<T, TC>, 'fields'>\n): ObjectValidator<T, TC> {\n return new ObjectValidator({ fields, ...(params ?? {}) });\n}\n\n/**\n * Helper function to create a {@link Validation.Classes.ArrayValidator | ArrayValidator} which\n * validates an array in place.\n * @param validateElement - A {@link Validation.Validator | validator} which validates each element.\n * @returns A new {@link Validation.Classes.ArrayValidator | ArrayValidator } which validates the desired\n * array in place.\n * @public\n */\nexport function arrayOf<T, TC>(\n validateElement: Validator<T, TC>,\n params?: Omit<ArrayValidatorConstructorParams<T, TC>, 'validateElement'>\n): ArrayValidator<T, TC> {\n return new ArrayValidator({ validateElement, ...(params ?? {}) });\n}\n\n/**\n * Helper function to create a {@link Validation.Validator} which validates an enumerated\n * value in place.\n * @public\n */\nexport function enumeratedValue<T extends string>(values: T[]): Validator<T, T[]> {\n return new GenericValidator({\n validator: (from: unknown, context?: T[]): boolean | Failure<T> => {\n if (typeof from === 'string') {\n const v = context ?? values;\n const index = v.indexOf(from as T);\n return index >= 0 ? true : fail(`Invalid enumerated value \"${from}\" - expected: (${v.join(', ')})`);\n }\n return fail(`Not a string: \"${JSON.stringify(from, undefined, 2)}`);\n }\n });\n}\n\n/**\n * Helper function to create a {@link Validation.Validator} which validates a literal value.\n * @param value - the literal value to be validated\n * @public\n */\nexport function literal<T extends string | number | boolean | symbol | null | undefined>(\n value: T\n): Validator<T> {\n return new GenericValidator({\n validator: (from: unknown): boolean | Failure<T> => {\n return from === value\n ? true\n : fail(`Expected literal ${String(value)}, found \"${JSON.stringify(from, undefined, 2)}`);\n }\n });\n}\n\n/**\n * Helper function to create a {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator} which\n * validates a value or object in place.\n * @param description - a description of the thing to be validated for use in error messages\n * @param guard - a {@link Validation.TypeGuardWithContext} which performs the validation.\n * @returns A new {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator } which validates\n * the values using the supplied type guard.\n * @public\n */\nexport function isA<T, TC>(\n description: string,\n guard: TypeGuardWithContext<T, TC>,\n params?: Omit<TypeGuardValidatorConstructorParams<T, TC>, 'description' | 'guard'>\n): TypeGuardValidator<T, TC> {\n return new TypeGuardValidator({ description, guard, ...(params ?? {}) });\n}\n"]}
package/package.json CHANGED
@@ -1,27 +1,20 @@
1
1
  {
2
2
  "name": "@fgv/ts-utils",
3
- "version": "1.9.4",
3
+ "version": "2.0.1-alpha.0",
4
4
  "description": "Assorted Typescript Utilities",
5
- "main": "index.js",
5
+ "main": "lib/index.js",
6
+ "types": "dist/ts-utils.d.ts",
6
7
  "scripts": {
7
- "api-extractor": "$(npm bin)/api-extractor run --local --verbose -c ./config/api-extractor.json",
8
- "build": "rimraf dist && tsc && ./prep.sh",
9
- "build-docs": "$(npm bin)/api-documenter markdown --input-folder ./temp --output-folder docs",
10
- "build-all": "npm run build; npm run api-extractor; npm run build-docs",
11
- "clean": "rimraf dist",
12
- "test": "jest",
8
+ "build": "heft test --clean",
9
+ "clean": "heft clean",
10
+ "test": "heft test",
11
+ "build-docs": "api-documenter markdown --input-folder ./temp --output-folder docs",
12
+ "build-all": "rushx build; rushx build-docs",
13
13
  "test-handles": "jest --runInBand --detectOpenHandles",
14
14
  "clean-jest": "jest --clear-cache",
15
15
  "coverage": "jest --coverage",
16
- "lint": "eslint src test/unit --ext .ts",
17
- "fixlint": "eslint src test/unit --ext .ts --fix"
18
- },
19
- "repository": {
20
- "type": "git",
21
- "url": "git+https://github.com/DidjaRedo/ts-utils.git"
22
- },
23
- "publishConfig": {
24
- "registry": "https://registry.npmjs.org"
16
+ "lint": "eslint src --ext .ts",
17
+ "fixlint": "eslint src --ext .ts --fix"
25
18
  },
26
19
  "keywords": [
27
20
  "typescript",
@@ -30,9 +23,9 @@
30
23
  "author": "Erik Fortune",
31
24
  "license": "MIT",
32
25
  "bugs": {
33
- "url": "https://github.com/DidjaRedo/ts-utils/issues"
26
+ "url": "https://github.com/ErikFortune/fgv/issues"
34
27
  },
35
- "homepage": "https://github.com/DidjaRedo/ts-utils#readme",
28
+ "homepage": "https://github.com/ErikFortune/fgv#readme",
36
29
  "devDependencies": {
37
30
  "@jest/expect-utils": "^29.5.0",
38
31
  "@microsoft/api-documenter": "^7.21.6",
@@ -55,7 +48,15 @@
55
48
  "rimraf": "^4.4.1",
56
49
  "ts-jest": "^29.0.5",
57
50
  "ts-node": "^10.9.1",
58
- "typescript": "^4.9.5"
51
+ "typescript": "^4.9.5",
52
+ "eslint-plugin-n": "^15.0.0",
53
+ "jest-snapshot": "~29.5.0",
54
+ "@rushstack/heft": "~0.50.0",
55
+ "@rushstack/heft-node-rig": "~1.12.5",
56
+ "@rushstack/eslint-config": "~3.2.0",
57
+ "@types/heft-jest": "1.0.3",
58
+ "@rushstack/heft-jest-plugin": "~0.5.5",
59
+ "eslint-plugin-tsdoc": "~0.2.17"
59
60
  },
60
61
  "dependencies": {
61
62
  "luxon": "^3.3.0",
package/brand.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"brand.d.ts","sourceRoot":"","sources":["../src/brand.ts"],"names":[],"mappings":"AAsBA;;;GAGG;AAEH,MAAM,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAAE,OAAO,EAAE,CAAC,CAAA;CAAE,CAAC"}
package/brand.js DELETED
@@ -1,24 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2021 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
- Object.defineProperty(exports, "__esModule", { value: true });
24
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnJhbmQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvYnJhbmQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBOzs7Ozs7Ozs7Ozs7Ozs7Ozs7OztHQW9CRyIsInNvdXJjZXNDb250ZW50IjpbIi8qXG4gKiBDb3B5cmlnaHQgKGMpIDIwMjEgRXJpayBGb3J0dW5lXG4gKlxuICogUGVybWlzc2lvbiBpcyBoZXJlYnkgZ3JhbnRlZCwgZnJlZSBvZiBjaGFyZ2UsIHRvIGFueSBwZXJzb24gb2J0YWluaW5nIGEgY29weVxuICogb2YgdGhpcyBzb2Z0d2FyZSBhbmQgYXNzb2NpYXRlZCBkb2N1bWVudGF0aW9uIGZpbGVzICh0aGUgXCJTb2Z0d2FyZVwiKSwgdG8gZGVhbFxuICogaW4gdGhlIFNvZnR3YXJlIHdpdGhvdXQgcmVzdHJpY3Rpb24sIGluY2x1ZGluZyB3aXRob3V0IGxpbWl0YXRpb24gdGhlIHJpZ2h0c1xuICogdG8gdXNlLCBjb3B5LCBtb2RpZnksIG1lcmdlLCBwdWJsaXNoLCBkaXN0cmlidXRlLCBzdWJsaWNlbnNlLCBh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