@fgv/ts-utils 1.9.4 → 2.0.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,97 @@
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.StringConverter = void 0;
25
+ const base_1 = require("../base");
26
+ const converter_1 = require("./converter");
27
+ /**
28
+ * The {@link Conversion.StringConverter | StringConverter} class extends
29
+ * {@link Conversion.BaseConverter | BaseConverter} to provide string-specific
30
+ * helper methods.
31
+ * @public
32
+ */
33
+ class StringConverter extends converter_1.BaseConverter {
34
+ /**
35
+ * Construct a new {@link Conversion.StringConverter | StringConverter}.
36
+ * @param defaultContext - Optional context used by the conversion.
37
+ * @param traits - Optional traits to be applied to the conversion.
38
+ * @param converter - Optional conversion function to be used for the conversion.
39
+ */
40
+ constructor(defaultContext, traits, converter = StringConverter._convert) {
41
+ super(converter, defaultContext, traits);
42
+ }
43
+ /**
44
+ * @internal
45
+ */
46
+ static _convert(from) {
47
+ return typeof from === 'string' ? (0, base_1.succeed)(from) : (0, base_1.fail)(`Not a string: ${JSON.stringify(from)}`);
48
+ }
49
+ /**
50
+ * @internal
51
+ */
52
+ static _wrap(wrapped, converter, traits) {
53
+ return new StringConverter(undefined, undefined, (from) => {
54
+ return wrapped.convert(from).onSuccess(converter);
55
+ })._with(wrapped._traits(traits));
56
+ }
57
+ /**
58
+ * Concrete implementation of {@link Conversion.StringConverter.matching#string | StringConverter.matching(string)},
59
+ * {@link Conversion.StringConverter.matching#array | StringConverter.matching(string[])},
60
+ * {@link Conversion.StringConverter.matching#set | StringConverter.matching(Set<string>)}, and
61
+ * {@link Conversion.StringConverter.matching#regexp | StringConverter.matching(RegExp)}.
62
+ * @internal
63
+ */
64
+ matching(match, options) {
65
+ const message = options === null || options === void 0 ? void 0 : options.message;
66
+ if (typeof match === 'string') {
67
+ return StringConverter._wrap(this, (from) => {
68
+ return match === from
69
+ ? (0, base_1.succeed)(from)
70
+ : (0, base_1.fail)(message ? `"${from}": ${message}` : `"${from}": does not match "${match}"`);
71
+ });
72
+ }
73
+ else if (match instanceof RegExp) {
74
+ return StringConverter._wrap(this, (from) => {
75
+ return match.test(from)
76
+ ? (0, base_1.succeed)(from)
77
+ : (0, base_1.fail)(message ? `"${from}": ${message}` : `"${from}": does not match "${match}"`);
78
+ });
79
+ }
80
+ else if (match instanceof Set) {
81
+ return StringConverter._wrap(this, (from) => {
82
+ return match.has(from)
83
+ ? (0, base_1.succeed)(from)
84
+ : (0, base_1.fail)(message ? `"${from}": ${message}` : `"${from}": not found in set`);
85
+ });
86
+ }
87
+ else {
88
+ return StringConverter._wrap(this, (from) => {
89
+ return match.includes(from)
90
+ ? (0, base_1.succeed)(from)
91
+ : (0, base_1.fail)(message ? `"${from}": ${message}` : `"${from}": not found in [${match.join(',')}]`);
92
+ });
93
+ }
94
+ }
95
+ }
96
+ exports.StringConverter = StringConverter;
97
+ //# sourceMappingURL=stringConverter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stringConverter.js","sourceRoot":"","sources":["../../../src/packlets/conversion/stringConverter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAAgD;AAChD,2CAAwE;AAiBxE;;;;;GAKG;AACH,MAAa,eAAyD,SAAQ,yBAAoB;IAChG;;;;;OAKG;IACH,YACE,cAAmB,EACnB,MAAwB,EACxB,YAAgF,eAAe,CAAC,QAAQ;QAExG,KAAK,CAAC,SAAS,EAAE,cAAc,EAAE,MAAM,CAAC,CAAC;IAC3C,CAAC;IAED;;OAEG;IACO,MAAM,CAAC,QAAQ,CAAmB,IAAa;QACvD,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAA,cAAO,EAAC,IAAS,CAAC,CAAC,CAAC,CAAC,IAAA,WAAI,EAAC,iBAAiB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACvG,CAAC;IAED;;OAEG;IACO,MAAM,CAAC,KAAK,CACpB,OAA+B,EAC/B,SAAiC,EACjC,MAAwB;QAExB,OAAO,IAAI,eAAe,CAAQ,SAAS,EAAE,SAAS,EAAE,CAAC,IAAa,EAAE,EAAE;YACxE,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IACpC,CAAC;IA8CD;;;;;;OAMG;IACI,QAAQ,CACb,KAA0C,EAC1C,OAAqC;QAErC,MAAM,OAAO,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,CAAC;QACjC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,OAAO,eAAe,CAAC,KAAK,CAAQ,IAAI,EAAE,CAAC,IAAO,EAAE,EAAE;gBACpD,OAAO,KAAK,KAAK,IAAI;oBACnB,CAAC,CAAC,IAAA,cAAO,EAAC,IAAS,CAAC;oBACpB,CAAC,CAAC,IAAA,WAAI,EAAC,OAAO,CAAC,CAAC,CAAC,IAAI,IAAI,MAAM,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,sBAAsB,KAAK,GAAG,CAAC,CAAC;YACvF,CAAC,CAAC,CAAC;SACJ;aAAM,IAAI,KAAK,YAAY,MAAM,EAAE;YAClC,OAAO,eAAe,CAAC,KAAK,CAAQ,IAAI,EAAE,CAAC,IAAO,EAAE,EAAE;gBACpD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;oBACrB,CAAC,CAAC,IAAA,cAAO,EAAC,IAAS,CAAC;oBACpB,CAAC,CAAC,IAAA,WAAI,EAAC,OAAO,CAAC,CAAC,CAAC,IAAI,IAAI,MAAM,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,sBAAsB,KAAK,GAAG,CAAC,CAAC;YACvF,CAAC,CAAC,CAAC;SACJ;aAAM,IAAI,KAAK,YAAY,GAAG,EAAE;YAC/B,OAAO,eAAe,CAAC,KAAK,CAAQ,IAAI,EAAE,CAAC,IAAO,EAAE,EAAE;gBACpD,OAAO,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;oBACpB,CAAC,CAAC,IAAA,cAAO,EAAC,IAAS,CAAC;oBACpB,CAAC,CAAC,IAAA,WAAI,EAAC,OAAO,CAAC,CAAC,CAAC,IAAI,IAAI,MAAM,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,qBAAqB,CAAC,CAAC;YAC9E,CAAC,CAAC,CAAC;SACJ;aAAM;YACL,OAAO,eAAe,CAAC,KAAK,CAAQ,IAAI,EAAE,CAAC,IAAO,EAAE,EAAE;gBACpD,OAAO,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC;oBACzB,CAAC,CAAC,IAAA,cAAO,EAAC,IAAS,CAAC;oBACpB,CAAC,CAAC,IAAA,WAAI,EAAC,OAAO,CAAC,CAAC,CAAC,IAAI,IAAI,MAAM,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,oBAAoB,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC/F,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;CACF;AArHD,0CAqHC","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 { Result, fail, succeed } from '../base';\nimport { BaseConverter, Converter, ConverterTraits } from './converter';\n\n/**\n * Options for {@link Conversion.StringConverter | StringConverter}\n * matching method\n * @public\n */\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface StringMatchOptions {\n /**\n * An optional message to be displayed if a non-matching string\n * is encountered.\n */\n message?: string;\n}\n\n/**\n * The {@link Conversion.StringConverter | StringConverter} class extends\n * {@link Conversion.BaseConverter | BaseConverter} to provide string-specific\n * helper methods.\n * @public\n */\nexport class StringConverter<T extends string = string, TC = unknown> extends BaseConverter<T, TC> {\n /**\n * Construct a new {@link Conversion.StringConverter | StringConverter}.\n * @param defaultContext - Optional context used by the conversion.\n * @param traits - Optional traits to be applied to the conversion.\n * @param converter - Optional conversion function to be used for the conversion.\n */\n public constructor(\n defaultContext?: TC,\n traits?: ConverterTraits,\n converter: (from: unknown, self: Converter<T, TC>, context?: TC) => Result<T> = StringConverter._convert\n ) {\n super(converter, defaultContext, traits);\n }\n\n /**\n * @internal\n */\n protected static _convert<T extends string>(from: unknown): Result<T> {\n return typeof from === 'string' ? succeed(from as T) : fail(`Not a string: ${JSON.stringify(from)}`);\n }\n\n /**\n * @internal\n */\n protected static _wrap<T extends string, TC>(\n wrapped: StringConverter<T, TC>,\n converter: (from: T) => Result<T>,\n traits?: ConverterTraits\n ): StringConverter<T, TC> {\n return new StringConverter<T, TC>(undefined, undefined, (from: unknown) => {\n return wrapped.convert(from).onSuccess(converter);\n })._with(wrapped._traits(traits));\n }\n\n /**\n * Returns a {@link Conversion.StringConverter | StringConverter} which constrains the result to match\n * a supplied string.\n * @param match - The string to be matched\n * @param options - Optional {@link Conversion.StringMatchOptions} for this conversion.\n * @returns {@link Success} with a matching string or {@link Failure} with an informative\n * error if the string does not match.\n * {@label WITH_STRING}\n */\n public matching(match: string, options?: Partial<StringMatchOptions>): StringConverter<T, TC>;\n\n /**\n * Returns a {@link Conversion.StringConverter | StringConverter} which constrains the result to match\n * one of a supplied array of strings.\n * @param match - The array of allowed strings.\n * @param options - Optional {@link Conversion.StringMatchOptions} for this conversion.\n * @returns {@link Success} with a matching string or {@link Failure} with an informative\n * error if the string does not match.\n * {@label WITH_ARRAY}\n */\n public matching(match: string[], options?: Partial<StringMatchOptions>): StringConverter<T, TC>;\n\n /**\n * Returns a {@link Conversion.StringConverter | StringConverter} which constrains the result to match\n * one of a supplied `Set` of strings.\n * @param match - The `Set` of allowed strings.\n * @param options - Optional {@link Conversion.StringMatchOptions} for this conversion.\n * @returns {@link Success} with a matching string or {@link Failure} with an informative\n * error if the string does not match.\n * {@label WITH_SET}\n */\n public matching(match: Set<T>, options?: Partial<StringMatchOptions>): StringConverter<T, TC>;\n\n /**\n * Returns a {@link Conversion.StringConverter | StringConverter} which constrains the result to match\n * a supplied regular expression.\n * @param match - The regular expression to be used as a constraint.\n * @param options - Optional {@link Conversion.StringMatchOptions} for this conversion\n * @returns {@link Success} with a matching string or {@link Failure} with an informative\n * error if the string does not match.\n * {@label WITH_REGEXP}\n */\n public matching(match: RegExp, options?: Partial<StringMatchOptions>): StringConverter<T, TC>;\n\n /**\n * Concrete implementation of {@link Conversion.StringConverter.matching#string | StringConverter.matching(string)},\n * {@link Conversion.StringConverter.matching#array | StringConverter.matching(string[])},\n * {@link Conversion.StringConverter.matching#set | StringConverter.matching(Set<string>)}, and\n * {@link Conversion.StringConverter.matching#regexp | StringConverter.matching(RegExp)}.\n * @internal\n */\n public matching(\n match: string | string[] | Set<T> | RegExp,\n options?: Partial<StringMatchOptions>\n ): StringConverter<T, TC> {\n const message = options?.message;\n if (typeof match === 'string') {\n return StringConverter._wrap<T, TC>(this, (from: T) => {\n return match === from\n ? succeed(from as T)\n : fail(message ? `\"${from}\": ${message}` : `\"${from}\": does not match \"${match}\"`);\n });\n } else if (match instanceof RegExp) {\n return StringConverter._wrap<T, TC>(this, (from: T) => {\n return match.test(from)\n ? succeed(from as T)\n : fail(message ? `\"${from}\": ${message}` : `\"${from}\": does not match \"${match}\"`);\n });\n } else if (match instanceof Set) {\n return StringConverter._wrap<T, TC>(this, (from: T) => {\n return match.has(from)\n ? succeed(from as T)\n : fail(message ? `\"${from}\": ${message}` : `\"${from}\": not found in set`);\n });\n } else {\n return StringConverter._wrap<T, TC>(this, (from: T) => {\n return match.includes(from)\n ? succeed(from as T)\n : fail(message ? `\"${from}\": ${message}` : `\"${from}\": not found in [${match.join(',')}]`);\n });\n }\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { Result } from './result';
1
+ import { Result } from '../base';
2
2
  /**
3
3
  * Options for {@link Csv.readCsvFileSync}
4
4
  * @beta
@@ -0,0 +1 @@
1
+ {"version":3,"file":"csvHelpers.d.ts","sourceRoot":"","sources":["../../../src/packlets/csv/csvHelpers.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,MAAM,EAAiB,MAAM,SAAS,CAAC;AAEhD;;;GAGG;AAEH,MAAM,WAAW,UAAU;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,CActF"}
@@ -0,0 +1,69 @@
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
24
+ if (k2 === undefined) k2 = k;
25
+ var desc = Object.getOwnPropertyDescriptor(m, k);
26
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
27
+ desc = { enumerable: true, get: function() { return m[k]; } };
28
+ }
29
+ Object.defineProperty(o, k2, desc);
30
+ }) : (function(o, m, k, k2) {
31
+ if (k2 === undefined) k2 = k;
32
+ o[k2] = m[k];
33
+ }));
34
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
35
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
36
+ }) : function(o, v) {
37
+ o["default"] = v;
38
+ });
39
+ var __importStar = (this && this.__importStar) || function (mod) {
40
+ if (mod && mod.__esModule) return mod;
41
+ var result = {};
42
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
43
+ __setModuleDefault(result, mod);
44
+ return result;
45
+ };
46
+ Object.defineProperty(exports, "__esModule", { value: true });
47
+ exports.readCsvFileSync = void 0;
48
+ const fs = __importStar(require("fs"));
49
+ const papaparse_1 = require("papaparse");
50
+ const path = __importStar(require("path"));
51
+ const base_1 = require("../base");
52
+ /**
53
+ * Reads a CSV file from a supplied path.
54
+ * @param srcPath - Source path from which the file is read.
55
+ * @param options - optional parameters to control the processing
56
+ * @returns The contents of the file.
57
+ * @beta
58
+ */
59
+ function readCsvFileSync(srcPath, options) {
60
+ return (0, base_1.captureResult)(() => {
61
+ const fullPath = path.resolve(srcPath);
62
+ const body = fs.readFileSync(fullPath, 'utf8').toString();
63
+ options = options !== null && options !== void 0 ? options : {};
64
+ // eslint-disable-next-line
65
+ return (0, papaparse_1.parse)(body, Object.assign({ transform: (s) => s.trim(), header: false, dynamicTyping: false, skipEmptyLines: 'greedy' }, options)).data.slice(1);
66
+ });
67
+ }
68
+ exports.readCsvFileSync = readCsvFileSync;
69
+ //# sourceMappingURL=csvHelpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"csvHelpers.js","sourceRoot":"","sources":["../../../src/packlets/csv/csvHelpers.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,uCAAyB;AACzB,yCAAkC;AAClC,2CAA6B;AAC7B,kCAAgD;AAWhD;;;;;;GAMG;AACH,SAAgB,eAAe,CAAC,OAAe,EAAE,OAAoB;IACnE,OAAO,IAAA,oBAAa,EAAC,GAAG,EAAE;QACxB,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACvC,MAAM,IAAI,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC;QAC1D,OAAO,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAC;QACxB,2BAA2B;QAC3B,OAAO,IAAA,iBAAK,EAAC,IAAI,kBACf,SAAS,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,EAClC,MAAM,EAAE,KAAK,EACb,aAAa,EAAE,KAAK,EACpB,cAAc,EAAE,QAAQ,IACrB,OAAO,EACV,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC;AAdD,0CAcC","sourcesContent":["/*\n * Copyright (c) 2020 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 * as fs from 'fs';\nimport { parse } from 'papaparse';\nimport * as path from 'path';\nimport { Result, captureResult } from '../base';\n\n/**\n * Options for {@link Csv.readCsvFileSync}\n * @beta\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface CsvOptions {\n delimiter?: string;\n}\n\n/**\n * Reads a CSV file from a supplied path.\n * @param srcPath - Source path from which the file is read.\n * @param options - optional parameters to control the processing\n * @returns The contents of the file.\n * @beta\n */\nexport function readCsvFileSync(srcPath: string, options?: CsvOptions): Result<unknown> {\n return captureResult(() => {\n const fullPath = path.resolve(srcPath);\n const body = fs.readFileSync(fullPath, 'utf8').toString();\n options = options ?? {};\n // eslint-disable-next-line\n return parse(body, {\n transform: (s: string) => s.trim(),\n header: false,\n dynamicTyping: false,\n skipEmptyLines: 'greedy',\n ...options\n }).data.slice(1);\n });\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export * from './csvHelpers';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/csv/index.ts"],"names":[],"mappings":"AAsBA,cAAc,cAAc,CAAC"}
@@ -0,0 +1,39 @@
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
24
+ if (k2 === undefined) k2 = k;
25
+ var desc = Object.getOwnPropertyDescriptor(m, k);
26
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
27
+ desc = { enumerable: true, get: function() { return m[k]; } };
28
+ }
29
+ Object.defineProperty(o, k2, desc);
30
+ }) : (function(o, m, k, k2) {
31
+ if (k2 === undefined) k2 = k;
32
+ o[k2] = m[k];
33
+ }));
34
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
35
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ __exportStar(require("./csvHelpers"), exports);
39
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/csv/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;AAEH,+CAA6B","sourcesContent":["/*\n * Copyright (c) 2020 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\nexport * from './csvHelpers';\n"]}
@@ -1,4 +1,4 @@
1
- import { Result } from './result';
1
+ import { Result } from '../base';
2
2
  /**
3
3
  * An experimental array template which extend built-in `Array` to include a handful
4
4
  * of predicates which return {@link Result | Result<T>}.
@@ -7,16 +7,16 @@ import { Result } from './result';
7
7
  export declare class ExtendedArray<T> extends Array<T> {
8
8
  readonly itemDescription: string;
9
9
  /**
10
- * Constructs an {@link ExtendedArray}.
10
+ * Constructs an {@link Experimental.ExtendedArray}.
11
11
  * @param itemDescription - Brief description of the type of each item in this array.
12
12
  * @param items - The initial contents of the array.
13
13
  */
