@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,10 @@
1
+ import { MaybePromise, type AnyObject } from '@augment-vir/core';
2
+ export declare function getOrSetFromMap<MapKey extends object, MapValue>(map: WeakMap<MapKey, MapValue>, key: MapKey, createCallback: () => MapValue): MapValue;
3
+ export declare function getOrSetFromMap<MapKey, MapValue>(map: Map<MapKey, MapValue>, key: MapKey, createCallback: () => MapValue): MapValue;
4
+ export declare function getOrSetFromMap<MapKey extends object, MapValue>(map: WeakMap<MapKey, MapValue>, key: MapKey, createCallback: () => Promise<MapValue>): Promise<MapValue>;
5
+ export declare function getOrSetFromMap<MapKey, MapValue>(map: Map<MapKey, MapValue>, key: MapKey, createCallback: () => Promise<MapValue>): Promise<MapValue>;
6
+ export declare function getOrSetFromMap<MapKey extends object, MapValue>(map: WeakMap<MapKey, MapValue>, key: MapKey, createCallback: () => MaybePromise<MapValue>): MaybePromise<MapValue>;
7
+ export declare function getOrSetFromMap<MapKey, MapValue>(map: Map<MapKey, MapValue>, key: MapKey, createCallback: () => MaybePromise<MapValue>): MaybePromise<MapValue>;
8
+ export declare function getOrSet<OriginalObject extends AnyObject, Key extends keyof OriginalObject>(originalObject: OriginalObject, key: Key, createCallback: () => OriginalObject[Key]): Required<OriginalObject>[Key];
9
+ export declare function getOrSet<OriginalObject extends AnyObject, Key extends keyof OriginalObject>(originalObject: OriginalObject, key: Key, createCallback: () => Promise<OriginalObject[Key]>): Promise<Required<OriginalObject>[Key]>;
10
+ export declare function getOrSet<OriginalObject extends AnyObject, Key extends keyof OriginalObject>(originalObject: OriginalObject, key: Key, createCallback: () => MaybePromise<OriginalObject[Key]>): MaybePromise<Required<OriginalObject>[Key]>;
@@ -0,0 +1,100 @@
1
+ import { check } from '@augment-vir/assert';
2
+ import { ensureError } from '@augment-vir/core';
3
+ /**
4
+ * Given an map, tries to get the given key in that map. If the key is not in that map, then the
5
+ * given `createCallback` is used to create a new value which is then stored in the given map and
6
+ * returned. Automatically handles an async `createCallback`.
7
+ *
8
+ * @category Object
9
+ * @category Package : @augment-vir/common
10
+ * @example
11
+ *
12
+ * ```ts
13
+ * // instead of doing this
14
+ * if (!myMap.get(myKey)) {
15
+ * myMap.set(myKey, {});
16
+ * }
17
+ * myMap.get(myKey)![nextKey] = 'some value';
18
+ *
19
+ * // do this
20
+ * getOrSetInObject(myMap, myKey, () => {
21
+ * return {};
22
+ * });
23
+ * ```
24
+ *
25
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
26
+ */
27
+ export function getOrSetFromMap(map, key, createCallback) {
28
+ const mapKey = key;
29
+ if (map.has(mapKey)) {
30
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
31
+ return map.get(mapKey);
32
+ }
33
+ else {
34
+ const createdValue = createCallback();
35
+ if (check.isPromise(createdValue)) {
36
+ return new Promise(async (resolve, reject) => {
37
+ try {
38
+ const awaitedValue = await createdValue;
39
+ map.set(mapKey, awaitedValue);
40
+ resolve(awaitedValue);
41
+ }
42
+ catch (error) {
43
+ reject(ensureError(error));
44
+ }
45
+ });
46
+ }
47
+ else {
48
+ map.set(mapKey, createdValue);
49
+ return createdValue;
50
+ }
51
+ }
52
+ }
53
+ /**
54
+ * Given an object, tries to get the given key in that object. If the key is not in that object,
55
+ * then the given `createCallback` is used to create a new value which is then stored in the given
56
+ * object and returned. Automatically handles an async `createCallback`.
57
+ *
58
+ * @category Object
59
+ * @category Package : @augment-vir/common
60
+ * @example
61
+ *
62
+ * ```ts
63
+ * // instead of doing this
64
+ * if (!myObject[myKey]) {
65
+ * myObject[myKey] = {};
66
+ * }
67
+ * myObject[myKey]![nextKey] = 'some value';
68
+ *
69
+ * // do this
70
+ * getOrSetInObject(myObject, myKey, () => {
71
+ * return {};
72
+ * });
73
+ * ```
74
+ *
75
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
76
+ */
77
+ export function getOrSet(originalObject, key, createCallback) {
78
+ if (key in originalObject) {
79
+ return originalObject[key];
80
+ }
81
+ else {
82
+ const createdValue = createCallback();
83
+ if (check.isPromise(createdValue)) {
84
+ return new Promise(async (resolve, reject) => {
85
+ try {
86
+ const awaitedValue = await createdValue;
87
+ originalObject[key] = awaitedValue;
88
+ resolve(awaitedValue);
89
+ }
90
+ catch (error) {
91
+ reject(ensureError(error));
92
+ }
93
+ });
94
+ }
95
+ else {
96
+ originalObject[key] = createdValue;
97
+ return createdValue;
98
+ }
99
+ }
100
+ }
@@ -0,0 +1,21 @@
1
+ import type { AnyObject } from '@augment-vir/core';
2
+ /**
3
+ * Counts the number of unique keys in an object type. Note that a key of just `string` will count
4
+ * as 1.
5
+ *
6
+ * @category Object
7
+ * @category Package : @augment-vir/common
8
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
9
+ */
10
+ export type KeyCount<T extends AnyObject> = UnionToTuple<keyof T>['length'];
11
+ /**
12
+ * This is not exported because its order is not stable but it's okay for our simple use case where
13
+ * we simply want to count the size of the union.
14
+ */
15
+ type UnionToTuple<T> = UnionToIntersection<T extends any ? (t: T) => T : never> extends (args: any) => infer W ? [...UnionToTuple<Exclude<T, W>>, W] : [];
16
+ /**
17
+ * This is the version of UnionToIntersection from type-fest v4.3.3. In version 4.4.0 type-fest
18
+ * changed this type helper and it broke how we're using it.
19
+ */
20
+ type UnionToIntersection<Union> = (Union extends unknown ? (distributedUnion: Union) => void : never) extends (mergedIntersection: infer Intersection) => void ? Intersection : never;
21
+ export {};
@@ -0,0 +1,13 @@
1
+ import { Values, type MaybePromise } from '@augment-vir/core';
2
+ export declare function mapObject<const OriginalObject, const NewKey extends PropertyKey, const NewValue>(inputObject: OriginalObject, mapCallback: (originalKey: keyof OriginalObject, originalValue: Values<OriginalObject>, originalObject: OriginalObject) => Promise<{
3
+ key: NewKey;
4
+ value: NewValue;
5
+ } | undefined>): Promise<Record<NewKey, NewValue>>;
6
+ export declare function mapObject<const OriginalObject, const NewKey extends PropertyKey, const NewValue>(inputObject: OriginalObject, mapCallback: (originalKey: keyof OriginalObject, originalValue: Values<OriginalObject>, originalObject: OriginalObject) => {
7
+ key: NewKey;
8
+ value: NewValue;
9
+ } | undefined): Record<NewKey, NewValue>;
10
+ export declare function mapObject<const OriginalObject, const NewKey extends PropertyKey, const NewValue>(inputObject: OriginalObject, mapCallback: (originalKey: keyof OriginalObject, originalValue: Values<OriginalObject>, originalObject: OriginalObject) => MaybePromise<{
11
+ key: NewKey;
12
+ value: NewValue;
13
+ } | undefined>): MaybePromise<Record<NewKey, NewValue>>;
@@ -0,0 +1,80 @@
1
+ import { check } from '@augment-vir/assert';
2
+ import { ensureError } from '@augment-vir/core';
3
+ import { filterMap } from '../array/filter.js';
4
+ import { getObjectTypedEntries, typedObjectFromEntries } from './object-entries.js';
5
+ /**
6
+ * Maps an object. The callback must return a key and value.
7
+ *
8
+ * @category Object
9
+ * @category Package : @augment-vir/common
10
+ * @example
11
+ *
12
+ * ```ts
13
+ * import {mapObject} from '@augment-vir/common';
14
+ *
15
+ * mapObject({a: 1, b: 2}, (key, value) => {
16
+ * return {
17
+ * key: `key-${key}`,
18
+ * value: `value-${value}`,
19
+ * };
20
+ * });
21
+ * // output is `{'key-a': 'value-1', 'key-b': 'value-2'}`
22
+ * ```
23
+ *
24
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
25
+ * @see
26
+ * - {@link mapObjectValues}: the variant that only maps values.
27
+ */
28
+ export function mapObject(originalObject, mapCallback) {
29
+ try {
30
+ let gotAPromise = false;
31
+ const mappedEntries = getObjectTypedEntries(originalObject)
32
+ .map(([originalKey, originalValue,]) => {
33
+ const output = mapCallback(originalKey, originalValue, originalObject);
34
+ if (output instanceof Promise) {
35
+ gotAPromise = true;
36
+ return output;
37
+ }
38
+ else if (output) {
39
+ return [
40
+ output.key,
41
+ output.value,
42
+ ];
43
+ }
44
+ else {
45
+ return undefined;
46
+ }
47
+ })
48
+ .filter(check.isTruthy);
49
+ if (gotAPromise) {
50
+ return new Promise(async (resolve, reject) => {
51
+ try {
52
+ const entries = filterMap(await Promise.all(mappedEntries), (entry) => {
53
+ if (!entry) {
54
+ return undefined;
55
+ }
56
+ else if (Array.isArray(entry)) {
57
+ return entry;
58
+ }
59
+ else {
60
+ return [
61
+ entry.key,
62
+ entry.value,
63
+ ];
64
+ }
65
+ }, check.isTruthy);
66
+ resolve(typedObjectFromEntries(entries));
67
+ }
68
+ catch (error) {
69
+ reject(ensureError(error));
70
+ }
71
+ });
72
+ }
73
+ else {
74
+ return typedObjectFromEntries(mappedEntries);
75
+ }
76
+ }
77
+ catch (error) {
78
+ throw ensureError(error);
79
+ }
80
+ }
@@ -0,0 +1,11 @@
1
+ import type { EnumBaseType, MaybePromise, Values } from '@augment-vir/core';
2
+ /**
3
+ * Creates an object that maps all values of an enum to the provided `Values` type.
4
+ *
5
+ * @category Object
6
+ * @category Package : @augment-vir/common
7
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
8
+ */
9
+ export type EnumMap<Enum extends EnumBaseType, Value> = Values<Enum> extends PropertyKey ? Record<Values<Enum>, Value> : 'ERROR: invalid enum';
10
+ export declare function mapEnumToObject<const Enum extends EnumBaseType, const Value>(enumInput: Enum, callback: (enumValue: Values<Enum>) => Promise<Value>): Promise<EnumMap<Enum, Value>>;
11
+ export declare function mapEnumToObject<const Enum extends EnumBaseType, const Value>(enumInput: Enum, callback: (enumValue: Values<Enum>, wholeEnum: Enum) => Value): Value extends Promise<any> ? Promise<any> extends Value ? Promise<EnumMap<Enum, Awaited<Value>>> : MaybePromise<EnumMap<Enum, Awaited<Value>>> : EnumMap<Enum, Value>;
@@ -0,0 +1,45 @@
1
+ import { mapObject } from './map-entries.js';
2
+ /**
3
+ * Maps all values of an enum as keys in an object where each value is the callback's output for
4
+ * that key.
5
+ *
6
+ * @category Object
7
+ * @category Package : @augment-vir/common
8
+ * @example
9
+ *
10
+ * ```ts
11
+ * import {mapEnumToObject} from '@augment-vir/common';
12
+ *
13
+ * enum MyEnum {
14
+ * A = 'a',
15
+ * B = 'b',
16
+ * }
17
+ *
18
+ * mapEnumToObject(MyEnum, (enumValue) => {
19
+ * return `value-${enumValue}`;
20
+ * });
21
+ * // output is `{[MyEnum.A]: 'value-a', [MyEnum.B]: 'value-b'}`
22
+ * ```
23
+ *
24
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
25
+ */
26
+ export function mapEnumToObject(enumInput, callback) {
27
+ return mapObject(enumInput, (enumKey, enumValue) => {
28
+ const key = enumValue;
29
+ const value = callback(enumValue, enumInput);
30
+ if (value instanceof Promise) {
31
+ return value.then((resolvedValue) => {
32
+ return {
33
+ key,
34
+ value: resolvedValue,
35
+ };
36
+ });
37
+ }
38
+ else {
39
+ return {
40
+ key,
41
+ value,
42
+ };
43
+ }
44
+ });
45
+ }
@@ -0,0 +1,35 @@
1
+ type InnerMappedValues<EntireInputGeneric extends object, MappedValueGeneric> = {
2
+ [MappedProp in keyof EntireInputGeneric]: MappedValueGeneric;
3
+ };
4
+ type MappedValues<EntireInputGeneric extends object, MappedValueGeneric> = MappedValueGeneric extends PromiseLike<unknown> ? Promise<InnerMappedValues<EntireInputGeneric, Awaited<MappedValueGeneric>>> : InnerMappedValues<EntireInputGeneric, Awaited<MappedValueGeneric>>;
5
+ /**
6
+ * Creates a new object with the same keys as the input object, but with values set to the result of
7
+ * `mapCallback` for each property. This is the same as {@link mapObjectValues} except that this
8
+ * preserves Promise values: it doesn't wrap them all in a single promise.
9
+ *
10
+ * @category Object
11
+ * @category Package : @augment-vir/common
12
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
13
+ */
14
+ export declare function mapObjectValuesSync<EntireInputGeneric extends object, MappedValueGeneric>(inputObject: EntireInputGeneric, mapCallback: (inputKey: keyof EntireInputGeneric, keyValue: Required<EntireInputGeneric>[typeof inputKey], fullObject: EntireInputGeneric) => MappedValueGeneric): InnerMappedValues<EntireInputGeneric, MappedValueGeneric>;
15
+ /**
16
+ * Creates a new object with the same keys as the input object, but with values set to the result of
17
+ * `mapCallback` for each property. Automatically handles an async `mapCallback`.
18
+ *
19
+ * @category Object
20
+ * @category Package : @augment-vir/common
21
+ * @example
22
+ *
23
+ * ```ts
24
+ * import {mapObjectValues} from '@augment-vir/common';
25
+ *
26
+ * mapObjectValues({a: 1, b: 2}, (key, value) => {
27
+ * return `key-${key} value-${value}`;
28
+ * });
29
+ * // output is `{a: 'key-a value-1', b: 'key-b value-2'}`
30
+ * ```
31
+ *
32
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
33
+ */
34
+ export declare function mapObjectValues<EntireInputGeneric extends object, MappedValueGeneric>(inputObject: EntireInputGeneric, mapCallback: (inputKey: keyof EntireInputGeneric, keyValue: Required<EntireInputGeneric>[typeof inputKey], fullObject: EntireInputGeneric) => MappedValueGeneric): MappedValues<EntireInputGeneric, MappedValueGeneric>;
35
+ export {};
@@ -0,0 +1,65 @@
1
+ import { ensureError, getObjectTypedKeys } from '@augment-vir/core';
2
+ /**
3
+ * Creates a new object with the same keys as the input object, but with values set to the result of
4
+ * `mapCallback` for each property. This is the same as {@link mapObjectValues} except that this
5
+ * preserves Promise values: it doesn't wrap them all in a single promise.
6
+ *
7
+ * @category Object
8
+ * @category Package : @augment-vir/common
9
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
10
+ */
11
+ export function mapObjectValuesSync(inputObject, mapCallback) {
12
+ const mappedObject = getObjectTypedKeys(inputObject).reduce((accum, currentKey) => {
13
+ const mappedValue = mapCallback(currentKey, inputObject[currentKey], inputObject);
14
+ accum[currentKey] = mappedValue;
15
+ return accum;
16
+ }, {});
17
+ return mappedObject;
18
+ }
19
+ /**
20
+ * Creates a new object with the same keys as the input object, but with values set to the result of
21
+ * `mapCallback` for each property. Automatically handles an async `mapCallback`.
22
+ *
23
+ * @category Object
24
+ * @category Package : @augment-vir/common
25
+ * @example
26
+ *
27
+ * ```ts
28
+ * import {mapObjectValues} from '@augment-vir/common';
29
+ *
30
+ * mapObjectValues({a: 1, b: 2}, (key, value) => {
31
+ * return `key-${key} value-${value}`;
32
+ * });
33
+ * // output is `{a: 'key-a value-1', b: 'key-b value-2'}`
34
+ * ```
35
+ *
36
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
37
+ */
38
+ export function mapObjectValues(inputObject, mapCallback) {
39
+ let gotAPromise = false;
40
+ const mappedObject = getObjectTypedKeys(inputObject).reduce((accum, currentKey) => {
41
+ const mappedValue = mapCallback(currentKey, inputObject[currentKey], inputObject);
42
+ if (mappedValue instanceof Promise) {
43
+ gotAPromise = true;
44
+ }
45
+ accum[currentKey] = mappedValue;
46
+ return accum;
47
+ }, {});
48
+ if (gotAPromise) {
49
+ return new Promise(async (resolve, reject) => {
50
+ try {
51
+ await Promise.all(getObjectTypedKeys(mappedObject).map(async (key) => {
52
+ const value = await mappedObject[key];
53
+ mappedObject[key] = value;
54
+ }));
55
+ resolve(mappedObject);
56
+ }
57
+ catch (error) {
58
+ reject(ensureError(error));
59
+ }
60
+ });
61
+ }
62
+ else {
63
+ return mappedObject;
64
+ }
65
+ }
@@ -4,6 +4,10 @@ import { PartialDeep } from 'type-fest';
4
4
  * undefined will be removed.
