@pawells/typescript-common 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (311) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +148 -0
  3. package/build/array/array-chunk.d.ts +10 -0
  4. package/build/array/array-chunk.d.ts.map +1 -0
  5. package/build/array/array-chunk.js +19 -0
  6. package/build/array/array-chunk.js.map +1 -0
  7. package/build/array/array-compact.d.ts +18 -0
  8. package/build/array/array-compact.d.ts.map +1 -0
  9. package/build/array/array-compact.js +22 -0
  10. package/build/array/array-compact.js.map +1 -0
  11. package/build/array/array-contains.d.ts +9 -0
  12. package/build/array/array-contains.d.ts.map +1 -0
  13. package/build/array/array-contains.js +13 -0
  14. package/build/array/array-contains.js.map +1 -0
  15. package/build/array/array-count-by.d.ts +21 -0
  16. package/build/array/array-count-by.d.ts.map +1 -0
  17. package/build/array/array-count-by.js +29 -0
  18. package/build/array/array-count-by.js.map +1 -0
  19. package/build/array/array-difference.d.ts +25 -0
  20. package/build/array/array-difference.d.ts.map +1 -0
  21. package/build/array/array-difference.js +34 -0
  22. package/build/array/array-difference.js.map +1 -0
  23. package/build/array/array-element.d.ts +7 -0
  24. package/build/array/array-element.d.ts.map +1 -0
  25. package/build/array/array-element.js +2 -0
  26. package/build/array/array-element.js.map +1 -0
  27. package/build/array/array-filter.d.ts +37 -0
  28. package/build/array/array-filter.d.ts.map +1 -0
  29. package/build/array/array-filter.js +78 -0
  30. package/build/array/array-filter.js.map +1 -0
  31. package/build/array/array-flatten.d.ts +16 -0
  32. package/build/array/array-flatten.d.ts.map +1 -0
  33. package/build/array/array-flatten.js +20 -0
  34. package/build/array/array-flatten.js.map +1 -0
  35. package/build/array/array-group-by.d.ts +13 -0
  36. package/build/array/array-group-by.d.ts.map +1 -0
  37. package/build/array/array-group-by.js +24 -0
  38. package/build/array/array-group-by.js.map +1 -0
  39. package/build/array/array-intersection.d.ts +25 -0
  40. package/build/array/array-intersection.d.ts.map +1 -0
  41. package/build/array/array-intersection.js +39 -0
  42. package/build/array/array-intersection.js.map +1 -0
  43. package/build/array/array-partition.d.ts +19 -0
  44. package/build/array/array-partition.d.ts.map +1 -0
  45. package/build/array/array-partition.js +32 -0
  46. package/build/array/array-partition.js.map +1 -0
  47. package/build/array/array-range.d.ts +18 -0
  48. package/build/array/array-range.d.ts.map +1 -0
  49. package/build/array/array-range.js +30 -0
  50. package/build/array/array-range.js.map +1 -0
  51. package/build/array/array-sample.d.ts +29 -0
  52. package/build/array/array-sample.d.ts.map +1 -0
  53. package/build/array/array-sample.js +19 -0
  54. package/build/array/array-sample.js.map +1 -0
  55. package/build/array/array-shuffle.d.ts +8 -0
  56. package/build/array/array-shuffle.d.ts.map +1 -0
  57. package/build/array/array-shuffle.js +19 -0
  58. package/build/array/array-shuffle.js.map +1 -0
  59. package/build/array/array-sort-by.d.ts +20 -0
  60. package/build/array/array-sort-by.d.ts.map +1 -0
  61. package/build/array/array-sort-by.js +31 -0
  62. package/build/array/array-sort-by.js.map +1 -0
  63. package/build/array/array-zip.d.ts +22 -0
  64. package/build/array/array-zip.d.ts.map +1 -0
  65. package/build/array/array-zip.js +25 -0
  66. package/build/array/array-zip.js.map +1 -0
  67. package/build/array/array.test.d.ts +2 -0
  68. package/build/array/array.test.d.ts.map +1 -0
  69. package/build/array/array.test.js +347 -0
  70. package/build/array/array.test.js.map +1 -0
  71. package/build/array/index.d.ts +27 -0
  72. package/build/array/index.d.ts.map +1 -0
  73. package/build/array/index.js +25 -0
  74. package/build/array/index.js.map +1 -0
  75. package/build/array/types.d.ts +32 -0
  76. package/build/array/types.d.ts.map +1 -0
  77. package/build/array/types.js +2 -0
  78. package/build/array/types.js.map +1 -0
  79. package/build/array/unique.d.ts +8 -0
  80. package/build/array/unique.d.ts.map +1 -0
  81. package/build/array/unique.js +13 -0
  82. package/build/array/unique.js.map +1 -0
  83. package/build/enum/enum-entries.d.ts +11 -0
  84. package/build/enum/enum-entries.d.ts.map +1 -0
  85. package/build/enum/enum-entries.js +14 -0
  86. package/build/enum/enum-entries.js.map +1 -0
  87. package/build/enum/enum-key-by-value.d.ts +13 -0
  88. package/build/enum/enum-key-by-value.d.ts.map +1 -0
  89. package/build/enum/enum-key-by-value.js +21 -0
  90. package/build/enum/enum-key-by-value.js.map +1 -0
  91. package/build/enum/enum-keys.d.ts +10 -0
  92. package/build/enum/enum-keys.d.ts.map +1 -0
  93. package/build/enum/enum-keys.js +14 -0
  94. package/build/enum/enum-keys.js.map +1 -0
  95. package/build/enum/enum-safe-value.d.ts +14 -0
  96. package/build/enum/enum-safe-value.d.ts.map +1 -0
  97. package/build/enum/enum-safe-value.js +16 -0
  98. package/build/enum/enum-safe-value.js.map +1 -0
  99. package/build/enum/enum-values.d.ts +19 -0
  100. package/build/enum/enum-values.d.ts.map +1 -0
  101. package/build/enum/enum-values.js +25 -0
  102. package/build/enum/enum-values.js.map +1 -0
  103. package/build/enum/enum.test.d.ts +2 -0
  104. package/build/enum/enum.test.d.ts.map +1 -0
  105. package/build/enum/enum.test.js +122 -0
  106. package/build/enum/enum.test.js.map +1 -0
  107. package/build/enum/index.d.ts +17 -0
  108. package/build/enum/index.d.ts.map +1 -0
  109. package/build/enum/index.js +17 -0
  110. package/build/enum/index.js.map +1 -0
  111. package/build/enum/types.d.ts +9 -0
  112. package/build/enum/types.d.ts.map +1 -0
  113. package/build/enum/types.js +2 -0
  114. package/build/enum/types.js.map +1 -0
  115. package/build/enum/validate-enum-value.d.ts +13 -0
  116. package/build/enum/validate-enum-value.d.ts.map +1 -0
  117. package/build/enum/validate-enum-value.js +18 -0
  118. package/build/enum/validate-enum-value.js.map +1 -0
  119. package/build/function/compose.d.ts +37 -0
  120. package/build/function/compose.d.ts.map +1 -0
  121. package/build/function/compose.js +7 -0
  122. package/build/function/compose.js.map +1 -0
  123. package/build/function/debounce.d.ts +25 -0
  124. package/build/function/debounce.d.ts.map +1 -0
  125. package/build/function/debounce.js +37 -0
  126. package/build/function/debounce.js.map +1 -0
  127. package/build/function/function.test.d.ts +2 -0
  128. package/build/function/function.test.d.ts.map +1 -0
  129. package/build/function/function.test.js +158 -0
  130. package/build/function/function.test.js.map +1 -0
  131. package/build/function/index.d.ts +17 -0
  132. package/build/function/index.d.ts.map +1 -0
  133. package/build/function/index.js +16 -0
  134. package/build/function/index.js.map +1 -0
  135. package/build/function/memoize.d.ts +23 -0
  136. package/build/function/memoize.d.ts.map +1 -0
  137. package/build/function/memoize.js +34 -0
  138. package/build/function/memoize.js.map +1 -0
  139. package/build/function/once.d.ts +17 -0
  140. package/build/function/once.d.ts.map +1 -0
  141. package/build/function/once.js +27 -0
  142. package/build/function/once.js.map +1 -0
  143. package/build/function/sleep.d.ts +20 -0
  144. package/build/function/sleep.d.ts.map +1 -0
  145. package/build/function/sleep.js +22 -0
  146. package/build/function/sleep.js.map +1 -0
  147. package/build/function/throttle.d.ts +17 -0
  148. package/build/function/throttle.d.ts.map +1 -0
  149. package/build/function/throttle.js +37 -0
  150. package/build/function/throttle.js.map +1 -0
  151. package/build/function/types.d.ts +5 -0
  152. package/build/function/types.d.ts.map +1 -0
  153. package/build/function/types.js +2 -0
  154. package/build/function/types.js.map +1 -0
  155. package/build/index.d.ts +32 -0
  156. package/build/index.d.ts.map +1 -0
  157. package/build/index.js +51 -0
  158. package/build/index.js.map +1 -0
  159. package/build/object/assert-object.d.ts +8 -0
  160. package/build/object/assert-object.d.ts.map +1 -0
  161. package/build/object/assert-object.js +10 -0
  162. package/build/object/assert-object.js.map +1 -0
  163. package/build/object/clone.d.ts +39 -0
  164. package/build/object/clone.d.ts.map +1 -0
  165. package/build/object/clone.js +85 -0
  166. package/build/object/clone.js.map +1 -0
  167. package/build/object/equals.d.ts +44 -0
  168. package/build/object/equals.d.ts.map +1 -0
  169. package/build/object/equals.js +104 -0
  170. package/build/object/equals.js.map +1 -0
  171. package/build/object/filter-cached.d.ts +9 -0
  172. package/build/object/filter-cached.d.ts.map +1 -0
  173. package/build/object/filter-cached.js +108 -0
  174. package/build/object/filter-cached.js.map +1 -0
  175. package/build/object/filter.d.ts +85 -0
  176. package/build/object/filter.d.ts.map +1 -0
  177. package/build/object/filter.js +248 -0
  178. package/build/object/filter.js.map +1 -0
  179. package/build/object/has-circular-reference.d.ts +8 -0
  180. package/build/object/has-circular-reference.d.ts.map +1 -0
  181. package/build/object/has-circular-reference.js +40 -0
  182. package/build/object/has-circular-reference.js.map +1 -0
  183. package/build/object/hash.d.ts +20 -0
  184. package/build/object/hash.d.ts.map +1 -0
  185. package/build/object/hash.js +39 -0
  186. package/build/object/hash.js.map +1 -0
  187. package/build/object/index.d.ts +32 -0
  188. package/build/object/index.d.ts.map +1 -0
  189. package/build/object/index.js +30 -0
  190. package/build/object/index.js.map +1 -0
  191. package/build/object/key-value-pairs.d.ts +21 -0
  192. package/build/object/key-value-pairs.d.ts.map +1 -0
  193. package/build/object/key-value-pairs.js +28 -0
  194. package/build/object/key-value-pairs.js.map +1 -0
  195. package/build/object/map-cached.d.ts +9 -0
  196. package/build/object/map-cached.d.ts.map +1 -0
  197. package/build/object/map-cached.js +97 -0
  198. package/build/object/map-cached.js.map +1 -0
  199. package/build/object/map.d.ts +29 -0
  200. package/build/object/map.d.ts.map +1 -0
  201. package/build/object/map.js +40 -0
  202. package/build/object/map.js.map +1 -0
  203. package/build/object/merge.d.ts +14 -0
  204. package/build/object/merge.d.ts.map +1 -0
  205. package/build/object/merge.js +41 -0
  206. package/build/object/merge.js.map +1 -0
  207. package/build/object/object-diff.d.ts +40 -0
  208. package/build/object/object-diff.d.ts.map +1 -0
  209. package/build/object/object-diff.js +45 -0
  210. package/build/object/object-diff.js.map +1 -0
  211. package/build/object/object-flatten.d.ts +22 -0
  212. package/build/object/object-flatten.d.ts.map +1 -0
  213. package/build/object/object-flatten.js +38 -0
  214. package/build/object/object-flatten.js.map +1 -0
  215. package/build/object/object-invert.d.ts +20 -0
  216. package/build/object/object-invert.d.ts.map +1 -0
  217. package/build/object/object-invert.js +26 -0
  218. package/build/object/object-invert.js.map +1 -0
  219. package/build/object/object.test.d.ts +2 -0
  220. package/build/object/object.test.d.ts.map +1 -0
  221. package/build/object/object.test.js +432 -0
  222. package/build/object/object.test.js.map +1 -0
  223. package/build/object/omit.d.ts +8 -0
  224. package/build/object/omit.d.ts.map +1 -0
  225. package/build/object/omit.js +17 -0
  226. package/build/object/omit.js.map +1 -0
  227. package/build/object/pick.d.ts +50 -0
  228. package/build/object/pick.d.ts.map +1 -0
  229. package/build/object/pick.js +60 -0
  230. package/build/object/pick.js.map +1 -0
  231. package/build/object/property-paths.d.ts +115 -0
  232. package/build/object/property-paths.d.ts.map +1 -0
  233. package/build/object/property-paths.js +170 -0
  234. package/build/object/property-paths.js.map +1 -0
  235. package/build/object/security-utils.d.ts +59 -0
  236. package/build/object/security-utils.d.ts.map +1 -0
  237. package/build/object/security-utils.js +165 -0
  238. package/build/object/security-utils.js.map +1 -0
  239. package/build/object/sort-keys.d.ts +26 -0
  240. package/build/object/sort-keys.d.ts.map +1 -0
  241. package/build/object/sort-keys.js +52 -0
  242. package/build/object/sort-keys.js.map +1 -0
  243. package/build/object/types.d.ts +152 -0
  244. package/build/object/types.d.ts.map +1 -0
  245. package/build/object/types.js +6 -0
  246. package/build/object/types.js.map +1 -0
  247. package/build/string/case-conversion.d.ts +50 -0
  248. package/build/string/case-conversion.d.ts.map +1 -0
  249. package/build/string/case-conversion.js +94 -0
  250. package/build/string/case-conversion.js.map +1 -0
  251. package/build/string/formatting.d.ts +108 -0
  252. package/build/string/formatting.d.ts.map +1 -0
  253. package/build/string/formatting.js +171 -0
  254. package/build/string/formatting.js.map +1 -0
  255. package/build/string/index.d.ts +15 -0
  256. package/build/string/index.d.ts.map +1 -0
  257. package/build/string/index.js +14 -0
  258. package/build/string/index.js.map +1 -0
  259. package/build/string/string.test.d.ts +2 -0
  260. package/build/string/string.test.d.ts.map +1 -0
  261. package/build/string/string.test.js +321 -0
  262. package/build/string/string.test.js.map +1 -0
  263. package/build/string/transformation.d.ts +18 -0
  264. package/build/string/transformation.d.ts.map +1 -0
  265. package/build/string/transformation.js +32 -0
  266. package/build/string/transformation.js.map +1 -0
  267. package/build/string/types.d.ts +44 -0
  268. package/build/string/types.d.ts.map +1 -0
  269. package/build/string/types.js +2 -0
  270. package/build/string/types.js.map +1 -0
  271. package/build/string/validation.d.ts +18 -0
  272. package/build/string/validation.d.ts.map +1 -0
  273. package/build/string/validation.js +26 -0
  274. package/build/string/validation.js.map +1 -0
  275. package/build/time/elapsed-time/constants.d.ts +10 -0
  276. package/build/time/elapsed-time/constants.d.ts.map +1 -0
  277. package/build/time/elapsed-time/constants.js +96 -0
  278. package/build/time/elapsed-time/constants.js.map +1 -0
  279. package/build/time/elapsed-time/elapsed-time.d.ts +412 -0
  280. package/build/time/elapsed-time/elapsed-time.d.ts.map +1 -0
  281. package/build/time/elapsed-time/elapsed-time.js +652 -0
  282. package/build/time/elapsed-time/elapsed-time.js.map +1 -0
  283. package/build/time/elapsed-time/types.d.ts +150 -0
  284. package/build/time/elapsed-time/types.d.ts.map +1 -0
  285. package/build/time/elapsed-time/types.js +2 -0
  286. package/build/time/elapsed-time/types.js.map +1 -0
  287. package/build/time/elapsed-time/utils.d.ts +18 -0
  288. package/build/time/elapsed-time/utils.d.ts.map +1 -0
  289. package/build/time/elapsed-time/utils.js +24 -0
  290. package/build/time/elapsed-time/utils.js.map +1 -0
  291. package/build/time/index.d.ts +18 -0
  292. package/build/time/index.d.ts.map +1 -0
  293. package/build/time/index.js +17 -0
  294. package/build/time/index.js.map +1 -0
  295. package/build/time/stopwatch/entry-types.d.ts +13 -0
  296. package/build/time/stopwatch/entry-types.d.ts.map +1 -0
  297. package/build/time/stopwatch/entry-types.js +2 -0
  298. package/build/time/stopwatch/entry-types.js.map +1 -0
  299. package/build/time/stopwatch/entry.d.ts +80 -0
  300. package/build/time/stopwatch/entry.d.ts.map +1 -0
  301. package/build/time/stopwatch/entry.js +105 -0
  302. package/build/time/stopwatch/entry.js.map +1 -0
  303. package/build/time/stopwatch/stopwatch.d.ts +232 -0
  304. package/build/time/stopwatch/stopwatch.d.ts.map +1 -0
  305. package/build/time/stopwatch/stopwatch.js +315 -0
  306. package/build/time/stopwatch/stopwatch.js.map +1 -0
  307. package/build/time/time.test.d.ts +2 -0
  308. package/build/time/time.test.d.ts.map +1 -0
  309. package/build/time/time.test.js +211 -0
  310. package/build/time/time.test.js.map +1 -0
  311. package/package.json +63 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Phillip Aaron Wells
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.
package/README.md ADDED
@@ -0,0 +1,148 @@
1
+ # TypeScript Common Utilities
2
+
3
+ [![npm](https://img.shields.io/npm/v/@pawells/typescript-common)](https://www.npmjs.com/package/@pawells/typescript-common)
4
+ [![GitHub Release](https://img.shields.io/github/v/release/PhillipAWells/typescript-common)](https://github.com/PhillipAWells/typescript-common/releases)
5
+ [![CI](https://github.com/PhillipAWells/typescript-common/actions/workflows/ci.yml/badge.svg)](https://github.com/PhillipAWells/typescript-common/actions/workflows/ci.yml)
6
+ [![Node](https://img.shields.io/badge/node-%3E%3D24-brightgreen)](https://nodejs.org)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](./LICENSE)
8
+ [![GitHub Sponsors](https://img.shields.io/github/sponsors/PhillipAWells?style=social)](https://github.com/sponsors/PhillipAWells)
9
+
10
+ Shared TypeScript utility library. ESM-only, no runtime dependencies, targets ES2022.
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ npm install @pawells/typescript-common
16
+ # or
17
+ yarn add @pawells/typescript-common
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ All utilities are available as namespace imports or as individual named exports for tree-shaking.
23
+
24
+ ```typescript
25
+ // Namespace import
26
+ import { ArrayUtils, ObjectUtils, StringUtils, TimeUtils, EnumUtils, FunctionUtils } from '@pawells/typescript-common';
27
+
28
+ ArrayUtils.ArrayChunk([1, 2, 3, 4], 2); // [[1, 2], [3, 4]]
29
+
30
+ // Direct named import (tree-shakeable)
31
+ import { ArrayChunk, ObjectPick, CamelCase, Sleep } from '@pawells/typescript-common';
32
+ ```
33
+
34
+ ## API
35
+
36
+ ### Array utilities — `ArrayUtils`
37
+
38
+ | Export | Description |
39
+ |--------|-------------|
40
+ | `ArrayChunk(array, size)` | Split an array into chunks of a given size |
41
+ | `ArrayContains(array, predicate)` | Check if any element satisfies a predicate |
42
+ | `ArrayFilter(array, predicate)` | Type-safe array filter |
43
+ | `ArrayGroupBy(array, keyFn)` | Group array elements by a key function |
44
+ | `ArrayIntersection(a, b)` | Return elements present in both arrays |
45
+ | `ArrayShuffle(array)` | Return a shuffled copy of an array |
46
+ | `Unique(array)` | Remove duplicate values |
47
+ | `ArrayDifference(a, b)` | Elements in `a` not present in `b` |
48
+ | `ArrayFlatten(array, depth?)` | Flatten a nested array to a given depth |
49
+ | `ArrayCompact(array)` | Remove `null`/`undefined`, narrowing the type |
50
+ | `ArrayPartition(array, predicate)` | Split into `[matches, rest]` |
51
+ | `ArrayZip(...arrays)` | Zip multiple arrays into tuples |
52
+ | `ArrayRange(start, end, step?)` | Generate a numeric sequence |
53
+ | `ArraySortBy(array, keyFn, direction?)` | Immutable sort by a computed key |
54
+ | `ArrayCountBy(array, keyFn)` | Count elements per group key |
55
+ | `ArraySample(array, n?)` | Random element or `n` random elements |
56
+
57
+ ### Object utilities — `ObjectUtils`
58
+
59
+ | Export | Description |
60
+ |--------|-------------|
61
+ | `AssertObject(value)` | Assert a value is a non-null object |
62
+ | `ObjectClone(obj)` | Deep-clone an object |
63
+ | `ObjectEquals(a, b)` | Deep equality check |
64
+ | `ObjectFilter(obj, predicate)` | Filter object entries by predicate |
65
+ | `FilterObject(obj, keys)` | Keep only specified keys |
66
+ | `ObjectPick(obj, keys)` | Pick a subset of keys |
67
+ | `ObjectOmit(obj, keys)` | Omit specified keys |
68
+ | `ObjectMerge(target, ...sources)` | Deep merge objects |
69
+ | `MapObject(obj, fn)` | Map over object values |
70
+ | `TransformObject(obj, fn)` | Transform object entries |
71
+ | `ObjectHash(obj)` | Compute a stable hash of an object |
72
+ | `ObjectSortKeys(obj)` | Return object with keys sorted |
73
+ | `ObjectFromKeyValuePairs(pairs)` | Build an object from `[key, value]` pairs |
74
+ | `ObjectToKeyValuePairs(obj)` | Convert an object to `[key, value]` pairs |
75
+ | `ObjectGetPropertyByPath(obj, path)` | Get a nested property by dot-path |
76
+ | `ObjectSetPropertyByPath(obj, path, value)` | Set a nested property by dot-path |
77
+ | `ObjectInvert(obj)` | Swap keys and values |
78
+ | `ObjectFlatten(obj, separator?)` | Flatten nested object to dot-separated keys |
79
+ | `ObjectDiff(objA, objB)` | Compute added/removed/changed keys between two objects |
80
+
81
+ ### String utilities — `StringUtils`
82
+
83
+ | Export | Description |
84
+ |--------|-------------|
85
+ | `CamelCase(str)` | Convert a string to camelCase |
86
+ | `PASCAL_CASE(str)` | Convert a string to PascalCase |
87
+ | `KEBAB_CASE(str)` | Convert a string to kebab-case |
88
+ | `SNAKE_CASE(str)` | Convert a string to snake_case |
89
+ | `SCREAMING_SNAKE_CASE(str)` | Convert a string to SCREAMING_SNAKE_CASE |
90
+ | `FormatString(template, values)` | Simple string template formatting |
91
+ | `EscapeHTML(str)` | Escape HTML special characters |
92
+ | `StripHTML(str)` | Remove all HTML tags from a string |
93
+ | `Pluralize(word, count, plural?)` | Return singular or plural form based on count |
94
+ | `WordCount(str)` | Count the number of words in a string |
95
+ | `CountOccurrences(str, substr)` | Count non-overlapping occurrences of a substring |
96
+
97
+ ### Time utilities — `TimeUtils`
98
+
99
+ | Export | Description |
100
+ |--------|-------------|
101
+ | `ElapsedTime` | Measure elapsed time with human-readable output |
102
+ | `Stopwatch` | Lap-based stopwatch for benchmarking |
103
+
104
+ ### Enum utilities — `EnumUtils`
105
+
106
+ | Export | Description |
107
+ |--------|-------------|
108
+ | `EnumKeys(enumObj)` | Get keys of a TypeScript enum |
109
+ | `EnumValues(enumObj)` | Get values of a TypeScript enum |
110
+ | `EnumEntries(enumObj)` | Get key-value pairs of a TypeScript enum |
111
+ | `ValidateEnumValue(enumObj, value)` | Check if a value is a valid enum member |
112
+ | `EnumKeyByValue(enumObj, value)` | Look up an enum key by its value |
113
+ | `EnumSafeValue(enumObj, value)` | Return the value if valid, or `undefined` |
114
+
115
+ ### Function utilities — `FunctionUtils`
116
+
117
+ | Export | Description |
118
+ |--------|-------------|
119
+ | `Debounce(fn, ms)` | Delay execution until `ms` ms after the last call |
120
+ | `Throttle(fn, ms)` | Limit execution to at most once per `ms` ms |
121
+ | `Memoize(fn, keyFn?)` | Cache results by serialised arguments |
122
+ | `Once(fn)` | Execute a function at most once, caching the result |
123
+ | `Pipe(...fns)` | Compose functions left-to-right |
124
+ | `Compose(...fns)` | Compose functions right-to-left |
125
+ | `Sleep(ms)` | Return a `Promise` that resolves after `ms` ms |
126
+
127
+ ## Development
128
+
129
+ ```bash
130
+ yarn install # Install dependencies
131
+ yarn build # Compile TypeScript → ./build/
132
+ yarn dev # Build + run
133
+ yarn watch # Watch mode
134
+ yarn typecheck # Type check without building
135
+ yarn lint # ESLint
136
+ yarn lint:fix # ESLint with auto-fix
137
+ yarn test # Run tests
138
+ yarn test:ui # Interactive Vitest UI
139
+ yarn test:coverage # Tests with coverage report
140
+ ```
141
+
142
+ ## Requirements
143
+
144
+ - Node.js >= 24.0.0
145
+
146
+ ## License
147
+
148
+ MIT — See [LICENSE](./LICENSE) for details.
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Chunks an array into smaller arrays of a specified size.
3
+ * @param array The array to split.
4
+ * @param size Size of each chunk.
5
+ * @returns Array of arrays, each of the specified size.
6
+ * @example
7
+ * const chunks = ArrayChunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]
8
+ */
9
+ export declare function ArrayChunk<T>(array: T[], size: number): T[][];
10
+ //# sourceMappingURL=array-chunk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array-chunk.d.ts","sourceRoot":"","sources":["../../src/array/array-chunk.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,EAAE,EAAE,CAY7D"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Chunks an array into smaller arrays of a specified size.
3
+ * @param array The array to split.
4
+ * @param size Size of each chunk.
5
+ * @returns Array of arrays, each of the specified size.
6
+ * @example
7
+ * const chunks = ArrayChunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]
8
+ */
9
+ export function ArrayChunk(array, size) {
10
+ if (!array || size <= 0) {
11
+ return [];
12
+ }
13
+ const result = [];
14
+ for (let i = 0; i < array.length; i += size) {
15
+ result.push(array.slice(i, i + size));
16
+ }
17
+ return result;
18
+ }
19
+ //# sourceMappingURL=array-chunk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array-chunk.js","sourceRoot":"","sources":["../../src/array/array-chunk.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAI,KAAU,EAAE,IAAY;IACrD,IAAI,CAAC,KAAK,IAAI,IAAI,IAAI,CAAC,EAAE,CAAC;QACzB,OAAO,EAAE,CAAC;IACX,CAAC;IAED,MAAM,MAAM,GAAU,EAAE,CAAC;IAEzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC;QAC7C,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;IACvC,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Removes `null` and `undefined` values from an array, narrowing the element type.
3
+ *
4
+ * @template T - The non-nullish element type
5
+ * @param array - The array to compact
6
+ * @returns A new array with `null`/`undefined` entries removed
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * ArrayCompact([1, null, 2, undefined, 3]); // [1, 2, 3]
11
+ * // Return type is narrowed: number[]
12
+ *
13
+ * const names: (string | null)[] = ['Alice', null, 'Bob'];
14
+ * const clean: string[] = ArrayCompact(names);
15
+ * ```
16
+ */
17
+ export declare function ArrayCompact<T>(array: (T | null | undefined)[]): T[];
18
+ //# sourceMappingURL=array-compact.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array-compact.d.ts","sourceRoot":"","sources":["../../src/array/array-compact.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,GAAG,CAAC,EAAE,CAGpE"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Removes `null` and `undefined` values from an array, narrowing the element type.
3
+ *
4
+ * @template T - The non-nullish element type
5
+ * @param array - The array to compact
6
+ * @returns A new array with `null`/`undefined` entries removed
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * ArrayCompact([1, null, 2, undefined, 3]); // [1, 2, 3]
11
+ * // Return type is narrowed: number[]
12
+ *
13
+ * const names: (string | null)[] = ['Alice', null, 'Bob'];
14
+ * const clean: string[] = ArrayCompact(names);
15
+ * ```
16
+ */
17
+ export function ArrayCompact(array) {
18
+ if (!array)
19
+ return [];
20
+ return array.filter((item) => item !== null && item !== undefined);
21
+ }
22
+ //# sourceMappingURL=array-compact.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array-compact.js","sourceRoot":"","sources":["../../src/array/array-compact.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,YAAY,CAAI,KAA+B;IAC9D,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IACtB,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAa,EAAE,CAAC,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,CAAC,CAAC;AAC/E,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { TPredicate } from './types';
2
+ /**
3
+ * Checks if an array contains at least one element that passes a predicate test.
4
+ * @param array The array to check.
5
+ * @param predicate TPredicate function to test each element.
6
+ * @returns True if at least one element passes the test, false otherwise.
7
+ */
8
+ export declare function ArrayContains<T>(array: T[], predicate: TPredicate<T>): boolean;
9
+ //# sourceMappingURL=array-contains.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array-contains.d.ts","sourceRoot":"","sources":["../../src/array/array-contains.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,OAAO,CAM9E"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Checks if an array contains at least one element that passes a predicate test.
3
+ * @param array The array to check.
4
+ * @param predicate TPredicate function to test each element.
5
+ * @returns True if at least one element passes the test, false otherwise.
6
+ */
7
+ export function ArrayContains(array, predicate) {
8
+ if (!array || array.length === 0) {
9
+ return false;
10
+ }
11
+ return array.some(predicate);
12
+ }
13
+ //# sourceMappingURL=array-contains.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array-contains.js","sourceRoot":"","sources":["../../src/array/array-contains.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAI,KAAU,EAAE,SAAwB;IACpE,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClC,OAAO,KAAK,CAAC;IACd,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,21 @@
1
+ import type { TTransform } from './types';
2
+ /**
3
+ * Counts how many elements fall into each group defined by `keyFn`.
4
+ *
5
+ * @template T - The type of array elements
6
+ * @template K - The key type (string, number, or symbol)
7
+ * @param array - The array to count
8
+ * @param keyFn - Function that assigns each element to a group key
9
+ * @returns A record where keys are group identifiers and values are occurrence counts
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * ArrayCountBy(['one', 'two', 'three'], (s) => s.length);
14
+ * // { 3: 2, 5: 1 }
15
+ *
16
+ * ArrayCountBy(users, (u) => u.role);
17
+ * // { admin: 3, member: 12, guest: 1 }
18
+ * ```
19
+ */
20
+ export declare function ArrayCountBy<T, K extends string | number | symbol>(array: T[], keyFn: TTransform<T, K>): Record<K, number>;
21
+ //# sourceMappingURL=array-count-by.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array-count-by.d.ts","sourceRoot":"","sources":["../../src/array/array-count-by.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EACjE,KAAK,EAAE,CAAC,EAAE,EACV,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,GACrB,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAWnB"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Counts how many elements fall into each group defined by `keyFn`.
3
+ *
4
+ * @template T - The type of array elements
5
+ * @template K - The key type (string, number, or symbol)
6
+ * @param array - The array to count
7
+ * @param keyFn - Function that assigns each element to a group key
8
+ * @returns A record where keys are group identifiers and values are occurrence counts
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * ArrayCountBy(['one', 'two', 'three'], (s) => s.length);
13
+ * // { 3: 2, 5: 1 }
14
+ *
15
+ * ArrayCountBy(users, (u) => u.role);
16
+ * // { admin: 3, member: 12, guest: 1 }
17
+ * ```
18
+ */
19
+ export function ArrayCountBy(array, keyFn) {
20
+ if (!array)
21
+ return {};
22
+ const result = {};
23
+ for (const item of array) {
24
+ const key = keyFn(item);
25
+ result[key] = (result[key] ?? 0) + 1;
26
+ }
27
+ return result;
28
+ }
29
+ //# sourceMappingURL=array-count-by.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array-count-by.js","sourceRoot":"","sources":["../../src/array/array-count-by.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,YAAY,CAC3B,KAAU,EACV,KAAuB;IAEvB,IAAI,CAAC,KAAK;QAAE,OAAO,EAAuB,CAAC;IAE3C,MAAM,MAAM,GAAG,EAAuB,CAAC;IAEvC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC1B,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;QACxB,MAAM,CAAC,GAAG,CAAC,GAAG,CAAE,MAAM,CAAC,GAAG,CAAwB,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IAC9D,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC"}
@@ -0,0 +1,25 @@
1
+ import type { TEqualityComparator } from './types';
2
+ /**
3
+ * Returns elements present in the first array but not in the second (set difference).
4
+ * Optimised O(n+m) using a Set when no custom comparator is provided.
5
+ *
6
+ * @template T - The type of array elements
7
+ * @param array1 - The source array
8
+ * @param array2 - Elements to exclude
9
+ * @param comparator - Optional custom equality comparator
10
+ * @returns Array of elements in `array1` that are not in `array2`
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * ArrayDifference([1, 2, 3, 4], [2, 4]); // [1, 3]
15
+ * ArrayDifference(
16
+ * [{ id: 1 }, { id: 2 }],
17
+ * [{ id: 2 }],
18
+ * (a, b) => a.id === b.id,
19
+ * ); // [{ id: 1 }]
20
+ * ```
21
+ *
22
+ * @complexity O(n+m) for primitive values, O(n*m) when a comparator is provided
23
+ */
24
+ export declare function ArrayDifference<T>(array1: T[], array2: T[], comparator?: TEqualityComparator<T>): T[];
25
+ //# sourceMappingURL=array-difference.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array-difference.d.ts","sourceRoot":"","sources":["../../src/array/array-difference.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAChC,MAAM,EAAE,CAAC,EAAE,EACX,MAAM,EAAE,CAAC,EAAE,EACX,UAAU,CAAC,EAAE,mBAAmB,CAAC,CAAC,CAAC,GACjC,CAAC,EAAE,CAUL"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Returns elements present in the first array but not in the second (set difference).
3
+ * Optimised O(n+m) using a Set when no custom comparator is provided.
4
+ *
5
+ * @template T - The type of array elements
6
+ * @param array1 - The source array
7
+ * @param array2 - Elements to exclude
8
+ * @param comparator - Optional custom equality comparator
9
+ * @returns Array of elements in `array1` that are not in `array2`
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * ArrayDifference([1, 2, 3, 4], [2, 4]); // [1, 3]
14
+ * ArrayDifference(
15
+ * [{ id: 1 }, { id: 2 }],
16
+ * [{ id: 2 }],
17
+ * (a, b) => a.id === b.id,
18
+ * ); // [{ id: 1 }]
19
+ * ```
20
+ *
21
+ * @complexity O(n+m) for primitive values, O(n*m) when a comparator is provided
22
+ */
23
+ export function ArrayDifference(array1, array2, comparator) {
24
+ if (!array1)
25
+ return [];
26
+ if (!array2 || array2.length === 0)
27
+ return [...array1];
28
+ if (comparator) {
29
+ return array1.filter((item) => !array2.some((other) => comparator(item, other)));
30
+ }
31
+ const set2 = new Set(array2);
32
+ return array1.filter((item) => !set2.has(item));
33
+ }
34
+ //# sourceMappingURL=array-difference.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array-difference.js","sourceRoot":"","sources":["../../src/array/array-difference.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,eAAe,CAC9B,MAAW,EACX,MAAW,EACX,UAAmC;IAEnC,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;IACvB,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,CAAC,GAAG,MAAM,CAAC,CAAC;IAEvD,IAAI,UAAU,EAAE,CAAC;QAChB,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IAClF,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;IAC7B,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;AACjD,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Extracts the element type from an array type.
3
+ * @example
4
+ * type T = TArrayElement<string[]>; // T is string
5
+ */
6
+ export type TArrayElement<A> = A extends readonly (infer T)[] ? T : never;
7
+ //# sourceMappingURL=array-element.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array-element.d.ts","sourceRoot":"","sources":["../../src/array/array-element.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,KAAK,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=array-element.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array-element.js","sourceRoot":"","sources":["../../src/array/array-element.ts"],"names":[],"mappings":""}
@@ -0,0 +1,37 @@
1
+ import type { TPredicate } from './types';
2
+ /**
3
+ * Filters an array based on criteria that can be an object filter or a predicate function.
4
+ * Supports nested property filtering with dot notation and array property filtering.
5
+ *
6
+ * @param array - The array to filter
7
+ * @param criteria - Either an object with filter criteria or a predicate function
8
+ * @returns A new array containing only items that match the criteria
9
+ *
10
+ * @example
11
+ * // Simple property filtering
12
+ * const users = [{ name: 'John', age: 25 }, { name: 'Jane', age: 30 }];
13
+ * ArrayFilter(users, { age: 30 }); // [{ name: 'Jane', age: 30 }]
14
+ *
15
+ * @example
16
+ * // Nested property filtering
17
+ * const profiles = [
18
+ * { user: { name: 'John', active: true } },
19
+ * { user: { name: 'Jane', active: false } }
20
+ * ];
21
+ * ArrayFilter(profiles, { 'user.name': 'John' }); // [{ user: { name: 'John', active: true } }]
22
+ *
23
+ * @example
24
+ * // Array property filtering
25
+ * const posts = [
26
+ * { tags: ['js', 'web'] },
27
+ * { tags: ['ts', 'node'] }
28
+ * ];
29
+ * ArrayFilter(posts, { tags: 'js' }); // [{ tags: ['js', 'web'] }]
30
+ *
31
+ * @example
32
+ * // Predicate function filtering
33
+ * const numbers = [1, 2, 3, 4, 5];
34
+ * ArrayFilter(numbers, (n) => n > 3); // [4, 5]
35
+ */
36
+ export declare function ArrayFilter<T>(array: T[], criteria: Partial<Record<string, unknown>> | TPredicate<T>): T[];
37
+ //# sourceMappingURL=array-filter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array-filter.d.ts","sourceRoot":"","sources":["../../src/array/array-filter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAoC1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC5B,KAAK,EAAE,CAAC,EAAE,EACV,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,GACxD,CAAC,EAAE,CAaL"}
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Gets nested property value from an object using dot notation
3
+ * @param obj - The object to get value from
4
+ * @param path - The property path (e.g., 'user.name')
5
+ * @returns The value at the path, or undefined
6
+ */
7
+ function getNestedValue(obj, path) {
8
+ const keys = path.split('.');
9
+ let current = obj;
10
+ for (const key of keys) {
11
+ if (current === null || current === undefined)
12
+ return undefined;
13
+ current = current[key];
14
+ }
15
+ return current;
16
+ }
17
+ /**
18
+ * Checks if a value matches the filter criteria
19
+ * @param value - The value to check
20
+ * @param filterValue - The filter criteria
21
+ * @returns true if matches, false otherwise
22
+ */
23
+ function matchesValue(value, filterValue) {
24
+ // If value is an array, check if it contains the filter value
25
+ if (Array.isArray(value)) {
26
+ return value.includes(filterValue);
27
+ }
28
+ // Direct equality check
29
+ return value === filterValue;
30
+ }
31
+ /**
32
+ * Filters an array based on criteria that can be an object filter or a predicate function.
33
+ * Supports nested property filtering with dot notation and array property filtering.
34
+ *
35
+ * @param array - The array to filter
36
+ * @param criteria - Either an object with filter criteria or a predicate function
37
+ * @returns A new array containing only items that match the criteria
38
+ *
39
+ * @example
40
+ * // Simple property filtering
41
+ * const users = [{ name: 'John', age: 25 }, { name: 'Jane', age: 30 }];
42
+ * ArrayFilter(users, { age: 30 }); // [{ name: 'Jane', age: 30 }]
43
+ *
44
+ * @example
45
+ * // Nested property filtering
46
+ * const profiles = [
47
+ * { user: { name: 'John', active: true } },
48
+ * { user: { name: 'Jane', active: false } }
49
+ * ];
50
+ * ArrayFilter(profiles, { 'user.name': 'John' }); // [{ user: { name: 'John', active: true } }]
51
+ *
52
+ * @example
53
+ * // Array property filtering
54
+ * const posts = [
55
+ * { tags: ['js', 'web'] },
56
+ * { tags: ['ts', 'node'] }
57
+ * ];
58
+ * ArrayFilter(posts, { tags: 'js' }); // [{ tags: ['js', 'web'] }]
59
+ *
60
+ * @example
61
+ * // Predicate function filtering
62
+ * const numbers = [1, 2, 3, 4, 5];
63
+ * ArrayFilter(numbers, (n) => n > 3); // [4, 5]
64
+ */
65
+ export function ArrayFilter(array, criteria) {
66
+ // If criteria is a function, use it as predicate
67
+ if (typeof criteria === 'function') {
68
+ return array.filter(criteria);
69
+ }
70
+ // Object-based filtering with nested support
71
+ return array.filter((item) => {
72
+ return Object.entries(criteria).every(([key, filterValue]) => {
73
+ const itemValue = getNestedValue(item, key);
74
+ return matchesValue(itemValue, filterValue);
75
+ });
76
+ });
77
+ }
78
+ //# sourceMappingURL=array-filter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array-filter.js","sourceRoot":"","sources":["../../src/array/array-filter.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,SAAS,cAAc,CAAC,GAAY,EAAE,IAAY;IACjD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7B,IAAI,OAAO,GAAQ,GAAG,CAAC;IAEvB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACxB,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,SAAS;YAAE,OAAO,SAAS,CAAC;QAChE,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IAED,OAAO,OAAO,CAAC;AAChB,CAAC;AAED;;;;;GAKG;AACH,SAAS,YAAY,CAAC,KAAc,EAAE,WAAoB;IACzD,8DAA8D;IAC9D,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IACpC,CAAC;IAED,wBAAwB;IACxB,OAAO,KAAK,KAAK,WAAW,CAAC;AAC9B,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,UAAU,WAAW,CAC1B,KAAU,EACV,QAA0D;IAE1D,iDAAiD;IACjD,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;QACpC,OAAO,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC/B,CAAC;IAED,6CAA6C;IAC7C,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;QAC5B,OAAO,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE,WAAW,CAAC,EAAE,EAAE;YAC5D,MAAM,SAAS,GAAG,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;YAC5C,OAAO,YAAY,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Flattens a nested array to a specified depth (default: all levels).
3
+ *
4
+ * @template T - The leaf element type
5
+ * @param array - The nested array to flatten
6
+ * @param depth - How many levels deep to flatten (default: `Infinity`)
7
+ * @returns Flattened array of `T`
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * ArrayFlatten([1, [2, [3, [4]]]]); // [1, 2, 3, 4]
12
+ * ArrayFlatten([1, [2, [3]]], 1); // [1, 2, [3]]
13
+ * ```
14
+ */
15
+ export declare function ArrayFlatten<T = unknown>(array: any[], depth?: number): T[];
16
+ //# sourceMappingURL=array-flatten.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array-flatten.d.ts","sourceRoot":"","sources":["../../src/array/array-flatten.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAAC,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,CAG3E"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Flattens a nested array to a specified depth (default: all levels).
3
+ *
4
+ * @template T - The leaf element type
5
+ * @param array - The nested array to flatten
6
+ * @param depth - How many levels deep to flatten (default: `Infinity`)
7
+ * @returns Flattened array of `T`
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * ArrayFlatten([1, [2, [3, [4]]]]); // [1, 2, 3, 4]
12
+ * ArrayFlatten([1, [2, [3]]], 1); // [1, 2, [3]]
13
+ * ```
14
+ */
15
+ export function ArrayFlatten(array, depth) {
16
+ if (!array)
17
+ return [];
18
+ return array.flat(depth ?? Infinity);
19
+ }
20
+ //# sourceMappingURL=array-flatten.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array-flatten.js","sourceRoot":"","sources":["../../src/array/array-flatten.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,YAAY,CAAc,KAAY,EAAE,KAAc;IACrE,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IACtB,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,QAAQ,CAAQ,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { TTransform } from './types';
2
+ /**
3
+ * Groups array elements by a key generated by a provided function.
4
+ * @param array The array to group.
5
+ * @param keyFn TTransform function that returns the grouping key for each element.
6
+ * @returns An object with keys as group names and values as arrays of grouped elements.
7
+ * @example
8
+ * const items = [{ category: 'fruit', name: 'apple' }, { category: 'vegetable', name: 'carrot' }];
9
+ * const grouped = ArrayGroupBy(items, item => item.category);
10
+ * // grouped.fruit is [{ category: 'fruit', name: 'apple' }]
11
+ */
12
+ export declare function ArrayGroupBy<T, K extends string | number | symbol>(array: T[], keyFn: TTransform<T, K>): Record<K, T[]>;
13
+ //# sourceMappingURL=array-group-by.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array-group-by.d.ts","sourceRoot":"","sources":["../../src/array/array-group-by.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAavH"}