@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,11 @@
1
+ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
+ // It should be published with your NPM package. It should not be tracked by Git.
3
+ {
4
+ "tsdocVersion": "0.12",
5
+ "toolPackages": [
6
+ {
7
+ "packageName": "@microsoft/api-extractor",
8
+ "packageVersion": "7.34.4"
9
+ }
10
+ ]
11
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import * as Conversion from './packlets/conversion';
2
+ import * as Csv from './packlets/csv';
3
+ import * as Experimental from './packlets/experimental';
4
+ import * as Hash from './packlets/hash';
5
+ import * as RecordJar from './packlets/record-jar';
6
+ import * as Validation from './packlets/validation';
7
+ import { Converter, Converters } from './packlets/conversion';
8
+ import { Validator, Validators } from './packlets/validation';
9
+ export * from './packlets/base';
10
+ export { Converter, Converters, Validator, Validators };
11
+ export { Conversion, Experimental, Csv, Hash, RecordJar, Validation };
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,GAAG,MAAM,gBAAgB,CAAC;AACtC,OAAO,KAAK,YAAY,MAAM,yBAAyB,CAAC;AACxD,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAE9D,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,68 @@
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
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
47
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.Validation = exports.RecordJar = exports.Hash = exports.Csv = exports.Experimental = exports.Conversion = exports.Validators = exports.Converters = void 0;
51
+ const Conversion = __importStar(require("./packlets/conversion"));
52
+ exports.Conversion = Conversion;
53
+ const Csv = __importStar(require("./packlets/csv"));
54
+ exports.Csv = Csv;
55
+ const Experimental = __importStar(require("./packlets/experimental"));
56
+ exports.Experimental = Experimental;
57
+ const Hash = __importStar(require("./packlets/hash"));
58
+ exports.Hash = Hash;
59
+ const RecordJar = __importStar(require("./packlets/record-jar"));
60
+ exports.RecordJar = RecordJar;
61
+ const Validation = __importStar(require("./packlets/validation"));
62
+ exports.Validation = Validation;
63
+ const conversion_1 = require("./packlets/conversion");
64
+ Object.defineProperty(exports, "Converters", { enumerable: true, get: function () { return conversion_1.Converters; } });
65
+ const validation_1 = require("./packlets/validation");
66
+ Object.defineProperty(exports, "Validators", { enumerable: true, get: function () { return validation_1.Validators; } });
67
+ __exportStar(require("./packlets/base"), exports);
68
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,kEAAoD;AAY3C,gCAAU;AAXnB,oDAAsC;AAWH,kBAAG;AAVtC,sEAAwD;AAUnC,oCAAY;AATjC,sDAAwC;AASA,oBAAI;AAR5C,iEAAmD;AAQL,8BAAS;AAPvD,kEAAoD;AAOK,gCAAU;AALnE,sDAA8D;AAI1C,2FAJA,uBAAU,OAIA;AAH9B,sDAA8D;AAGnB,2FAHvB,uBAAU,OAGuB;AADrD,kDAAgC","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 Conversion from './packlets/conversion';\nimport * as Csv from './packlets/csv';\nimport * as Experimental from './packlets/experimental';\nimport * as Hash from './packlets/hash';\nimport * as RecordJar from './packlets/record-jar';\nimport * as Validation from './packlets/validation';\n\nimport { Converter, Converters } from './packlets/conversion';\nimport { Validator, Validators } from './packlets/validation';\n\nexport * from './packlets/base';\nexport { Converter, Converters, Validator, Validators };\nexport { Conversion, Experimental, Csv, Hash, RecordJar, Validation };\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"brand.d.ts","sourceRoot":"","sources":["../../../src/packlets/base/brand.ts"],"names":[],"mappings":"AAsBA;;;GAGG;AAEH,MAAM,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAAE,OAAO,EAAE,CAAC,CAAA;CAAE,CAAC"}
@@ -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=brand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"brand.js","sourceRoot":"","sources":["../../../src/packlets/base/brand.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\n/**\n * Helper type to brand a simple type to prevent inappropriate use\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport type Brand<T, B> = T & { __brand: B };\n"]}
@@ -0,0 +1,7 @@
1
+ import * as Logging from './logger';
2
+ export * from './brand';
3
+ export { Normalizer } from './normalize';
4
+ export * from './result';
5
+ export * from './utils';
6
+ export { Logging };
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/base/index.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,OAAO,MAAM,UAAU,CAAC;AAEpC,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,CAAC"}
@@ -0,0 +1,58 @@
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
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
47
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.Logging = exports.Normalizer = void 0;
51
+ const Logging = __importStar(require("./logger"));
52
+ exports.Logging = Logging;
53
+ __exportStar(require("./brand"), exports);
54
+ var normalize_1 = require("./normalize");
55
+ Object.defineProperty(exports, "Normalizer", { enumerable: true, get: function () { return normalize_1.Normalizer; } });
56
+ __exportStar(require("./result"), exports);
57
+ __exportStar(require("./utils"), exports);
58
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/base/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,kDAAoC;AAM3B,0BAAO;AAJhB,0CAAwB;AACxB,yCAAyC;AAAhC,uGAAA,UAAU,OAAA;AACnB,2CAAyB;AACzB,0CAAwB","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 Logging from './logger';\n\nexport * from './brand';\nexport { Normalizer } from './normalize';\nexport * from './result';\nexport * from './utils';\nexport { Logging };\n"]}
@@ -1,5 +1,11 @@
1
1
  import { Failure, Success } from './result';