14
14
  constructor(itemDescription: string, ...items: T[]);
15
15
  /**
16
16
  * Type guard to determine if some arbitrary array is an
17
- * {@link ExtendedArray}
17
+ * {@link Experimental.ExtendedArray}
18
18
  * @param a - The `Array` to be tested.
19
- * @returns Returns `true` if `a` is an {@link ExtendedArray},
19
+ * @returns Returns `true` if `a` is an {@link Experimental.ExtendedArray},
20
20
  * `false` otherwise.
21
21
  */
22
22
  static isExtendedArray<T>(a?: T[]): a is ExtendedArray<T>;
@@ -30,7 +30,7 @@ export declare class ExtendedArray<T> extends Array<T> {
30
30
  */
31
31
  single(predicate?: (item: T) => boolean): Result<T>;
32
32
  /**
33
- * Returns the first element of an {@link ExtendedArray}. Fails with an
33
+ * Returns the first element of an {@link Experimental.ExtendedArray}. Fails with an
34
34
  * error message if the array is empty.
35
35
  * @param failMessage - Optional message to be displayed in the event of failure.
36
36
  * @returns Returns {@link Success | Success<T>} with the value of the first element
@@ -38,7 +38,7 @@ export declare class ExtendedArray<T> extends Array<T> {
38
38
  */
39
39
  first(failMessage?: string): Result<T>;
40
40
  /**
41
- * Returns an array containing all elements of an {@link ExtendedArray}. Fails with
41
+ * Returns an array containing all elements of an {@link Experimental.ExtendedArray}. Fails with
42
42
  * an error message if the array is empty.
43
43
  * @param failMessage - Optional message to be displayed in the event of failure.
44
44
  * @returns Returns {@link Success | Success<T[]>} with a new (non-extended) `Array`
@@ -48,7 +48,7 @@ export declare class ExtendedArray<T> extends Array<T> {
48
48
  atLeastOne(failMessage?: string): Result<T[]>;
49
49
  /**
50
50
  * Gets a new (non-extended) `Array` containing all of the elements from this
51
- * {@link ExtendedArray}.
51
+ * {@link Experimental.ExtendedArray}.
52
52
  * @returns A new (non-extended) `Array<T>`.
53
53
  */
54
54
  all(): T[];
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extendedArray.d.ts","sourceRoot":"","sources":["../../../src/packlets/experimental/extendedArray.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,MAAM,EAAiB,MAAM,SAAS,CAAC;AAEhD;;;;GAIG;AACH,qBAAa,aAAa,CAAC,CAAC,CAAE,SAAQ,KAAK,CAAC,CAAC,CAAC;IAC5C,SAAgB,eAAe,EAAE,MAAM,CAAC;IAExC;;;;OAIG;gBACgB,eAAe,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,CAAC,EAAE;IAKzD;;;;;;OAMG;WACW,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC;IAIhE;;;;;;;OAOG;IACI,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC;IAW1D;;;;;;OAMG;IACI,KAAK,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC;IAO7C;;;;;;;OAOG;IACI,UAAU,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC;IAOpD;;;;OAIG;IACI,GAAG,IAAI,CAAC,EAAE;CAGlB"}
@@ -0,0 +1,106 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.ExtendedArray = void 0;
25
+ const base_1 = require("../base");
26
+ /**
27
+ * An experimental array template which extend built-in `Array` to include a handful
28
+ * of predicates which return {@link Result | Result<T>}.
29
+ * @beta
30
+ */
31
+ class ExtendedArray extends Array {
32
+ /**
33
+ * Constructs an {@link Experimental.ExtendedArray}.
34
+ * @param itemDescription - Brief description of the type of each item in this array.
35
+ * @param items - The initial contents of the array.
36
+ */
37
+ constructor(itemDescription, ...items) {
38
+ super(...items);
39
+ this.itemDescription = itemDescription;
40
+ }
41
+ /**
42
+ * Type guard to determine if some arbitrary array is an
43
+ * {@link Experimental.ExtendedArray}
44
+ * @param a - The `Array` to be tested.
45
+ * @returns Returns `true` if `a` is an {@link Experimental.ExtendedArray},
46
+ * `false` otherwise.
47
+ */
48
+ static isExtendedArray(a) {
49
+ return a instanceof ExtendedArray;
50
+ }
51
+ /**
52
+ * Determines if this array contains exactly one element which matches
53
+ * a supplied predicate.
54
+ * @param predicate - The predicate function to be applied.
55
+ * @returns Returns {@link Success | Success<T>} with the single matching
56
+ * result if exactly one item matches `predicate`. Returns {@link Failure}
57
+ * with an error message if there are no matches or more than one match.
58
+ */
59
+ single(predicate) {
60
+ const match = predicate ? this.filter(predicate) : this;
61
+ if (match.length === 1) {
62
+ return (0, base_1.succeed)(match[0]);
63
+ }
64
+ if (match.length === 0) {
65
+ return (0, base_1.fail)(`${this.itemDescription} not found`);
66
+ }
67
+ return (0, base_1.fail)(`${this.itemDescription} matches ${match.length} items`);
68
+ }
69
+ /**
70
+ * Returns the first element of an {@link Experimental.ExtendedArray}. Fails with an
71
+ * error message if the array is empty.
72
+ * @param failMessage - Optional message to be displayed in the event of failure.
73
+ * @returns Returns {@link Success | Success<T>} with the value of the first element
74
+ * in the array, or {@link Failure} with an error message if the array is empty.
75
+ */
76
+ first(failMessage) {
77
+ if (this.length > 0) {
78
+ return (0, base_1.succeed)(this[0]);
79
+ }
80
+ return (0, base_1.fail)(failMessage !== null && failMessage !== void 0 ? failMessage : `${this.itemDescription} not found`);
81
+ }
82
+ /**
83
+ * Returns an array containing all elements of an {@link Experimental.ExtendedArray}. Fails with
84
+ * an error message if the array is empty.
85
+ * @param failMessage - Optional message to be displayed in the event of failure.
86
+ * @returns Returns {@link Success | Success<T[]>} with a new (non-extended) `Array`
87
+ * containing the elements of this array, or {@link Failure} with an error message
88
+ * if the array is empty.
89
+ */
90
+ atLeastOne(failMessage) {
91
+ if (this.length > 0) {
92
+ return (0, base_1.succeed)(Array.from(this));
93
+ }
94
+ return (0, base_1.fail)(failMessage !== null && failMessage !== void 0 ? failMessage : `${this.itemDescription} not found`);
95
+ }
96
+ /**
97
+ * Gets a new (non-extended) `Array` containing all of the elements from this
98
+ * {@link Experimental.ExtendedArray}.
99
+ * @returns A new (non-extended) `Array<T>`.
100
+ */
101
+ all() {
102
+ return Array.from(this);
103
+ }
104
+ }
105
+ exports.ExtendedArray = ExtendedArray;
106
+ //# sourceMappingURL=extendedArray.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extendedArray.js","sourceRoot":"","sources":["../../../src/packlets/experimental/extendedArray.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAAgD;AAEhD;;;;GAIG;AACH,MAAa,aAAiB,SAAQ,KAAQ;IAG5C;;;;OAIG;IACH,YAAmB,eAAuB,EAAE,GAAG,KAAU;QACvD,KAAK,CAAC,GAAG,KAAK,CAAC,CAAC;QAChB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IACzC,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,eAAe,CAAI,CAAO;QACtC,OAAO,CAAC,YAAY,aAAa,CAAC;IACpC,CAAC;IAED;;;;;;;OAOG;IACI,MAAM,CAAC,SAAgC;QAC5C,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACxD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;YACtB,OAAO,IAAA,cAAO,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;SAC1B;QACD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;YACtB,OAAO,IAAA,WAAI,EAAC,GAAG,IAAI,CAAC,eAAe,YAAY,CAAC,CAAC;SAClD;QACD,OAAO,IAAA,WAAI,EAAC,GAAG,IAAI,CAAC,eAAe,YAAY,KAAK,CAAC,MAAM,QAAQ,CAAC,CAAC;IACvE,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,WAAoB;QAC/B,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;YACnB,OAAO,IAAA,cAAO,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;SACzB;QACD,OAAO,IAAA,WAAI,EAAC,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,GAAG,IAAI,CAAC,eAAe,YAAY,CAAC,CAAC;IAClE,CAAC;IAED;;;;;;;OAOG;IACI,UAAU,CAAC,WAAoB;QACpC,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;YACnB,OAAO,IAAA,cAAO,EAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;SAClC;QACD,OAAO,IAAA,WAAI,EAAC,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,GAAG,IAAI,CAAC,eAAe,YAAY,CAAC,CAAC;IAClE,CAAC;IAED;;;;OAIG;IACI,GAAG;QACR,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CACF;AAhFD,sCAgFC","sourcesContent":["/*\r\n * Copyright (c) 2020 Erik Fortune\r\n *\r\n * Permission is hereby granted, free of charge, to any person obtaining a copy\r\n * of this software and associated documentation files (the \"Software\"), to deal\r\n * in the Software without restriction, including without limitation the rights\r\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n * copies of the Software, and to permit persons to whom the Software is\r\n * furnished to do so, subject to the following conditions:\r\n *\r\n * The above copyright notice and this permission notice shall be included in all\r\n * copies or substantial portions of the Software.\r\n *\r\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n * SOFTWARE.\r\n */\r\n\r\nimport { Result, fail, succeed } from '../base';\r\n\r\n/**\r\n * An experimental array template which extend built-in `Array` to include a handful\r\n * of predicates which return {@link Result | Result<T>}.\r\n * @beta\r\n */\r\nexport class ExtendedArray<T> extends Array<T> {\r\n public readonly itemDescription: string;\r\n\r\n /**\r\n * Constructs an {@link Experimental.ExtendedArray}.\r\n * @param itemDescription - Brief description of the type of each item in this array.\r\n * @param items - The initial contents of the array.\r\n */\r\n public constructor(itemDescription: string, ...items: T[]) {\r\n super(...items);\r\n this.itemDescription = itemDescription;\r\n }\r\n\r\n /**\r\n * Type guard to determine if some arbitrary array is an\r\n * {@link Experimental.ExtendedArray}\r\n * @param a - The `Array` to be tested.\r\n * @returns Returns `true` if `a` is an {@link Experimental.ExtendedArray},\r\n * `false` otherwise.\r\n */\r\n public static isExtendedArray<T>(a?: T[]): a is ExtendedArray<T> {\r\n return a instanceof ExtendedArray;\r\n }\r\n\r\n /**\r\n * Determines if this array contains exactly one element which matches\r\n * a supplied predicate.\r\n * @param predicate - The predicate function to be applied.\r\n * @returns Returns {@link Success | Success<T>} with the single matching\r\n * result if exactly one item matches `predicate`. Returns {@link Failure}\r\n * with an error message if there are no matches or more than one match.\r\n */\r\n public single(predicate?: (item: T) => boolean): Result<T> {\r\n const match = predicate ? this.filter(predicate) : this;\r\n if (match.length === 1) {\r\n return succeed(match[0]);\r\n }\r\n if (match.length === 0) {\r\n return fail(`${this.itemDescription} not found`);\r\n }\r\n return fail(`${this.itemDescription} matches ${match.length} items`);\r\n }\r\n\r\n /**\r\n * Returns the first element of an {@link Experimental.ExtendedArray}. Fails with an\r\n * error message if the array is empty.\r\n * @param failMessage - Optional message to be displayed in the event of failure.\r\n * @returns Returns {@link Success | Success<T>} with the value of the first element\r\n * in the array, or {@link Failure} with an error message if the array is empty.\r\n */\r\n public first(failMessage?: string): Result<T> {\r\n if (this.length > 0) {\r\n return succeed(this[0]);\r\n }\r\n return fail(failMessage ?? `${this.itemDescription} not found`);\r\n }\r\n\r\n /**\r\n * Returns an array containing all elements of an {@link Experimental.ExtendedArray}. Fails with\r\n * an error message if the array is empty.\r\n * @param failMessage - Optional message to be displayed in the event of failure.\r\n * @returns Returns {@link Success | Success<T[]>} with a new (non-extended) `Array`\r\n * containing the elements of this array, or {@link Failure} with an error message\r\n * if the array is empty.\r\n */\r\n public atLeastOne(failMessage?: string): Result<T[]> {\r\n if (this.length > 0) {\r\n return succeed(Array.from(this));\r\n }\r\n return fail(failMessage ?? `${this.itemDescription} not found`);\r\n }\r\n\r\n /**\r\n * Gets a new (non-extended) `Array` containing all of the elements from this\r\n * {@link Experimental.ExtendedArray}.\r\n * @returns A new (non-extended) `Array<T>`.\r\n */\r\n public all(): T[] {\r\n return Array.from(this);\r\n }\r\n}\r\n"]}
@@ -1,4 +1,4 @@
1
- import { Result } from './result';
1
+ import { Result } from '../base';
2
2
  /**
3
3
  * Destination format for some formatted string.
4
4
  * @beta
@@ -31,7 +31,7 @@ export declare class FormattableBase {
31
31
  */
32
32
  protected static _tryAddDetail(details: string[], label: string, value: string | undefined): void;
33
33
  /**
34
- * {@inheritdoc Formattable.format}
34
+ * {@inheritdoc Experimental.Formattable.format}
35
35
  */
36
36
  format(template: string): Result<string>;
37
37
  }