5
5
  *
6
6
  * Note that order matters! Each input object will overwrite the properties of the previous objects.
7
+ *
8
+ * @category Object : Merge
9
+ * @category Package : @augment-vir/common
10
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
7
11
  */
8
12
  export declare function mergeDeep<const T extends object>(...inputs: (Readonly<T> | Readonly<PartialDeep<T, {
9
13
  recurseIntoArrays: true;
@@ -1,13 +1,16 @@
1
- import { isRunTimeType } from 'run-time-assertions';
2
- import { isLengthAtLeast } from '../tuple';
1
+ import { check } from '@augment-vir/assert';
3
2
  /**
4
3
  * Accepts multiple objects and merges their key-value pairs recursively. Any values set to
5
4
  * undefined will be removed.
6
5
  *
7
6
  * Note that order matters! Each input object will overwrite the properties of the previous objects.
7
+ *
8
+ * @category Object : Merge
9
+ * @category Package : @augment-vir/common
10
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
8
11
  */
9
12
  export function mergeDeep(...inputs) {
10
- if (!isLengthAtLeast(inputs, 1)) {
13
+ if (!check.isLengthAtLeast(inputs, 1)) {
11
14
  // nothing to merge if no inputs
12
15
  return {};
13
16
  }
@@ -18,12 +21,12 @@ export function mergeDeep(...inputs) {
18
21
  let result = undefined;
19
22
  const mergeProps = {};
20
23
  inputs.forEach((individualInput) => {
21
- if (!isRunTimeType(individualInput, 'object')) {
24
+ if (!check.isObject(individualInput)) {
22
25
  /** If not an object, we can't merge. So overwrite instead. */
23
26
  result = individualInput;
24
27
  return;
25
28
  }
26
- else if (!isRunTimeType(result, 'object')) {
29
+ else if (!check.isObject(result)) {
27
30
  /** If result isn't an object then we need to make it into one. */
28
31
  result = { ...individualInput };
29
32
  }
@@ -34,7 +37,7 @@ export function mergeDeep(...inputs) {
34
37
  mergeProps[key].push(value);
35
38
  });
36
39
  });
37
- if (isRunTimeType(result, 'object')) {
40
+ if (check.isObject(result)) {
38
41
  Object.entries(mergeProps).forEach(([key, mergeValues,]) => {
39
42
  const newValue = mergeDeep(...mergeValues);
40
43
  if (newValue === undefined && key in result) {
@@ -0,0 +1,19 @@
1
+ import type { AnyObject, PartialWithNullable } from '@augment-vir/core';
2
+ /**
3
+ * Merge all objects together but ignore any override values that are `undefined` or `null` or
4
+ * missing. This only merges objects at the top level, it is not a deep merge.
5
+ *
6
+ * @category Object : Merge
7
+ * @category Package : @augment-vir/common
8
+ * @example
9
+ *
10
+ * ```ts
11
+ * import {mergeDefinedProperties} from '@augment-vir/common';
12
+ *
13
+ * mergeDefinedProperties({a: 'default', b: 'default'}, {a: 'override', b: undefined});
14
+ * // output is `{a: 'override', b: 'default'}`
15
+ * ```
16
+ *
17
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
18
+ */
19
+ export declare function mergeDefinedProperties<const T extends AnyObject>(original: T, ...overrides: ReadonlyArray<PartialWithNullable<NoInfer<T>> | undefined>): T;
@@ -0,0 +1,32 @@
1
+ import { getObjectTypedEntries } from './object-entries.js';
2
+ /**
3
+ * Merge all objects together but ignore any override values that are `undefined` or `null` or
4
+ * missing. This only merges objects at the top level, it is not a deep merge.
5
+ *
6
+ * @category Object : Merge
7
+ * @category Package : @augment-vir/common
8
+ * @example
9
+ *
10
+ * ```ts
11
+ * import {mergeDefinedProperties} from '@augment-vir/common';
12
+ *
13
+ * mergeDefinedProperties({a: 'default', b: 'default'}, {a: 'override', b: undefined});
14
+ * // output is `{a: 'override', b: 'default'}`
15
+ * ```
16
+ *
17
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
18
+ */
19
+ export function mergeDefinedProperties(original, ...overrides) {
20
+ const finalObject = { ...original };
21
+ overrides.forEach((entry) => {
22
+ if (!entry) {
23
+ return;
24
+ }
25
+ getObjectTypedEntries(entry).forEach(([key, value,]) => {
26
+ if (value != undefined) {
27
+ finalObject[key] = value;
28
+ }
29
+ });
30
+ });
31
+ return finalObject;
32
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Merges all arrays by their property in the given objects.
3
+ *
4
+ * @category Object : Merge
5
+ * @category Package : @augment-vir/common
6
+ * @example
7
+ *
8
+ * ```ts
9
+ * import {mergePropertyArrays} from '@augment-vir/common';
10
+ *
11
+ * mergePropertyArrays(
12
+ * {
13
+ * a: [
14
+ * 'a',
15
+ * 'b',
16
+ * ],
17
+ * },
18
+ * {
19
+ * a: [
20
+ * 'c',
21
+ * 'd',
22
+ * ],
23
+ * },
24
+ * ); // output is `{a: ['a', 'b', 'c', 'd']}`
25
+ * ```
26
+ *
27
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
28
+ */
29
+ export declare function mergePropertyArrays<T extends Record<PropertyKey, unknown[]>>(...inputs: ReadonlyArray<Readonly<T>>): T;
@@ -0,0 +1,39 @@
1
+ import { getOrSet } from './get-or-set.js';
2
+ /**
3
+ * Merges all arrays by their property in the given objects.
4
+ *
5
+ * @category Object : Merge
6
+ * @category Package : @augment-vir/common
7
+ * @example
8
+ *
9
+ * ```ts
10
+ * import {mergePropertyArrays} from '@augment-vir/common';
11
+ *
12
+ * mergePropertyArrays(
13
+ * {
14
+ * a: [
15
+ * 'a',
16
+ * 'b',
17
+ * ],
18
+ * },
19
+ * {
20
+ * a: [
21
+ * 'c',
22
+ * 'd',
23
+ * ],
24
+ * },
25
+ * ); // output is `{a: ['a', 'b', 'c', 'd']}`
26
+ * ```
27
+ *
28
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
29
+ */
30
+ export function mergePropertyArrays(...inputs) {
31
+ const combined = {};
32
+ inputs.forEach((input) => {
33
+ Object.entries(input).forEach(([key, newArray,]) => {
34
+ const currentArray = getOrSet(combined, key, () => []);
35
+ currentArray.push(...newArray);
36
+ });
37
+ });
38
+ return combined;
39
+ }
@@ -0,0 +1,31 @@
1
+ import { CompleteRequire } from '@augment-vir/core';
2
+ /**
3
+ * Gets an object's entries. This is the same as
4
+ * [`Object.entries`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
5
+ * except that it has better TypeScript types.
6
+ *
7
+ * @category Object
8
+ * @category Package : @augment-vir/common
9
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
10
+ */
11
+ export declare function getObjectTypedEntries<const ObjectGeneric>(input: ObjectGeneric): [keyof ObjectGeneric, CompleteRequire<ObjectGeneric>[keyof CompleteRequire<ObjectGeneric>]][];
12
+ /**
13
+ * Create an object from an array of entries. This is the same as
14
+ * [`Object.fromEntries`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
15
+ * except that it has better TypeScript types.
16
+ *
17
+ * @category Object
18
+ * @category Package : @augment-vir/common
19
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
20
+ */
21
+ export declare function typedObjectFromEntries<const KeyType extends PropertyKey, const ValueType>(entries: ReadonlyArray<Readonly<[KeyType, ValueType]>>): Record<KeyType, ValueType>;
22
+ /**
23
+ * Gets an object's entries and sorts them by their key values. This is the same as
24
+ * [`Object.entries`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
25
+ * except that it has better TypeScript types and sorts the entries.
26
+ *
27
+ * @category Object
28
+ * @category Package : @augment-vir/common
29
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
30
+ */
31
+ export declare function getEntriesSortedByKey<const ObjectGeneric>(input: ObjectGeneric): [keyof ObjectGeneric, CompleteRequire<ObjectGeneric>[keyof CompleteRequire<ObjectGeneric>]][];
@@ -0,0 +1,40 @@
1
+ import { getObjectTypedKeys } from '@augment-vir/core';
2
+ /**
3
+ * Gets an object's entries. This is the same as
4
+ * [`Object.entries`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
5
+ * except that it has better TypeScript types.
6
+ *
7
+ * @category Object
8
+ * @category Package : @augment-vir/common
9
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
10
+ */
11
+ export function getObjectTypedEntries(input) {
12
+ return getObjectTypedKeys(input).map((key) => [
13
+ key,
14
+ input[key],
15
+ ]);
16
+ }
17
+ /**
18
+ * Create an object from an array of entries. This is the same as
19
+ * [`Object.fromEntries`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
20
+ * except that it has better TypeScript types.
21
+ *
22
+ * @category Object
23
+ * @category Package : @augment-vir/common
24
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
25
+ */
26
+ export function typedObjectFromEntries(entries) {
27
+ return Object.fromEntries(entries);
28
+ }
29
+ /**
30
+ * Gets an object's entries and sorts them by their key values. This is the same as
31
+ * [`Object.entries`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
32
+ * except that it has better TypeScript types and sorts the entries.
33
+ *
34
+ * @category Object
35
+ * @category Package : @augment-vir/common
36
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
37
+ */
38
+ export function getEntriesSortedByKey(input) {
39
+ return getObjectTypedEntries(input).sort((tupleA, tupleB) => String(tupleA[0]).localeCompare(String(tupleB[0])));
40
+ }
@@ -0,0 +1,22 @@
1
+ import { type Values } from '@augment-vir/core';
2
+ /**
3
+ * Filters an object. Like
4
+ * [`[].filter`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
5
+ * but for objects.
6
+ *
7
+ * @category Object
8
+ * @category Package : @augment-vir/common
9
+ * @example
10
+ *
11
+ * ```ts
12
+ * import {filterObject} from '@augment-vir';
13
+ *
14
+ * filterObject({a: 1, b: 2, c: 3}, (key, value) => {
15
+ * return value >= 2;
16
+ * });
17
+ * // output is `{b: 2, c: 3}`
18
+ * ```
19
+ *
20
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
21
+ */
22
+ export declare function filterObject<ObjectGeneric>(inputObject: ObjectGeneric, callback: (key: keyof ObjectGeneric, value: Values<ObjectGeneric>, fullObject: ObjectGeneric) => boolean): Partial<ObjectGeneric>;