2
+ /**
3
+ * @public
4
+ */
2
5
  export type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
6
+ /**
7
+ * @public
8
+ */
3
9
  export interface Logger {
4
10
  log(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
5
11
  detail(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
@@ -8,6 +14,9 @@ export interface Logger {
8
14
  warnAndFail<T>(message?: unknown, ...parameters: unknown[]): Failure<T>;
9
15
  error<T>(message?: unknown, ...parameters: unknown[]): Failure<T>;
10
16
  }
17
+ /**
18
+ * @public
19
+ */
11
20
  export declare abstract class LoggerBase {
12
21
  logLevel: LogLevel;
13
22
  constructor(logLevel?: LogLevel);
@@ -18,9 +27,12 @@ export declare abstract class LoggerBase {
18
27
  error<T>(message?: unknown, ...parameters: unknown[]): Failure<T>;
19
28
  log(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
20
29
  protected _format(message?: unknown, ...parameters: unknown[]): string;
21
- protected _innerSilent(_message: string): Success<string | undefined>;
30
+ protected _innerSilent(__message: string): Success<string | undefined>;
22
31
  protected abstract _innerLog(message: string): Success<string | undefined>;
23
32
  }
33
+ /**
34
+ * @public
35
+ */
24
36
  export declare class InMemoryLogger extends LoggerBase {
25
37
  protected _messages: string[];
26
38
  protected _silent: string[];
@@ -31,6 +43,9 @@ export declare class InMemoryLogger extends LoggerBase {
31
43
  protected _innerLog(message: string): Success<string | undefined>;
32
44
  protected _innerSilent(message: string): Success<string | undefined>;
33
45
  }
46
+ /**
47
+ * @public
48
+ */
34
49
  export declare class NoOpLogger extends LoggerBase {
35
50
  protected _innerLog(message: string): Success<string | undefined>;
36
51
  }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/packlets/base/logger.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAiB,MAAM,UAAU,CAAC;AAE3D;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE1E;;GAEG;AAEH,MAAM,WAAW,MAAM;IACrB,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,GAAG,UAAU,EAAE,OAAO,EAAE,GAAG,OAAO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Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NoOpLogger = exports.InMemoryLogger = exports.LoggerBase = void 0;
4
+ /*
5
+ * Copyright (c) 2020 Erik Fortune
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ const result_1 = require("./result");
26
+ /**
27
+ * @public
28
+ */
29
+ class LoggerBase {
30
+ constructor(logLevel) {
31
+ this.logLevel = 'info';
32
+ this.logLevel = logLevel !== null && logLevel !== void 0 ? logLevel : 'info';
33
+ }
34
+ detail(message, ...parameters) {
35
+ if (this.logLevel === 'detail') {
36
+ return this.log(message, parameters);
37
+ }
38
+ return (0, result_1.succeed)(undefined);
39
+ }
40
+ info(message, ...parameters) {
41
+ if (this.logLevel === 'detail' || this.logLevel === 'info') {
42
+ return this.log(message, parameters);
43
+ }
44
+ return (0, result_1.succeed)(undefined);
45
+ }
46
+ warn(message, ...parameters) {
47
+ if (this.logLevel !== 'error' && this.logLevel !== 'silent') {
48
+ return this.log(message, parameters);
49
+ }
50
+ return (0, result_1.succeed)(undefined);
51
+ }
52
+ warnAndFail(message, ...parameters) {
53
+ var _a;
54
+ const formatted = this._format(message, ...parameters);
55
+ if (this.logLevel !== 'error' && this.logLevel !== 'silent') {
56
+ const result = this.log(formatted);
57
+ return (0, result_1.fail)((_a = result.value) !== null && _a !== void 0 ? _a : formatted);
58
+ }
59
+ return (0, result_1.fail)(formatted);
60
+ }
61
+ error(message, ...parameters) {
62
+ var _a;
63
+ const formatted = this._format(message, ...parameters);
64
+ if (this.logLevel !== 'silent') {
65
+ const result = this.log(formatted);
66
+ return (0, result_1.fail)((_a = result.value) !== null && _a !== void 0 ? _a : formatted);
67
+ }
68
+ return (0, result_1.fail)(formatted);
69
+ }
70
+ log(message, ...parameters) {
71
+ const messageString = this._format(message, ...parameters);
72
+ if (this.logLevel === 'silent') {
73
+ return this._innerSilent(messageString);
74
+ }
75
+ return this._innerLog(messageString);
76
+ }
77
+ _format(message, ...parameters) {
78
+ const raw = [message, ...parameters];
79
+ const filtered = raw.filter((m) => m !== undefined);
80
+ const strings = filtered.map((m) => m.toString());
81
+ const joined = strings.join('');
82
+ return joined;
83
+ }
84
+ _innerSilent(__message) {
85
+ return (0, result_1.succeed)(undefined);
86
+ }
87
+ }
88
+ exports.LoggerBase = LoggerBase;
89
+ /**
90
+ * @public
91
+ */
92
+ class InMemoryLogger extends LoggerBase {
93
+ constructor(logLevel) {
94
+ super(logLevel);
95
+ this._messages = [];
96
+ this._silent = [];
97
+ }
98
+ get messages() {
99
+ return this._messages;
100
+ }
101
+ get silent() {
102
+ return this._silent;
103
+ }
104
+ clear() {
105
+ this._messages = [];
106
+ this._silent = [];
107
+ }
108
+ _innerLog(message) {
109
+ this._messages.push(message);
110
+ return (0, result_1.succeed)(message);
111
+ }
112
+ _innerSilent(message) {
113
+ this._silent.push(message);
114
+ return (0, result_1.succeed)(undefined);
115
+ }
116
+ }
117
+ exports.InMemoryLogger = InMemoryLogger;
118
+ /**
119
+ * @public
120
+ */
121
+ class NoOpLogger extends LoggerBase {
122
+ _innerLog(message) {
123
+ // no-op
124
+ return (0, result_1.succeed)(message);
125
+ }
126
+ }
127
+ exports.NoOpLogger = NoOpLogger;
128
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/packlets/base/logger.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qCAA2D;AAoB3D;;GAEG;AACH,MAAsB,UAAU;IAG9B,YAAmB,QAAmB;QAF/B,aAAQ,GAAa,MAAM,CAAC;QAGjC,IAAI,CAAC,QAAQ,GAAG,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,MAAM,CAAC;IACrC,CAAC;IAEM,MAAM,CAAC,OAAiB,EAAE,GAAG,UAAqB;QACvD,IAAI,IAAI,CAAC,QAAQ,KAAK,QAAQ,EAAE;YAC9B,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;SACtC;QACD,OAAO,IAAA,gBAAO,EAAC,SAAS,CAAC,CAAC;IAC5B,CAAC;IAEM,IAAI,CAAC,OAAiB,EAAE,GAAG,UAAqB;QACrD,IAAI,IAAI,CAAC,QAAQ,KAAK,QAAQ,IAAI,IAAI,CAAC,QAAQ,KAAK,MAAM,EAAE;YAC1D,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;SACtC;QACD,OAAO,IAAA,gBAAO,EAAC,SAAS,CAAC,CAAC;IAC5B,CAAC;IAEM,IAAI,CAAC,OAAiB,EAAE,GAAG,UAAqB;QACrD,IAAI,IAAI,CAAC,QAAQ,KAAK,OAAO,IAAI,IAAI,CAAC,QAAQ,KAAK,QAAQ,EAAE;YAC3D,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;SACtC;QACD,OAAO,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AACH,MAAa,UAAW,SAAQ,UAAU;IAC9B,SAAS,CAAC,OAAe;QACjC,QAAQ;QACR,OAAO,IAAA,gBAAO,EAAC,OAAO,CAAC,CAAC;IAC1B,CAAC;CACF;AALD,gCAKC","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 */\nimport { Failure, Success, fail, succeed } from './result';\n\n/**\n * @public\n */\nexport type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';\n\n/**\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface Logger {\n log(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;\n detail(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;\n info(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;\n warn(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;\n warnAndFail<T>(message?: unknown, ...parameters: unknown[]): Failure<T>;\n error<T>(message?: unknown, ...parameters: unknown[]): Failure<T>;\n}\n\n/**\n * @public\n */\nexport abstract class LoggerBase {\n public logLevel: LogLevel = 'info';\n\n public constructor(logLevel?: LogLevel) {\n this.logLevel = logLevel ?? 'info';\n }\n\n public detail(message?: unknown, ...parameters: unknown[]): Success<string | undefined> {\n if (this.logLevel === 'detail') {\n return this.log(message, parameters);\n }\n return succeed(undefined);\n }\n\n public info(message?: unknown, ...parameters: unknown[]): Success<string | undefined> {\n if (this.logLevel === 'detail' || this.logLevel === 'info') {\n return this.log(message, parameters);\n }\n return succeed(undefined);\n }\n\n public warn(message?: unknown, ...parameters: unknown[]): Success<string | undefined> {\n if (this.logLevel !== 'error' && this.logLevel !== 'silent') {\n return this.log(message, parameters);\n }\n return succeed(undefined);\n }\n\n public warnAndFail<T>(message?: unknown, ...parameters: unknown[]): Failure<T> {\n const formatted = this._format(message, ...parameters);\n if (this.logLevel !== 'error' && this.logLevel !== 'silent') {\n const result = this.log(formatted);\n return fail(result.value ?? formatted);\n }\n return fail(formatted);\n }\n\n public error<T>(message?: unknown, ...parameters: unknown[]): Failure<T> {\n const formatted = this._format(message, ...parameters);\n if (this.logLevel !== 'silent') {\n const result = this.log(formatted);\n return fail(result.value ?? formatted);\n }\n return fail(formatted);\n }\n\n public log(message?: unknown, ...parameters: unknown[]): Success<string | undefined> {\n const messageString = this._format(message, ...parameters);\n if (this.logLevel === 'silent') {\n return this._innerSilent(messageString);\n }\n return this._innerLog(messageString);\n }\n\n protected _format(message?: unknown, ...parameters: unknown[]): string {\n const raw = [message, ...parameters];\n const filtered = raw.filter((m): m is string => m !== undefined);\n const strings = filtered.map((m) => m.toString());\n const joined = strings.join('');\n return joined;\n }\n\n protected _innerSilent(__message: string): Success<string | undefined> {\n return succeed(undefined);\n }\n\n protected abstract _innerLog(message: string): Success<string | undefined>;\n}\n\n/**\n * @public\n */\nexport class InMemoryLogger extends LoggerBase {\n protected _messages: string[] = [];\n protected _silent: string[] = [];\n\n public constructor(logLevel?: LogLevel) {\n super(logLevel);\n }\n\n public get messages(): string[] {\n return this._messages;\n }\n public get silent(): string[] {\n return this._silent;\n }\n\n public clear(): void {\n this._messages = [];\n this._silent = [];\n }\n\n protected _innerLog(message: string): Success<string | undefined> {\n this._messages.push(message);\n return succeed(message);\n }\n\n protected _innerSilent(message: string): Success<string | undefined> {\n this._silent.push(message);\n return succeed(undefined);\n }\n}\n\n/**\n * @public\n */\nexport class NoOpLogger extends LoggerBase {\n protected _innerLog(message: string): Success<string | undefined> {\n // no-op\n return succeed(message);\n }\n}\n"]}
@@ -1,5 +1,11 @@
1
1
  import { Result } from './result';
2
+ /**
3
+ * @internal
4
+ */
2
5
  export type Entry<T> = [string | number | symbol, T];
6
+ /**
7
+ * @internal
8
+ */
3
9
  export type ResultEntry<T> = [string | number | symbol, Result<T>];
4
10
  /**
5
11
  * Normalizes an arbitrary JSON object
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../../src/packlets/base/normalize.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,MAAM,EAA6B,MAAM,UAAU,CAAC;AAE7D;;GAEG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAEnE;;;GAGG;AACH,qBAAa,UAAU;IACrB;;;;;OAKG;IACI,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;IA4BvC;;;;;;;OAOG;IACH,SAAS,CAAC,YAAY,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,GAAG,MAAM;IAexD;;;;;;;OAOG;IACH,SAAS,CAAC,iBAAiB,CAAC,CAAC,GAAG,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE;IAQjF,SAAS,CAAC,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;IAI7D;;;;;OAKG;IACH,SAAS,CAAC,iBAAiB,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;CAyBnD"}
@@ -0,0 +1,139 @@
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.Normalizer = void 0;
25
+ const result_1 = require("./result");
26
+ /**
27
+ * Normalizes an arbitrary JSON object
28
+ * @public
29
+ */
30
+ class Normalizer {
31
+ /**
32
+ * Normalizes the supplied value
33
+ *
34
+ * @param from - The value to be normalized
35
+ * @returns A normalized version of the value
36
+ */
37
+ normalize(from) {
38
+ switch (typeof from) {
39
+ case 'string':
40
+ case 'bigint':
41
+ case 'boolean':
42
+ case 'number':
43
+ case 'symbol':
44
+ case 'undefined':
45
+ return this._normalizeLiteral(from);
46
+ case 'object':
47
+ if (from === null || from instanceof Date || from instanceof RegExp) {
48
+ return this._normalizeLiteral(from);
49
+ }
50
+ else if (Array.isArray(from)) {
51
+ return this._normalizeArray(from);
52
+ }
53
+ else if (from instanceof Map) {
54
+ return (0, result_1.succeed)(new Map(this._normalizeEntries(from.entries())));
55
+ }
56
+ else if (from instanceof Set) {
57
+ return (0, result_1.succeed)(new Set(this._normalizeEntries(from.entries())));
58
+ }
59
+ const obj = {};
60
+ for (const e of this._normalizeEntries(Object.entries(from))) {
61
+ obj[e[0]] = e[1];
62
+ }
63
+ return (0, result_1.succeed)(obj);
64
+ }
65
+ return (0, result_1.fail)(`normalize: Unexpected type - cannot normalize '${typeof from}'`);
66
+ }
67
+ /**
68
+ * Compares two property names from some object being normalized.
69
+ * @param k1 - First key to be compared.
70
+ * @param k2 - Second key to be compared.
71
+ * @returns `1` if `k1` is greater, `-1` if `k2` is greater and
72
+ * `0` if they are equal.
73
+ * @internal
74
+ */
75
+ _compareKeys(k1, k2) {
76
+ const cs1 = String(k1);
77
+ const cs2 = String(k2);
78
+ if (cs1 > cs2) {
79
+ return 1;
80
+ }
81
+ // istanbul ignore else
82
+ if (cs2 > cs1) {
83
+ return -1;
84
+ }
85
+ // istanbul ignore next
86
+ return 0;
87
+ }
88
+ /**
89
+ * Normalizes an array of object property entries (e.g. as returned by `Object.entries()`).
90
+ * @remarks
91
+ * Converts property names (entry key) to string and then sorts as string.
92
+ * @param entries - The entries to be normalized.
93
+ * @returns A normalized sorted array of entries.
94
+ * @internal
95
+ */
96
+ _normalizeEntries(entries) {
97
+ return Array.from(entries)
98
+ .sort((e1, e2) => this._compareKeys(e1[0], e2[0]))
99
+ .map((e) => [e[0], this.normalize(e[1])])
100
+ .filter((e) => e[1].isSuccess())
101
+ .map((e) => [e[0], e[1].orThrow()]);
102
+ }
103
+ _normalizeArray(from) {
104
+ return (0, result_1.mapResults)(from.map((v) => this.normalize(v)));
105
+ }
106
+ /**
107
+ * Normalizes the supplied literal value
108
+ * @param from - The literal value to be normalized.
109
+ * @returns A normalized value for the literal.
110
+ * @internal
111
+ */
112
+ _normalizeLiteral(from) {
113
+ // TODO: Apply configurable normalization rules
114
+ switch (typeof from) {
115
+ case 'string':
116
+ return (0, result_1.succeed)(from);
117
+ case 'bigint':
118
+ case 'boolean':
119
+ case 'number':
120
+ case 'symbol':
121
+ case 'undefined':
122
+ return (0, result_1.succeed)(from);
123
+ }
124
+ if (from === null) {
125
+ return (0, result_1.succeed)(from);
126
+ }
127
+ if (from instanceof Date) {
128
+ return (0, result_1.succeed)(from);
129
+ }
130
+ // istanbul ignore else
131
+ if (from instanceof RegExp) {
132
+ return (0, result_1.succeed)(from);
133
+ }
134
+ // istanbul ignore next
135
+ return (0, result_1.fail)(`cannot normalize ${JSON.stringify(from)}`);
136
+ }
137
+ }
138
+ exports.Normalizer = Normalizer;
139
+ //# sourceMappingURL=normalize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize.js","sourceRoot":"","sources":["../../../src/packlets/base/normalize.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,qCAA6D;AAY7D;;;GAGG;AACH,MAAa,UAAU;IACrB;;;;;OAKG;IACI,SAAS,CAAI,IAAO;QACzB,QAAQ,OAAO,IAAI,EAAE;YACnB,KAAK,QAAQ,CAAC;YACd,KAAK,QAAQ,CAAC;YACd,KAAK,SAAS,CAAC;YACf,KAAK,QAAQ,CAAC;YACd,KAAK,QAAQ,CAAC;YACd,KAAK,WAAW;gBACd,OAAO,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;YACtC,KAAK,QAAQ;gBACX,IAAI,IAAI,KAAK,IAAI,IAAI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D,IAAI,IAAI,KAAK,IAAI,EAAE;YACjB,OAAO,IAAA,gBAAO,EAAC,IAAI,CAAC,CAAC;SACtB;QACD,IAAI,IAAI,YAAY,IAAI,EAAE;YACxB,OAAO,IAAA,gBAAO,EAAC,IAAI,CAAC,CAAC;SACtB;QACD,uBAAuB;QACvB,IAAI,IAAI,YAAY,MAAM,EAAE;YAC1B,OAAO,IAAA,gBAAO,EAAC,IAAI,CAAC,CAAC;SACtB;QACD,uBAAuB;QACvB,OAAO,IAAA,aAAI,EAAC,oBAAoB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC1D,CAAC;CACF;AA7GD,gCA6GC","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 { Result, fail, mapResults, succeed } from './result';\n\n/**\n * @internal\n */\nexport type Entry<T> = [string | number | symbol, T];\n\n/**\n * @internal\n */\nexport type ResultEntry<T> = [string | number | symbol, Result<T>];\n\n/**\n * Normalizes an arbitrary JSON object\n * @public\n */\nexport class Normalizer {\n /**\n * Normalizes the supplied value\n *\n * @param from - The value to be normalized\n * @returns A normalized version of the value\n */\n public normalize<T>(from: T): Result<T> {\n switch (typeof from) {\n case 'string':\n case 'bigint':\n case 'boolean':\n case 'number':\n case 'symbol':\n case 'undefined':\n return this._normalizeLiteral(from);\n case 'object':\n if (from === null || from instanceof Date || from instanceof RegExp) {\n return this._normalizeLiteral(from);\n } else if (Array.isArray(from)) {\n return this._normalizeArray(from) as unknown as Result<T>;\n } else if (from instanceof Map) {\n return succeed(new Map(this._normalizeEntries(from.entries())) as unknown as T);\n } else if (from instanceof Set) {\n return succeed(new Set(this._normalizeEntries(from.entries())) as unknown as T);\n }\n const obj: { [key in number | string | symbol]: unknown } = {};\n for (const e of this._normalizeEntries(Object.entries(from as unknown as object))) {\n obj[e[0]] = e[1];\n }\n return succeed(obj as T);\n }\n return fail(`normalize: Unexpected type - cannot normalize '${typeof from}'`);\n }\n\n /**\n * Compares two property names from some object being normalized.\n * @param k1 - First key to be compared.\n * @param k2 - Second key to be compared.\n * @returns `1` if `k1` is greater, `-1` if `k2` is greater and\n * `0` if they are equal.\n * @internal\n */\n protected _compareKeys(k1: unknown, k2: unknown): number {\n const cs1 = String(k1);\n const cs2 = String(k2);\n if (cs1 > cs2) {\n return 1;\n }\n // istanbul ignore else\n if (cs2 > cs1) {\n return -1;\n }\n\n // istanbul ignore next\n return 0;\n }\n\n /**\n * Normalizes an array of object property entries (e.g. as returned by `Object.entries()`).\n * @remarks\n * Converts property names (entry key) to string and then sorts as string.\n * @param entries - The entries to be normalized.\n * @returns A normalized sorted array of entries.\n * @internal\n */\n protected _normalizeEntries<T = unknown>(entries: Iterable<Entry<T>>): Entry<T>[] {\n return Array.from(entries)\n .sort((e1, e2) => this._compareKeys(e1[0], e2[0]))\n .map((e) => [e[0], this.normalize(e[1])] as ResultEntry<T>)\n .filter((e) => e[1].isSuccess())\n .map((e) => [e[0], e[1].orThrow()]);\n }\n\n protected _normalizeArray(from: unknown[]): Result<unknown[]> {\n return mapResults(from.map((v) => this.normalize(v)));\n }\n\n /**\n * Normalizes the supplied literal value\n * @param from - The literal value to be normalized.\n * @returns A normalized value for the literal.\n * @internal\n */\n protected _normalizeLiteral<T>(from: T): Result<T> {\n // TODO: Apply configurable normalization rules\n switch (typeof from) {\n case 'string':\n return succeed(from);\n case 'bigint':\n case 'boolean':\n case 'number':\n case 'symbol':\n case 'undefined':\n return succeed(from);\n }\n if (from === null) {\n return succeed(from);\n }\n if (from instanceof Date) {\n return succeed(from);\n }\n // istanbul ignore else\n if (from instanceof RegExp) {\n return succeed(from);\n }\n // istanbul ignore next\n return fail(`cannot normalize ${JSON.stringify(from)}`);\n }\n}\n"]}