@@ -42,14 +42,14 @@ export declare class FormattableBase {
42
42
  */
43
43
  export type Formatter<T> = (format: string, item: T) => Result<string>;
44
44
  /**
45
- * A collection of {@link Formatter | formatters} indexed by target name, to enable
45
+ * A collection of {@link Experimental.Formatter | formatters} indexed by target name, to enable
46
46
  * different format methods per output target.
47
47
  * @beta
48
48
  */
49
49
  export type FormattersByExtendedTarget<TFT extends FormatTargets, T> = Record<TFT, Formatter<T>>;
50
50
  /**
51
- * A collection of {@link Formatter | formatters} indexed by the {@link FormatTargets | default supported
52
- * target formats}.
51
+ * A collection of {@link Experimental.Formatter | formatters} indexed by the
52
+ * {@link Experimental.FormatTargets | default supported target formats}.
53
53
  * @beta
54
54
  */
55
55
  export type FormattersByTarget<T> = FormattersByExtendedTarget<FormatTargets, T>;
@@ -58,7 +58,7 @@ export type FormattersByTarget<T> = FormattersByExtendedTarget<FormatTargets, T>
58
58
  * per output line.
59
59
  * @param format - A mustache template used to format each item.
60
60
  * @param items - The items to be formatted.
61
- * @param itemFormatter - The {@link Formatter | Formatter<T>} used to format each item.
61
+ * @param itemFormatter - The {@link Experimental.Formatter | Formatter<T>} used to format each item.
62
62
  * @returns The resulting string.
63
63
  * @beta
64
64
  */
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../../src/packlets/experimental/formatter.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,MAAM,EAAsC,MAAM,SAAS,CAAC;AAIrE;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC;AAE1D;;;GAGG;AAEH,MAAM,WAAW,WAAW;IAC1B;;;;;OAKG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;CACxC;AAED;;;GAGG;AACH,qBAAa,eAAe;IAC1B;;;;;;OAMG;IACH,SAAS,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;IAOjG;;OAEG;IACI,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;CAGhD;AAED;;;;GAIG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC;AAEvE;;;;GAIG;AACH,MAAM,MAAM,0BAA0B,CAAC,GAAG,SAAS,aAAa,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;AACjG;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI,0BAA0B,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC;AAEjF;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,CASrG"}
@@ -0,0 +1,75 @@
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.formatList = exports.FormattableBase = void 0;
28
+ const mustache_1 = __importDefault(require("mustache"));
29
+ const base_1 = require("../base");
30
+ mustache_1.default.escape = (s) => s;
31
+ /**
32
+ * Base class which adds common formatting.
33
+ * @beta
34
+ */
35
+ class FormattableBase {
36
+ /**
37
+ * Helper enables derived classes to add named details to a formatted presentation.
38
+ * @param details - An array of detail description strings.
39
+ * @param label - Label to use for the new detail.
40
+ * @param value - Value to use for the new detail.
41
+ * @internal
42
+ */
43
+ static _tryAddDetail(details, label, value) {
44
+ if (value !== undefined) {
45
+ const padded = ` ${label}:`.padEnd(20, ' ');
46
+ details.push(`${padded} ${value}`);
47
+ }
48
+ }
49
+ /**
50
+ * {@inheritdoc Experimental.Formattable.format}
51
+ */
52
+ format(template) {
53
+ return (0, base_1.captureResult)(() => mustache_1.default.render(template, this));
54
+ }
55
+ }
56
+ exports.FormattableBase = FormattableBase;
57
+ /**
58
+ * Formats a list of items using the supplied template and formatter, one result
59
+ * per output line.
60
+ * @param format - A mustache template used to format each item.
61
+ * @param items - The items to be formatted.
62
+ * @param itemFormatter - The {@link Experimental.Formatter | Formatter<T>} used to format each item.
63
+ * @returns The resulting string.
64
+ * @beta
65
+ */
66
+ function formatList(format, items, itemFormatter) {
67
+ return (0, base_1.mapResults)(items.map((item) => {
68
+ return itemFormatter(format, item);
69
+ })).onSuccess((results) => {
70
+ const filtered = results.filter((s) => s !== '');
71
+ return (0, base_1.succeed)(filtered.join('\n'));
72
+ });
73
+ }
74
+ exports.formatList = formatList;
75
+ //# sourceMappingURL=formatter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatter.js","sourceRoot":"","sources":["../../../src/packlets/experimental/formatter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;AAEH,wDAAgC;AAChC,kCAAqE;AAErE,kBAAQ,CAAC,MAAM,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC;AAuBnC;;;GAGG;AACH,MAAa,eAAe;IAC1B;;;;;;OAMG;IACO,MAAM,CAAC,aAAa,CAAC,OAAiB,EAAE,KAAa,EAAE,KAAyB;QACxF,IAAI,KAAK,KAAK,SAAS,EAAE;YACvB,MAAM,MAAM,GAAG,KAAK,KAAK,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;YAC7C,OAAO,CAAC,IAAI,CAAC,GAAG,MAAM,IAAI,KAAK,EAAE,CAAC,CAAC;SACpC;IACH,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,QAAgB;QAC5B,OAAO,IAAA,oBAAa,EAAC,GAAG,EAAE,CAAC,kBAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC;IAC9D,CAAC;CACF;AArBD,0CAqBC;AAsBD;;;;;;;;GAQG;AACH,SAAgB,UAAU,CAAI,MAAc,EAAE,KAAU,EAAE,aAA2B;IACnF,OAAO,IAAA,iBAAU,EACf,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACjB,OAAO,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACrC,CAAC,CAAC,CACH,CAAC,SAAS,CAAC,CAAC,OAAiB,EAAE,EAAE;QAChC,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;QACjD,OAAO,IAAA,cAAO,EAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;AACL,CAAC;AATD,gCASC","sourcesContent":["/*\n * Copyright (c) 2020 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 Mustache from 'mustache';\nimport { Result, captureResult, mapResults, succeed } from '../base';\n\nMustache.escape = (s: string) => s;\n\n/**\n * Destination format for some formatted string.\n * @beta\n */\nexport type FormatTargets = 'text' | 'markdown' | 'embed';\n\n/**\n * Interface for an object that can be formatted.\n * @beta\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface Formattable {\n /**\n * Formats an object using the supplied mustache template.\n * @param format - A mustache template used to format the object.\n * @returns {@link Success} with the resulting string, or {@link Failure}\n * with an error message if an error occurs.\n */\n format(format: string): Result<string>;\n}\n\n/**\n * Base class which adds common formatting.\n * @beta\n */\nexport class FormattableBase {\n /**\n * Helper enables derived classes to add named details to a formatted presentation.\n * @param details - An array of detail description strings.\n * @param label - Label to use for the new detail.\n * @param value - Value to use for the new detail.\n * @internal\n */\n protected static _tryAddDetail(details: string[], label: string, value: string | undefined): void {\n if (value !== undefined) {\n const padded = ` ${label}:`.padEnd(20, ' ');\n details.push(`${padded} ${value}`);\n }\n }\n\n /**\n * {@inheritdoc Experimental.Formattable.format}\n */\n public format(template: string): Result<string> {\n return captureResult(() => Mustache.render(template, this));\n }\n}\n\n/**\n * Type definition for a formatting function, which takes a `string` and an\n * item and returns {@link Result | Result<string>}.\n * @beta\n */\nexport type Formatter<T> = (format: string, item: T) => Result<string>;\n\n/**\n * A collection of {@link Experimental.Formatter | formatters} indexed by target name, to enable\n * different format methods per output target.\n * @beta\n */\nexport type FormattersByExtendedTarget<TFT extends FormatTargets, T> = Record<TFT, Formatter<T>>;\n/**\n * A collection of {@link Experimental.Formatter | formatters} indexed by the\n * {@link Experimental.FormatTargets | default supported target formats}.\n * @beta\n */\nexport type FormattersByTarget<T> = FormattersByExtendedTarget<FormatTargets, T>;\n\n/**\n * Formats a list of items using the supplied template and formatter, one result\n * per output line.\n * @param format - A mustache template used to format each item.\n * @param items - The items to be formatted.\n * @param itemFormatter - The {@link Experimental.Formatter | Formatter<T>} used to format each item.\n * @returns The resulting string.\n * @beta\n */\nexport function formatList<T>(format: string, items: T[], itemFormatter: Formatter<T>): Result<string> {\n return mapResults(\n items.map((item) => {\n return itemFormatter(format, item);\n })\n ).onSuccess((results: string[]) => {\n const filtered = results.filter((s) => s !== '');\n return succeed(filtered.join('\\n'));\n });\n}\n"]}
@@ -0,0 +1,4 @@
1
+ export * from './extendedArray';
2
+ export * from './formatter';
3
+ export * from './rangeOf';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/experimental/index.ts"],"names":[],"mappings":"AAsBA,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC"}
@@ -0,0 +1,41 @@
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
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
24
+ if (k2 === undefined) k2 = k;
25
+ var desc = Object.getOwnPropertyDescriptor(m, k);
26
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
27
+ desc = { enumerable: true, get: function() { return m[k]; } };
28
+ }
29
+ Object.defineProperty(o, k2, desc);
30
+ }) : (function(o, m, k, k2) {
31
+ if (k2 === undefined) k2 = k;
32
+ o[k2] = m[k];
33
+ }));
34
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
35
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ __exportStar(require("./extendedArray"), exports);
39
+ __exportStar(require("./formatter"), exports);
40
+ __exportStar(require("./rangeOf"), exports);
41
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/experimental/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;AAEH,kDAAgC;AAChC,8CAA4B;AAC5B,4CAA0B","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\nexport * from './extendedArray';\nexport * from './formatter';\nexport * from './rangeOf';\n"]}