@augment-vir/common 29.3.0 → 30.0.1

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 (296) hide show
  1. package/LICENSE-CC0 +121 -0
  2. package/LICENSE-MIT +21 -0
  3. package/README.md +7 -3
  4. package/dist/augments/array/array-map.d.ts +34 -0
  5. package/dist/augments/array/array-map.js +32 -0
  6. package/dist/augments/array/array-to-object.d.ts +53 -0
  7. package/dist/augments/array/array-to-object.js +67 -0
  8. package/dist/augments/array/awaited/awaited-filter.d.ts +36 -0
  9. package/dist/augments/array/awaited/awaited-filter.js +36 -0
  10. package/dist/augments/array/awaited/awaited-for-each.d.ts +31 -0
  11. package/dist/augments/array/awaited/awaited-for-each.js +34 -0
  12. package/dist/augments/array/awaited/awaited-map.d.ts +33 -0
  13. package/dist/augments/array/awaited/awaited-map.js +40 -0
  14. package/dist/augments/array/filter.d.ts +32 -0
  15. package/dist/augments/array/filter.js +74 -0
  16. package/dist/augments/array/remove-duplicates.d.ts +60 -0
  17. package/dist/augments/array/remove-duplicates.js +72 -0
  18. package/dist/augments/array/repeat-array.d.ts +23 -0
  19. package/dist/augments/array/repeat-array.js +25 -0
  20. package/dist/augments/array/shuffle-array.d.ts +9 -0
  21. package/dist/augments/array/shuffle-array.js +17 -0
  22. package/dist/augments/array/string-array.d.ts +9 -0
  23. package/dist/augments/array/string-array.js +11 -0
  24. package/dist/augments/core-exports.d.ts +1 -0
  25. package/dist/augments/core-exports.js +1 -0
  26. package/dist/augments/enum/enum-value-check.d.ts +32 -0
  27. package/dist/augments/enum/enum-value-check.js +34 -0
  28. package/dist/augments/error/combine-errors.d.ts +24 -0
  29. package/dist/augments/error/combine-errors.js +34 -0
  30. package/dist/augments/function/call-asynchronously.d.ts +25 -0
  31. package/dist/augments/function/call-asynchronously.js +26 -0
  32. package/dist/augments/function/call-with-retries.d.ts +24 -0
  33. package/dist/augments/function/call-with-retries.js +50 -0
  34. package/dist/augments/function/debounce.d.ts +89 -0
  35. package/dist/augments/function/debounce.js +112 -0
  36. package/dist/augments/function/execution-duration.d.ts +20 -0
  37. package/dist/augments/function/execution-duration.js +39 -0
  38. package/dist/augments/function/if-truthy.d.ts +28 -0
  39. package/dist/augments/function/if-truthy.js +35 -0
  40. package/dist/{types/augments → augments/function}/wrap-in-try.d.ts +14 -7
  41. package/dist/augments/function/wrap-in-try.js +98 -0
  42. package/dist/augments/json/append-json.d.ts +5 -0
  43. package/dist/augments/json/append-json.js +59 -0
  44. package/dist/augments/json/copy-through-json.d.ts +34 -0
  45. package/dist/augments/json/copy-through-json.js +42 -0
  46. package/dist/augments/json/json-compatible.d.ts +50 -0
  47. package/dist/augments/json/jsonify.d.ts +31 -0
  48. package/dist/augments/json/jsonify.js +33 -0
  49. package/dist/augments/log/log-colors.d.ts +64 -0
  50. package/dist/augments/log/log-colors.js +157 -0
  51. package/dist/augments/log/log-string.d.ts +35 -0
  52. package/dist/augments/log/log-string.js +73 -0
  53. package/dist/augments/log/log-writer.d.ts +30 -0
  54. package/dist/augments/log/log.d.ts +56 -0
  55. package/dist/augments/log/log.js +85 -0
  56. package/dist/augments/log/logger.d.ts +60 -0
  57. package/dist/augments/log/logger.js +59 -0
  58. package/dist/augments/number/clamp.d.ts +18 -0
  59. package/dist/augments/number/clamp.js +19 -0
  60. package/dist/augments/number/coords.d.ts +23 -0
  61. package/dist/augments/number/digit.d.ts +8 -0
  62. package/dist/augments/number/dimensions.d.ts +23 -0
  63. package/dist/augments/number/min-max.d.ts +18 -0
  64. package/dist/augments/number/min-max.js +16 -0
  65. package/dist/augments/number/number-conversion.d.ts +29 -0
  66. package/dist/augments/number/number-conversion.js +56 -0
  67. package/dist/augments/number/round.d.ts +22 -0
  68. package/dist/augments/number/round.js +24 -0
  69. package/dist/augments/number/scientific.d.ts +18 -0
  70. package/dist/augments/number/scientific.js +20 -0
  71. package/dist/augments/number/truncate-number.d.ts +40 -0
  72. package/dist/{esm/augments → augments/number}/truncate-number.js +39 -17
  73. package/dist/augments/number/wrap-number.d.ts +19 -0
  74. package/dist/augments/number/wrap-number.js +28 -0
  75. package/dist/augments/object/diff.d.ts +51 -0
  76. package/dist/augments/object/diff.js +149 -0
  77. package/dist/augments/object/empty.d.ts +9 -0
  78. package/dist/augments/object/get-or-set.d.ts +10 -0
  79. package/dist/augments/object/get-or-set.js +100 -0
  80. package/dist/augments/object/key-count.d.ts +21 -0
  81. package/dist/augments/object/map-entries.d.ts +13 -0
  82. package/dist/augments/object/map-entries.js +80 -0
  83. package/dist/augments/object/map-enum.d.ts +11 -0
  84. package/dist/augments/object/map-enum.js +45 -0
  85. package/dist/augments/object/map-values.d.ts +35 -0
  86. package/dist/augments/object/map-values.js +65 -0
  87. package/dist/{types/augments → augments}/object/merge-deep.d.ts +4 -0
  88. package/dist/{esm/augments → augments}/object/merge-deep.js +9 -6
  89. package/dist/augments/object/merge-defined-properties.d.ts +19 -0
  90. package/dist/augments/object/merge-defined-properties.js +32 -0
  91. package/dist/augments/object/merge-property-arrays.d.ts +29 -0
  92. package/dist/augments/object/merge-property-arrays.js +39 -0
  93. package/dist/augments/object/object-entries.d.ts +31 -0
  94. package/dist/augments/object/object-entries.js +40 -0
  95. package/dist/augments/object/object-filter.d.ts +22 -0
  96. package/dist/augments/object/object-filter.js +27 -0
  97. package/dist/augments/object/object-keys.d.ts +34 -0
  98. package/dist/augments/object/object-keys.js +43 -0
  99. package/dist/augments/object/object-values.d.ts +11 -0
  100. package/dist/augments/object/object-values.js +13 -0
  101. package/dist/augments/path/esm-path.d.ts +26 -0
  102. package/dist/augments/path/esm-path.js +31 -0
  103. package/dist/augments/prisma/prisma-models.d.ts +143 -0
  104. package/dist/augments/prisma/prisma-models.js +1 -0
  105. package/dist/augments/promise/timed-promise.d.ts +22 -0
  106. package/dist/augments/promise/timed-promise.js +51 -0
  107. package/dist/augments/random/random-boolean.d.ts +24 -0
  108. package/dist/augments/random/random-boolean.js +32 -0
  109. package/dist/augments/random/random-integer.d.ts +14 -0
  110. package/dist/augments/random/random-integer.js +34 -0
  111. package/dist/augments/random/random-string.d.ts +18 -0
  112. package/dist/augments/random/random-string.js +67 -0
  113. package/dist/augments/regexp/match.d.ts +10 -0
  114. package/dist/augments/regexp/match.js +13 -0
  115. package/dist/augments/regexp/regexp-flags.d.ts +56 -0
  116. package/dist/augments/regexp/regexp-flags.js +75 -0
  117. package/dist/augments/regexp/regexp-string.d.ts +9 -0
  118. package/dist/augments/regexp/regexp-string.js +11 -0
  119. package/dist/augments/selection-set/select-collapsed.d.ts +54 -0
  120. package/dist/augments/selection-set/select-collapsed.js +63 -0
  121. package/dist/augments/selection-set/select-from.d.ts +48 -0
  122. package/dist/augments/selection-set/select-from.js +72 -0
  123. package/dist/augments/selection-set/selection-set.d.ts +37 -0
  124. package/dist/augments/selection-set/selection-set.js +1 -0
  125. package/dist/augments/string/casing/capitalization.d.ts +17 -0
  126. package/dist/augments/string/casing/capitalization.js +25 -0
  127. package/dist/augments/string/casing/casing.d.ts +73 -0
  128. package/dist/augments/string/casing/casing.js +65 -0
  129. package/dist/augments/string/casing/kebab-and-camel.d.ts +17 -0
  130. package/dist/augments/string/casing/kebab-and-camel.js +57 -0
  131. package/dist/augments/string/comma.d.ts +26 -0
  132. package/dist/augments/string/comma.js +48 -0
  133. package/dist/augments/string/join.d.ts +21 -0
  134. package/dist/augments/string/join.js +34 -0
  135. package/dist/augments/string/prefix.d.ts +30 -0
  136. package/dist/augments/string/prefix.js +30 -0
  137. package/dist/augments/string/remove-duplicate-characters.d.ts +17 -0
  138. package/dist/augments/string/remove-duplicate-characters.js +22 -0
  139. package/dist/augments/string/replace.d.ts +18 -0
  140. package/dist/augments/string/replace.js +22 -0
  141. package/dist/augments/string/split.d.ts +31 -0
  142. package/dist/augments/string/split.js +53 -0
  143. package/dist/augments/string/substring-index.d.ts +19 -0
  144. package/dist/augments/string/substring-index.js +47 -0
  145. package/dist/augments/string/suffix.d.ts +96 -0
  146. package/dist/augments/string/suffix.js +89 -0
  147. package/dist/augments/string/white-space.d.ts +12 -0
  148. package/dist/augments/string/white-space.js +19 -0
  149. package/dist/augments/string/wrap-string.d.ts +19 -0
  150. package/dist/augments/string/wrap-string.js +20 -0
  151. package/dist/augments/type/ensure-type.d.ts +12 -0
  152. package/dist/augments/type/ensure-type.js +14 -0
  153. package/dist/augments/type/readonly.d.ts +9 -0
  154. package/dist/augments/type/readonly.js +10 -0
  155. package/dist/augments/type/type-recursion.d.ts +253 -0
  156. package/dist/augments/type/type-recursion.js +1 -0
  157. package/dist/augments/type/union.d.ts +1 -0
  158. package/dist/augments/type/union.js +1 -0
  159. package/dist/augments/type/void-type.d.ts +9 -0
  160. package/dist/augments/type/void-type.js +1 -0
  161. package/dist/augments/type/writable.d.ts +10 -0
  162. package/dist/augments/type/writable.js +10 -0
  163. package/dist/index.d.ts +83 -0
  164. package/dist/index.js +83 -0
  165. package/package.json +43 -15
  166. package/dist/cjs/augments/ansi.js +0 -27
  167. package/dist/cjs/augments/array/array.js +0 -68
  168. package/dist/cjs/augments/array/remove-duplicates.js +0 -16
  169. package/dist/cjs/augments/async.js +0 -28
  170. package/dist/cjs/augments/boolean.js +0 -19
  171. package/dist/cjs/augments/common-number.js +0 -112
  172. package/dist/cjs/augments/common-string.js +0 -245
  173. package/dist/cjs/augments/debounce.js +0 -38
  174. package/dist/cjs/augments/environment.js +0 -6
  175. package/dist/cjs/augments/error.js +0 -52
  176. package/dist/cjs/augments/esm-path.js +0 -11
  177. package/dist/cjs/augments/function.js +0 -2
  178. package/dist/cjs/augments/json-compatible.js +0 -2
  179. package/dist/cjs/augments/json.js +0 -28
  180. package/dist/cjs/augments/object/any-object.js +0 -2
  181. package/dist/cjs/augments/object/enum.js +0 -48
  182. package/dist/cjs/augments/object/filter-object.js +0 -26
  183. package/dist/cjs/augments/object/get-or-set.js +0 -40
  184. package/dist/cjs/augments/object/has-key.js +0 -6
  185. package/dist/cjs/augments/object/jsonify.js +0 -6
  186. package/dist/cjs/augments/object/key-count.js +0 -2
  187. package/dist/cjs/augments/object/map-object.js +0 -61
  188. package/dist/cjs/augments/object/merge-deep.js +0 -52
  189. package/dist/cjs/augments/object/merge-property-arrays.js +0 -14
  190. package/dist/cjs/augments/object/object-entries.js +0 -40
  191. package/dist/cjs/augments/object/object.js +0 -18
  192. package/dist/cjs/augments/object/pick-deep.js +0 -2
  193. package/dist/cjs/augments/object/selection-set.js +0 -56
  194. package/dist/cjs/augments/object/typed-has-property.js +0 -29
  195. package/dist/cjs/augments/promise/deferred-promise.js +0 -31
  196. package/dist/cjs/augments/promise/promise.js +0 -79
  197. package/dist/cjs/augments/promise/wait.js +0 -66
  198. package/dist/cjs/augments/random.js +0 -118
  199. package/dist/cjs/augments/regexp.js +0 -19
  200. package/dist/cjs/augments/string/prefixes.js +0 -20
  201. package/dist/cjs/augments/string/suffixes.js +0 -40
  202. package/dist/cjs/augments/string/uuid.js +0 -13
  203. package/dist/cjs/augments/time.js +0 -35
  204. package/dist/cjs/augments/truncate-number.js +0 -153
  205. package/dist/cjs/augments/tuple.js +0 -20
  206. package/dist/cjs/augments/type-recursion.js +0 -2
  207. package/dist/cjs/augments/type.js +0 -36
  208. package/dist/cjs/augments/union.js +0 -2
  209. package/dist/cjs/augments/wrap-in-try.js +0 -37
  210. package/dist/cjs/index.js +0 -60
  211. package/dist/esm/augments/ansi.js +0 -24
  212. package/dist/esm/augments/array/array.js +0 -57
  213. package/dist/esm/augments/array/remove-duplicates.js +0 -13
  214. package/dist/esm/augments/async.js +0 -23
  215. package/dist/esm/augments/boolean.js +0 -14
  216. package/dist/esm/augments/common-number.js +0 -100
  217. package/dist/esm/augments/common-string.js +0 -227
  218. package/dist/esm/augments/debounce.js +0 -34
  219. package/dist/esm/augments/environment.js +0 -3
  220. package/dist/esm/augments/error.js +0 -45
  221. package/dist/esm/augments/esm-path.js +0 -8
  222. package/dist/esm/augments/json.js +0 -24
  223. package/dist/esm/augments/object/enum.js +0 -41
  224. package/dist/esm/augments/object/filter-object.js +0 -21
  225. package/dist/esm/augments/object/get-or-set.js +0 -36
  226. package/dist/esm/augments/object/has-key.js +0 -3
  227. package/dist/esm/augments/object/jsonify.js +0 -3
  228. package/dist/esm/augments/object/map-object.js +0 -57
  229. package/dist/esm/augments/object/merge-property-arrays.js +0 -11
  230. package/dist/esm/augments/object/object-entries.js +0 -32
  231. package/dist/esm/augments/object/object.js +0 -14
  232. package/dist/esm/augments/object/selection-set.js +0 -52
  233. package/dist/esm/augments/object/typed-has-property.js +0 -25
  234. package/dist/esm/augments/promise/deferred-promise.js +0 -28
  235. package/dist/esm/augments/promise/promise.js +0 -71
  236. package/dist/esm/augments/promise/wait.js +0 -60
  237. package/dist/esm/augments/random.js +0 -113
  238. package/dist/esm/augments/regexp.js +0 -14
  239. package/dist/esm/augments/string/prefixes.js +0 -16
  240. package/dist/esm/augments/string/suffixes.js +0 -31
  241. package/dist/esm/augments/string/uuid.js +0 -9
  242. package/dist/esm/augments/time.js +0 -31
  243. package/dist/esm/augments/tuple.js +0 -16
  244. package/dist/esm/augments/type.js +0 -30
  245. package/dist/esm/augments/wrap-in-try.js +0 -34
  246. package/dist/esm/index.js +0 -44
  247. package/dist/types/augments/ansi.d.ts +0 -1
  248. package/dist/types/augments/array/array.d.ts +0 -26
  249. package/dist/types/augments/array/remove-duplicates.d.ts +0 -1
  250. package/dist/types/augments/async.d.ts +0 -14
  251. package/dist/types/augments/boolean.d.ts +0 -6
  252. package/dist/types/augments/common-number.d.ts +0 -52
  253. package/dist/types/augments/common-string.d.ts +0 -74
  254. package/dist/types/augments/debounce.d.ts +0 -15
  255. package/dist/types/augments/environment.d.ts +0 -1
  256. package/dist/types/augments/error.d.ts +0 -9
  257. package/dist/types/augments/esm-path.d.ts +0 -4
  258. package/dist/types/augments/function.d.ts +0 -25
  259. package/dist/types/augments/json-compatible.d.ts +0 -22
  260. package/dist/types/augments/json.d.ts +0 -9
  261. package/dist/types/augments/object/any-object.d.ts +0 -2
  262. package/dist/types/augments/object/enum.d.ts +0 -8
  263. package/dist/types/augments/object/filter-object.d.ts +0 -4
  264. package/dist/types/augments/object/get-or-set.d.ts +0 -26
  265. package/dist/types/augments/object/has-key.d.ts +0 -1
  266. package/dist/types/augments/object/jsonify.d.ts +0 -2
  267. package/dist/types/augments/object/key-count.d.ts +0 -13
  268. package/dist/types/augments/object/map-object.d.ts +0 -20
  269. package/dist/types/augments/object/merge-property-arrays.d.ts +0 -1
  270. package/dist/types/augments/object/object-entries.d.ts +0 -8
  271. package/dist/types/augments/object/object.d.ts +0 -21
  272. package/dist/types/augments/object/pick-deep.d.ts +0 -14
  273. package/dist/types/augments/object/selection-set.d.ts +0 -27
  274. package/dist/types/augments/object/typed-has-property.d.ts +0 -7
  275. package/dist/types/augments/promise/deferred-promise.d.ts +0 -8
  276. package/dist/types/augments/promise/promise.d.ts +0 -15
  277. package/dist/types/augments/promise/wait.d.ts +0 -18
  278. package/dist/types/augments/random.d.ts +0 -37
  279. package/dist/types/augments/regexp.d.ts +0 -3
  280. package/dist/types/augments/string/prefixes.d.ts +0 -9
  281. package/dist/types/augments/string/suffixes.d.ts +0 -17
  282. package/dist/types/augments/string/uuid.d.ts +0 -5
  283. package/dist/types/augments/time.d.ts +0 -14
  284. package/dist/types/augments/truncate-number.d.ts +0 -19
  285. package/dist/types/augments/tuple.d.ts +0 -17
  286. package/dist/types/augments/type-recursion.d.ts +0 -161
  287. package/dist/types/augments/type.d.ts +0 -69
  288. package/dist/types/augments/union.d.ts +0 -5
  289. package/dist/types/index.d.ts +0 -44
  290. /package/dist/{esm/augments → augments/json}/json-compatible.js +0 -0
  291. /package/dist/{esm/augments/function.js → augments/log/log-writer.js} +0 -0
  292. /package/dist/{esm/augments/object/any-object.js → augments/number/coords.js} +0 -0
  293. /package/dist/{esm/augments/object/key-count.js → augments/number/digit.js} +0 -0
  294. /package/dist/{esm/augments/object/pick-deep.js → augments/number/dimensions.js} +0 -0
  295. /package/dist/{esm/augments/type-recursion.js → augments/object/empty.js} +0 -0
  296. /package/dist/{esm/augments/union.js → augments/object/key-count.js} +0 -0
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Supported log output types.
3
+ *
4
+ * @category Log : Util
5
+ * @category Package : @augment-vir/common
6
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
7
+ */
8
+ export declare enum LogOutputType {
9
+ /** Logged to stdout if the current environment supports it, or just `console.log`. */
10
+ Standard = "stdout",
11
+ /** Logged to stderr if the current environment supports it, or just `console.error`. */
12
+ Error = "stderr"
13
+ }
14
+ /**
15
+ * Standardized color keys for logging. If you want to use customized colors, use
16
+ * [ansi-styles](https://www.npmjs.com/package/ansi-styles) in Node.js or [custom
17
+ * CSS](https://developer.mozilla.org/docs/Web/API/console#styling_console_output) in browsers.
18
+ *
19
+ * @category Log : Util
20
+ * @category Package : @augment-vir/common
21
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
22
+ */
23
+ export declare enum LogColorKey {
24
+ Bold = "bold",
25
+ Debug = "debug",
26
+ Error = "error",
27
+ Faint = "faint",
28
+ Info = "info",
29
+ Mutate = "mutate",
30
+ NormalWeight = "normalWeight",
31
+ Plain = "plain",
32
+ Reset = "reset",
33
+ Success = "success",
34
+ Warning = "warning"
35
+ }
36
+ /**
37
+ * Configuration for creating a logger. This is not required, as a default configuration is built-in
38
+ * already.
39
+ *
40
+ * @category Log : Util
41
+ * @category Package : @augment-vir/common
42
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
43
+ */
44
+ export type LogColorConfig = Readonly<Record<LogColorKey, {
45
+ /** Either an array of CSS property assignments */
46
+ colors: string[];
47
+ logType: LogOutputType;
48
+ }>>;
49
+ /**
50
+ * Mapping of color keys to the current color string.
51
+ *
52
+ * @category Log : Util
53
+ * @category Package : @augment-vir/common
54
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
55
+ */
56
+ export declare const logColors: Readonly<Record<LogColorKey, string>>;
57
+ /**
58
+ * Default implementation of {@link LogColorConfig}.
59
+ *
60
+ * @category Log : Util
61
+ * @category Package : @augment-vir/common
62
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
63
+ */
64
+ export declare const defaultLogColorConfig: LogColorConfig;
@@ -0,0 +1,157 @@
1
+ import { perEnv, RuntimeEnv } from '@augment-vir/core';
2
+ /**
3
+ * Supported log output types.
4
+ *
5
+ * @category Log : Util
6
+ * @category Package : @augment-vir/common
7
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
8
+ */
9
+ export var LogOutputType;
10
+ (function (LogOutputType) {
11
+ /** Logged to stdout if the current environment supports it, or just `console.log`. */
12
+ LogOutputType["Standard"] = "stdout";
13
+ /** Logged to stderr if the current environment supports it, or just `console.error`. */
14
+ LogOutputType["Error"] = "stderr";
15
+ })(LogOutputType || (LogOutputType = {}));
16
+ /**
17
+ * Standardized color keys for logging. If you want to use customized colors, use
18
+ * [ansi-styles](https://www.npmjs.com/package/ansi-styles) in Node.js or [custom
19
+ * CSS](https://developer.mozilla.org/docs/Web/API/console#styling_console_output) in browsers.
20
+ *
21
+ * @category Log : Util
22
+ * @category Package : @augment-vir/common
23
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
24
+ */
25
+ export var LogColorKey;
26
+ (function (LogColorKey) {
27
+ LogColorKey["Bold"] = "bold";
28
+ LogColorKey["Debug"] = "debug";
29
+ LogColorKey["Error"] = "error";
30
+ LogColorKey["Faint"] = "faint";
31
+ LogColorKey["Info"] = "info";
32
+ LogColorKey["Mutate"] = "mutate";
33
+ LogColorKey["NormalWeight"] = "normalWeight";
34
+ LogColorKey["Plain"] = "plain";
35
+ LogColorKey["Reset"] = "reset";
36
+ LogColorKey["Success"] = "success";
37
+ LogColorKey["Warning"] = "warning";
38
+ })(LogColorKey || (LogColorKey = {}));
39
+ async function determineDefaultLogColors() {
40
+ return await perEnv({
41
+ /** We calculate coverage in web, so the node code will never run in coverage tests. */
42
+ /* node:coverage disable */
43
+ async [RuntimeEnv.Node]() {
44
+ const styles = (await import('ansi-styles')).default;
45
+ return {
46
+ [LogColorKey.Bold]: styles.bold.open,
47
+ [LogColorKey.Debug]: styles.blueBright.open,
48
+ [LogColorKey.Error]: styles.red.open,
49
+ [LogColorKey.Faint]: styles.gray.open,
50
+ [LogColorKey.Info]: styles.cyan.open,
51
+ [LogColorKey.Mutate]: styles.magenta.open,
52
+ [LogColorKey.NormalWeight]: '\x1b[22m',
53
+ [LogColorKey.Plain]: '',
54
+ [LogColorKey.Reset]: styles.reset.open,
55
+ [LogColorKey.Success]: styles.green.open,
56
+ [LogColorKey.Warning]: styles.yellow.open,
57
+ };
58
+ },
59
+ /* node:coverage enable */
60
+ [RuntimeEnv.Web]() {
61
+ return Promise.resolve({
62
+ [LogColorKey.Bold]: 'font-weight: bold',
63
+ [LogColorKey.Debug]: 'color: blue',
64
+ [LogColorKey.Error]: 'color: red',
65
+ [LogColorKey.Faint]: 'color: grey',
66
+ [LogColorKey.Info]: 'color: teal',
67
+ [LogColorKey.Mutate]: 'color: magenta',
68
+ [LogColorKey.NormalWeight]: '',
69
+ [LogColorKey.Plain]: '',
70
+ [LogColorKey.Reset]: '',
71
+ [LogColorKey.Success]: 'color: green',
72
+ [LogColorKey.Warning]: 'color: orange',
73
+ });
74
+ },
75
+ });
76
+ }
77
+ /**
78
+ * Mapping of color keys to the current color string.
79
+ *
80
+ * @category Log : Util
81
+ * @category Package : @augment-vir/common
82
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
83
+ */
84
+ export const logColors = await determineDefaultLogColors();
85
+ /**
86
+ * Default implementation of {@link LogColorConfig}.
87
+ *
88
+ * @category Log : Util
89
+ * @category Package : @augment-vir/common
90
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
91
+ */
92
+ export const defaultLogColorConfig = {
93
+ [LogColorKey.Bold]: {
94
+ colors: [
95
+ logColors.bold,
96
+ ],
97
+ logType: LogOutputType.Standard,
98
+ },
99
+ [LogColorKey.Debug]: {
100
+ colors: [
101
+ logColors.debug,
102
+ ],
103
+ logType: LogOutputType.Standard,
104
+ },
105
+ [LogColorKey.Faint]: {
106
+ colors: [
107
+ logColors.faint,
108
+ ],
109
+ logType: LogOutputType.Standard,
110
+ },
111
+ [LogColorKey.Info]: {
112
+ colors: [
113
+ logColors.info,
114
+ ],
115
+ logType: LogOutputType.Standard,
116
+ },
117
+ [LogColorKey.Mutate]: {
118
+ colors: [
119
+ logColors.mutate,
120
+ logColors.bold,
121
+ ],
122
+ logType: LogOutputType.Standard,
123
+ },
124
+ [LogColorKey.NormalWeight]: {
125
+ colors: [
126
+ logColors.normalWeight,
127
+ ],
128
+ logType: LogOutputType.Standard,
129
+ },
130
+ [LogColorKey.Plain]: { colors: [], logType: LogOutputType.Standard },
131
+ [LogColorKey.Reset]: {
132
+ colors: [
133
+ logColors.reset,
134
+ ],
135
+ logType: LogOutputType.Standard,
136
+ },
137
+ [LogColorKey.Success]: {
138
+ colors: [
139
+ logColors.success,
140
+ logColors.bold,
141
+ ],
142
+ logType: LogOutputType.Standard,
143
+ },
144
+ [LogColorKey.Error]: {
145
+ colors: [
146
+ logColors.error,
147
+ logColors.bold,
148
+ ],
149
+ logType: LogOutputType.Error,
150
+ },
151
+ [LogColorKey.Warning]: {
152
+ colors: [
153
+ logColors.warning,
154
+ ],
155
+ logType: LogOutputType.Error,
156
+ },
157
+ };
@@ -0,0 +1,35 @@
1
+ import { LogColorKey, type LogColorConfig } from './log-colors.js';
2
+ import { LogWriterParams } from './log-writer.js';
3
+ /**
4
+ * Options for a custom Logger.
5
+ *
6
+ * @category Log : Util
7
+ * @category Package : @augment-vir/common
8
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
9
+ */
10
+ export type LoggerOptions = {
11
+ colorConfig: LogColorConfig;
12
+ omitColors: boolean;
13
+ };
14
+ /**
15
+ * Parameters for {@link toLogString}.
16
+ *
17
+ * @category Log : Util
18
+ * @category Package : @augment-vir/common
19
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
20
+ */
21
+ export type ToLogStringParams = {
22
+ colorKey: LogColorKey;
23
+ args: ReadonlyArray<any>;
24
+ options: Readonly<LoggerOptions>;
25
+ };
26
+ type ToLogString = (params: Readonly<ToLogStringParams>) => LogWriterParams;
27
+ /**
28
+ * Converts log arguments into a single {@link LogWriterParams}.
29
+ *
30
+ * @category Log : Util
31
+ * @category Package : @augment-vir/common
32
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
33
+ */
34
+ export declare const toLogString: ToLogString;
35
+ export {};
@@ -0,0 +1,73 @@
1
+ import { check } from '@augment-vir/assert';
2
+ import { perEnv, RuntimeEnv, stringify } from '@augment-vir/core';
3
+ import { filterMap } from '../array/filter.js';
4
+ import { removeSuffix } from '../string/suffix.js';
5
+ import { LogColorKey } from './log-colors.js';
6
+ async function createToLogString() {
7
+ return await perEnv({
8
+ /** We calculate coverage in web, so the node code will never run in coverage tests. */
9
+ /* node:coverage disable */
10
+ async [RuntimeEnv.Node]() {
11
+ const { inspect } = await import('node:util');
12
+ return ({ args, colorKey, options }) => {
13
+ const argStrings = args.map((arg) => {
14
+ if (typeof arg === 'string') {
15
+ return arg;
16
+ }
17
+ else {
18
+ return inspect(arg);
19
+ }
20
+ });
21
+ const colorsString = options.omitColors
22
+ ? ''
23
+ : options.colorConfig[colorKey].colors.join('');
24
+ const text = [
25
+ colorsString,
26
+ argStrings.join('\n'),
27
+ options.omitColors
28
+ ? ''
29
+ : options.colorConfig[LogColorKey.Reset].colors.join(''),
30
+ ].join('');
31
+ return { text, css: undefined };
32
+ };
33
+ },
34
+ /**
35
+ * We have no way to test color output in the browser console so this block is ignored in
36
+ * coverage as well.
37
+ */
38
+ [RuntimeEnv.Web]() {
39
+ return ({ args, colorKey, options }) => {
40
+ const css = options.omitColors
41
+ ? undefined
42
+ : filterMap(options.colorConfig[colorKey].colors, (cssString) => removeSuffix({
43
+ value: cssString,
44
+ suffix: ';',
45
+ }), check.isTruthy).join('; ');
46
+ const argStrings = args.map((arg) => {
47
+ if (typeof arg === 'string') {
48
+ return arg;
49
+ }
50
+ else {
51
+ return stringify(arg);
52
+ }
53
+ });
54
+ const text = [
55
+ argStrings.join('\n'),
56
+ options.omitColors
57
+ ? ''
58
+ : options.colorConfig[LogColorKey.Reset].colors.join(''),
59
+ ].join('');
60
+ return { text, css };
61
+ };
62
+ },
63
+ /* node:coverage enable */
64
+ });
65
+ }
66
+ /**
67
+ * Converts log arguments into a single {@link LogWriterParams}.
68
+ *
69
+ * @category Log : Util
70
+ * @category Package : @augment-vir/common
71
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
72
+ */
73
+ export const toLogString = await createToLogString();
@@ -0,0 +1,30 @@
1
+ import { type LogOutputType } from './log-colors.js';
2
+ /**
3
+ * Params for {@link LogWriter}
4
+ *
5
+ * @category Log : Util
6
+ * @category Package : @augment-vir/common
7
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
8
+ */
9
+ export type LogWriterParams = {
10
+ text: string;
11
+ /** Typically this is only relevant in a browser console. */
12
+ css: string | undefined;
13
+ };
14
+ /**
15
+ * The final step in writing a log. This will actually perform the logging of text to the console.
16
+ * CSS will be applied if this is called within a browser.
17
+ *
18
+ * @category Log : Util
19
+ * @category Package : @augment-vir/common
20
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
21
+ */
22
+ export type LogWriter = (params: Readonly<LogWriterParams>) => void;
23
+ /**
24
+ * A log writer for each log output type.
25
+ *
26
+ * @category Log : Util
27
+ * @category Package : @augment-vir/common
28
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
29
+ */
30
+ export type LogWriters = Record<LogOutputType, LogWriter>;
@@ -0,0 +1,56 @@
1
+ import { type PartialWithUndefined } from '@augment-vir/core';
2
+ import { LoggerOptions } from './log-string.js';
3
+ import { LogWriters } from './log-writer.js';
4
+ import { type Logger } from './logger.js';
5
+ /**
6
+ * Default implementation of {@link LogWriters} that is dependent on the current runtime environment.
7
+ *
8
+ * @category Log : Util
9
+ * @category Package : @augment-vir/common
10
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
11
+ */
12
+ export declare const defaultLogWriters: LogWriters;
13
+ /**
14
+ * The default `log`. Use this in place of `console` methods for styled outputs in both Node.js and
15
+ * the browser.
16
+ *
17
+ * @category Log
18
+ * @category Package : @augment-vir/common
19
+ * @example
20
+ *
21
+ * ```ts
22
+ * import {log} from '@augment-vir/common';
23
+ *
24
+ * log.info('hi');
25
+ * log.error('failure');
26
+ * ```
27
+ *
28
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
29
+ */
30
+ export declare const log: Logger;
31
+ /**
32
+ * Creates a custom logger that doesn't actually log but stores the logs into a object for later
33
+ * usage. This is particularly useful in tests.
34
+ *
35
+ * @category Log
36
+ * @category Package : @augment-vir/common
37
+ * @example
38
+ *
39
+ * ```ts
40
+ * import {createArrayLogger} from '@augment-vir/common';
41
+ *
42
+ * const {log, logs} = createArrayLogger();
43
+ *
44
+ * log.info('hi');
45
+ * // `logs[LogOutputType.Standard]` is now `['hi']`
46
+ * ```
47
+ *
48
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
49
+ */
50
+ export declare function createArrayLogger(options?: PartialWithUndefined<LoggerOptions> | undefined): {
51
+ log: Logger;
52
+ logs: {
53
+ stdout: string[];
54
+ stderr: string[];
55
+ };
56
+ };
@@ -0,0 +1,85 @@
1
+ import { isRuntimeEnv, RuntimeEnv } from '@augment-vir/core';
2
+ import { addPrefix } from '../string/prefix.js';
3
+ import { LogOutputType } from './log-colors.js';
4
+ import { createLogger } from './logger.js';
5
+ /**
6
+ * Default implementation of {@link LogWriters} that is dependent on the current runtime environment.
7
+ *
8
+ * @category Log : Util
9
+ * @category Package : @augment-vir/common
10
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
11
+ */
12
+ export const defaultLogWriters =
13
+ /** We calculate coverage in web, so the node code will never run in coverage tests. */
14
+ /* node:coverage disable */
15
+ isRuntimeEnv(RuntimeEnv.Node)
16
+ ? {
17
+ [LogOutputType.Error]({ text }) {
18
+ process.stderr.write(text + '\n');
19
+ },
20
+ [LogOutputType.Standard]({ text }) {
21
+ process.stdout.write(text + '\n');
22
+ },
23
+ }
24
+ : /* node:coverage enable */
25
+ {
26
+ [LogOutputType.Error]({ text, css }) {
27
+ console.error(addPrefix({ value: text, prefix: '%c' }), css);
28
+ },
29
+ [LogOutputType.Standard]({ text, css }) {
30
+ // eslint-disable-next-line no-console
31
+ console.log(addPrefix({ value: text, prefix: '%c' }), css);
32
+ },
33
+ };
34
+ /**
35
+ * The default `log`. Use this in place of `console` methods for styled outputs in both Node.js and
36
+ * the browser.
37
+ *
38
+ * @category Log
39
+ * @category Package : @augment-vir/common
40
+ * @example
41
+ *
42
+ * ```ts
43
+ * import {log} from '@augment-vir/common';
44
+ *
45
+ * log.info('hi');
46
+ * log.error('failure');
47
+ * ```
48
+ *
49
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
50
+ */
51
+ export const log = createLogger(defaultLogWriters);
52
+ /**
53
+ * Creates a custom logger that doesn't actually log but stores the logs into a object for later
54
+ * usage. This is particularly useful in tests.
55
+ *
56
+ * @category Log
57
+ * @category Package : @augment-vir/common
58
+ * @example
59
+ *
60
+ * ```ts
61
+ * import {createArrayLogger} from '@augment-vir/common';
62
+ *
63
+ * const {log, logs} = createArrayLogger();
64
+ *
65
+ * log.info('hi');
66
+ * // `logs[LogOutputType.Standard]` is now `['hi']`
67
+ * ```
68
+ *
69
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
70
+ */
71
+ export function createArrayLogger(options) {
72
+ const logs = {
73
+ [LogOutputType.Standard]: [],
74
+ [LogOutputType.Error]: [],
75
+ };
76
+ const log = createLogger({
77
+ stderr({ text }) {
78
+ logs.stderr.push(text);
79
+ },
80
+ stdout({ text }) {
81
+ logs.stdout.push(text);
82
+ },
83
+ }, options);
84
+ return { log, logs };
85
+ }
@@ -0,0 +1,60 @@
1
+ import type { PartialWithUndefined } from '@augment-vir/core';
2
+ import { LogColorKey } from './log-colors.js';
3
+ import { type LoggerOptions } from './log-string.js';
4
+ import { type LogWriters } from './log-writer.js';
5
+ /**
6
+ * The base `log` methods.
7
+ *
8
+ * @category Log : Util
9
+ * @category Package : @augment-vir/common
10
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
11
+ */
12
+ export type LoggerLogs = Readonly<Record<LogColorKey, (...args: ReadonlyArray<unknown>) => void>>;
13
+ /**
14
+ * Type for the `log` export.
15
+ *
16
+ * @category Log : Util
17
+ * @category Package : @augment-vir/common
18
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
19
+ */
20
+ export type Logger = LoggerLogs & {
21
+ /**
22
+ * Only logs if the given condition is `true`.
23
+ *
24
+ * @example
25
+ *
26
+ * ```ts
27
+ * import {log} from '@augment-vir/common';
28
+ *
29
+ * // this will log
30
+ * log.if(true).info('hi');
31
+ * // this will not log
32
+ * log.if(false).info('hi');
33
+ * ```
34
+ */
35
+ if: (condition: boolean) => LoggerLogs;
36
+ };
37
+ /**
38
+ * Default implementation of {@link LoggerOptions}.
39
+ *
40
+ * @category Log : Util
41
+ * @category Package : @augment-vir/common
42
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
43
+ */
44
+ export declare const defaultLoggerOptions: LoggerOptions;
45
+ /**
46
+ * A default {@link Logger} that simply does nothing.
47
+ *
48
+ * @category Log
49
+ * @category Package : @augment-vir/common
50
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
51
+ */
52
+ export declare const emptyLog: Logger;
53
+ /**
54
+ * Creates a custom {@link Logger}.
55
+ *
56
+ * @category Log
57
+ * @category Package : @augment-vir/common
58
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
59
+ */
60
+ export declare function createLogger(logWriters: LogWriters, optionsOverride?: PartialWithUndefined<LoggerOptions> | undefined): Logger;
@@ -0,0 +1,59 @@
1
+ import { mapEnumToObject } from '../object/map-enum.js';
2
+ import { mergeDefinedProperties } from '../object/merge-defined-properties.js';
3
+ import { defaultLogColorConfig, LogColorKey, LogOutputType } from './log-colors.js';
4
+ import { toLogString } from './log-string.js';
5
+ /**
6
+ * Default implementation of {@link LoggerOptions}.
7
+ *
8
+ * @category Log : Util
9
+ * @category Package : @augment-vir/common
10
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
11
+ */
12
+ export const defaultLoggerOptions = {
13
+ colorConfig: defaultLogColorConfig,
14
+ omitColors: false,
15
+ };
16
+ /**
17
+ * A default {@link Logger} that simply does nothing.
18
+ *
19
+ * @category Log
20
+ * @category Package : @augment-vir/common
21
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
22
+ */
23
+ export const emptyLog = createLogger({
24
+ [LogOutputType.Error]() { },
25
+ [LogOutputType.Standard]() { },
26
+ });
27
+ /**
28
+ * Creates a custom {@link Logger}.
29
+ *
30
+ * @category Log
31
+ * @category Package : @augment-vir/common
32
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
33
+ */
34
+ export function createLogger(logWriters, optionsOverride) {
35
+ const options = mergeDefinedProperties(defaultLoggerOptions, optionsOverride);
36
+ function writeLog(params) {
37
+ logWriters[options.colorConfig[params.colorKey].logType](toLogString({
38
+ ...params,
39
+ options,
40
+ }));
41
+ }
42
+ const loggerLogs = mapEnumToObject(LogColorKey, (colorKey) => {
43
+ return (...args) => writeLog({
44
+ args,
45
+ colorKey,
46
+ });
47
+ });
48
+ return {
49
+ ...loggerLogs,
50
+ if(condition) {
51
+ if (condition) {
52
+ return loggerLogs;
53
+ }
54
+ else {
55
+ return emptyLog;
56
+ }
57
+ },
58
+ };
59
+ }
@@ -0,0 +1,18 @@
1
+ import { MinMax } from './min-max.js';
2
+ /**
3
+ * Clamp's the given value to within the min and max bounds, inclusive.
4
+ *
5
+ * @category Number
6
+ * @category Package : @augment-vir/common
7
+ * @example
8
+ *
9
+ * ```ts
10
+ * import {clamp} from '@augment-vir/common';
11
+ *
12
+ * // `result` will be `40`
13
+ * const result = clamp(42, {min: 30, max: 40});
14
+ * ```
15
+ *
16
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
17
+ */
18
+ export declare function clamp(value: number, { min, max }: Readonly<MinMax>): number;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Clamp's the given value to within the min and max bounds, inclusive.
3
+ *
4
+ * @category Number
5
+ * @category Package : @augment-vir/common
6
+ * @example
7
+ *
8
+ * ```ts
9
+ * import {clamp} from '@augment-vir/common';
10
+ *
11
+ * // `result` will be `40`
12
+ * const result = clamp(42, {min: 30, max: 40});
13
+ * ```
14
+ *
15
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
16
+ */
17
+ export function clamp(value, { min, max }) {
18
+ return Math.min(Math.max(value, min), max);
19
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * A simple type for storing 2D coordinates.
3
+ *
4
+ * @category Number
5
+ * @category Package : @augment-vir/common
6
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
7
+ */
8
+ export type Coords = {
9
+ x: number;
10
+ y: number;
11
+ };
12
+ /**
13
+ * A simple type for storing 3D coordinates.
14
+ *
15
+ * @category Number
16
+ * @category Package : @augment-vir/common
17
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
18
+ */
19
+ export type Coords3d = {
20
+ x: number;
21
+ y: number;
22
+ z: number;
23
+ };