@mongez/reinforcements 2.3.1 → 2.3.2

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 (295) hide show
  1. package/README.md +2 -0
  2. package/cjs/Random/random.d.ts +35 -35
  3. package/cjs/Random/random.js +65 -67
  4. package/cjs/Random/random.test.d.ts +2 -0
  5. package/cjs/array/average.d.ts +6 -6
  6. package/cjs/array/average.js +12 -15
  7. package/cjs/array/average.test.d.ts +2 -0
  8. package/cjs/array/chunk.d.ts +4 -4
  9. package/cjs/array/chunk.js +13 -15
  10. package/cjs/array/chunk.test.d.ts +2 -0
  11. package/cjs/array/count.d.ts +4 -4
  12. package/cjs/array/count.js +14 -17
  13. package/cjs/array/count.test.d.ts +2 -0
  14. package/cjs/array/countBy.d.ts +6 -6
  15. package/cjs/array/countBy.js +20 -23
  16. package/cjs/array/countBy.test.d.ts +2 -0
  17. package/cjs/array/even.d.ts +6 -6
  18. package/cjs/array/even.js +15 -18
  19. package/cjs/array/even.test.d.ts +2 -0
  20. package/cjs/array/evenIndexes.d.ts +4 -4
  21. package/cjs/array/evenIndexes.js +9 -11
  22. package/cjs/array/evenIndexes.test.d.ts +2 -0
  23. package/cjs/array/groupBy.d.ts +7 -7
  24. package/cjs/array/groupBy.js +45 -48
  25. package/cjs/array/groupBy.test.d.ts +2 -0
  26. package/cjs/array/max.d.ts +6 -6
  27. package/cjs/array/max.js +20 -23
  28. package/cjs/array/max.test.d.ts +2 -0
  29. package/cjs/array/median.d.ts +6 -6
  30. package/cjs/array/median.js +25 -28
  31. package/cjs/array/median.test.d.ts +2 -0
  32. package/cjs/array/min.d.ts +6 -6
  33. package/cjs/array/min.js +20 -23
  34. package/cjs/array/min.test.d.ts +2 -0
  35. package/cjs/array/odd.d.ts +6 -6
  36. package/cjs/array/odd.js +15 -18
  37. package/cjs/array/odd.test.d.ts +2 -0
  38. package/cjs/array/oddIndexes.d.ts +4 -4
  39. package/cjs/array/oddIndexes.js +9 -11
  40. package/cjs/array/oddIndexes.test.d.ts +2 -0
  41. package/cjs/array/pluck.d.ts +8 -8
  42. package/cjs/array/pluck.js +23 -26
  43. package/cjs/array/pluck.test.d.ts +2 -0
  44. package/cjs/array/pushUnique.d.ts +5 -5
  45. package/cjs/array/pushUnique.js +14 -16
  46. package/cjs/array/pushUnique.test.d.ts +2 -0
  47. package/cjs/array/range.d.ts +4 -4
  48. package/cjs/array/range.js +21 -23
  49. package/cjs/array/range.test.d.ts +2 -0
  50. package/cjs/array/sum.d.ts +6 -6
  51. package/cjs/array/sum.js +28 -31
  52. package/cjs/array/sum.test.d.ts +2 -0
  53. package/cjs/array/unique.d.ts +4 -4
  54. package/cjs/array/unique.js +14 -17
  55. package/cjs/array/unique.test.d.ts +2 -0
  56. package/cjs/array/unshiftUnique.d.ts +5 -5
  57. package/cjs/array/unshiftUnique.js +14 -16
  58. package/cjs/array/unshiftUnique.test.d.ts +2 -0
  59. package/cjs/index.d.ts +56 -56
  60. package/cjs/index.js +56 -59
  61. package/cjs/mixed/areEqual/areEqual.d.ts +4 -4
  62. package/cjs/mixed/areEqual/areEqual.js +23 -25
  63. package/cjs/mixed/areEqual/areEqual.test.d.ts +2 -0
  64. package/cjs/mixed/clone/clone.d.ts +4 -4
  65. package/cjs/mixed/clone/clone.js +12 -18
  66. package/cjs/mixed/clone/clone.test.d.ts +2 -0
  67. package/cjs/mixed/shuffle/shuffle.d.ts +4 -4
  68. package/cjs/mixed/shuffle/shuffle.js +14 -16
  69. package/cjs/mixed/shuffle/shuffle.test.d.ts +2 -0
  70. package/cjs/number/round.d.ts +4 -4
  71. package/cjs/number/round.js +9 -11
  72. package/cjs/object/except.d.ts +4 -4
  73. package/cjs/object/except.js +12 -15
  74. package/cjs/object/except.test.d.ts +2 -0
  75. package/cjs/object/flatten.d.ts +4 -4
  76. package/cjs/object/flatten.js +38 -40
  77. package/cjs/object/flatten.test.d.ts +2 -0
  78. package/cjs/object/get.d.ts +4 -4
  79. package/cjs/object/get.js +24 -26
  80. package/cjs/object/get.test.d.ts +2 -0
  81. package/cjs/object/map.d.ts +4 -4
  82. package/cjs/object/map.js +10 -12
  83. package/cjs/object/merge.d.ts +1 -1
  84. package/cjs/object/merge.js +99 -104
  85. package/cjs/object/merge.test.d.ts +2 -0
  86. package/cjs/object/only.d.ts +4 -4
  87. package/cjs/object/only.js +17 -20
  88. package/cjs/object/only.test.d.ts +2 -0
  89. package/cjs/object/set.d.ts +5 -5
  90. package/cjs/object/set.js +28 -30
  91. package/cjs/object/set.test.d.ts +2 -0
  92. package/cjs/object/sort.d.ts +4 -4
  93. package/cjs/object/sort.js +15 -17
  94. package/cjs/object/unset.d.ts +4 -4
  95. package/cjs/object/unset.js +23 -26
  96. package/cjs/object/unset.test.d.ts +2 -0
  97. package/cjs/string/capitalize.d.ts +6 -6
  98. package/cjs/string/capitalize.js +15 -18
  99. package/cjs/string/extension.d.ts +4 -4
  100. package/cjs/string/extension.js +11 -13
  101. package/cjs/string/initials.d.ts +4 -4
  102. package/cjs/string/initials.js +15 -17
  103. package/cjs/string/initials.test.d.ts +2 -0
  104. package/cjs/string/ltrim.d.ts +7 -7
  105. package/cjs/string/ltrim.js +15 -18
  106. package/cjs/string/readMoreChars.d.ts +5 -5
  107. package/cjs/string/readMoreChars.js +11 -13
  108. package/cjs/string/readMoreWords.d.ts +5 -5
  109. package/cjs/string/readMoreWords.js +14 -16
  110. package/cjs/string/removeFirst.d.ts +7 -7
  111. package/cjs/string/removeFirst.js +13 -16
  112. package/cjs/string/removeLast.d.ts +7 -7
  113. package/cjs/string/removeLast.js +13 -16
  114. package/cjs/string/repeatsOf.d.ts +7 -7
  115. package/cjs/string/repeatsOf.js +17 -19
  116. package/cjs/string/replaceAll.d.ts +8 -8
  117. package/cjs/string/replaceAll.js +14 -17
  118. package/cjs/string/replaceFirst.d.ts +8 -8
  119. package/cjs/string/replaceFirst.js +14 -17
  120. package/cjs/string/replaceLast.d.ts +8 -8
  121. package/cjs/string/replaceLast.js +21 -23
  122. package/cjs/string/rtrim.d.ts +7 -7
  123. package/cjs/string/rtrim.js +15 -18
  124. package/cjs/string/startsWithArabic.d.ts +2 -2
  125. package/cjs/string/startsWithArabic.js +13 -17
  126. package/cjs/string/toCamelCase.d.ts +1 -1
  127. package/cjs/string/toCamelCase.js +11 -14
  128. package/cjs/string/toCamelCase.test.d.ts +2 -0
  129. package/cjs/string/toInputName.d.ts +5 -5
  130. package/cjs/string/toInputName.js +21 -24
  131. package/cjs/string/toKebabCase.d.ts +4 -4
  132. package/cjs/string/toKebabCase.js +10 -13
  133. package/cjs/string/toKebabCase.test.d.ts +2 -0
  134. package/cjs/string/toSnakeCase.d.ts +7 -7
  135. package/cjs/string/toSnakeCase.js +20 -22
  136. package/cjs/string/toSnakeCase.test.d.ts +2 -0
  137. package/cjs/string/toStudlyCase.d.ts +9 -9
  138. package/cjs/string/toStudlyCase.js +19 -22
  139. package/cjs/string/trim.d.ts +7 -7
  140. package/cjs/string/trim.js +19 -22
  141. package/cjs/string/ucfirst.d.ts +6 -6
  142. package/cjs/string/ucfirst.js +11 -13
  143. package/cjs/types.d.ts +1 -1
  144. package/cjs/utils/debounce.d.ts +8 -8
  145. package/cjs/utils/debounce.js +16 -18
  146. package/cjs/utils/escapeRegex.d.ts +4 -4
  147. package/cjs/utils/escapeRegex.js +8 -10
  148. package/cjs/utils/escapeRegex.test.d.ts +2 -0
  149. package/esm/Random/random.d.ts +35 -35
  150. package/esm/Random/random.js +64 -65
  151. package/esm/Random/random.test.d.ts +2 -0
  152. package/esm/array/average.d.ts +6 -6
  153. package/esm/array/average.js +11 -13
  154. package/esm/array/average.test.d.ts +2 -0
  155. package/esm/array/chunk.d.ts +4 -4
  156. package/esm/array/chunk.js +12 -13
  157. package/esm/array/chunk.test.d.ts +2 -0
  158. package/esm/array/count.d.ts +4 -4
  159. package/esm/array/count.js +13 -15
  160. package/esm/array/count.test.d.ts +2 -0
  161. package/esm/array/countBy.d.ts +6 -6
  162. package/esm/array/countBy.js +19 -21
  163. package/esm/array/countBy.test.d.ts +2 -0
  164. package/esm/array/even.d.ts +6 -6
  165. package/esm/array/even.js +14 -16
  166. package/esm/array/even.test.d.ts +2 -0
  167. package/esm/array/evenIndexes.d.ts +4 -4
  168. package/esm/array/evenIndexes.js +8 -9
  169. package/esm/array/evenIndexes.test.d.ts +2 -0
  170. package/esm/array/groupBy.d.ts +7 -7
  171. package/esm/array/groupBy.js +44 -46
  172. package/esm/array/groupBy.test.d.ts +2 -0
  173. package/esm/array/max.d.ts +6 -6
  174. package/esm/array/max.js +19 -21
  175. package/esm/array/max.test.d.ts +2 -0
  176. package/esm/array/median.d.ts +6 -6
  177. package/esm/array/median.js +24 -26
  178. package/esm/array/median.test.d.ts +2 -0
  179. package/esm/array/min.d.ts +6 -6
  180. package/esm/array/min.js +19 -21
  181. package/esm/array/min.test.d.ts +2 -0
  182. package/esm/array/odd.d.ts +6 -6
  183. package/esm/array/odd.js +14 -16
  184. package/esm/array/odd.test.d.ts +2 -0
  185. package/esm/array/oddIndexes.d.ts +4 -4
  186. package/esm/array/oddIndexes.js +8 -9
  187. package/esm/array/oddIndexes.test.d.ts +2 -0
  188. package/esm/array/pluck.d.ts +8 -8
  189. package/esm/array/pluck.js +22 -24
  190. package/esm/array/pluck.test.d.ts +2 -0
  191. package/esm/array/pushUnique.d.ts +5 -5
  192. package/esm/array/pushUnique.js +13 -14
  193. package/esm/array/pushUnique.test.d.ts +2 -0
  194. package/esm/array/range.d.ts +4 -4
  195. package/esm/array/range.js +20 -21
  196. package/esm/array/range.test.d.ts +2 -0
  197. package/esm/array/sum.d.ts +6 -6
  198. package/esm/array/sum.js +27 -29
  199. package/esm/array/sum.test.d.ts +2 -0
  200. package/esm/array/unique.d.ts +4 -4
  201. package/esm/array/unique.js +13 -15
  202. package/esm/array/unique.test.d.ts +2 -0
  203. package/esm/array/unshiftUnique.d.ts +5 -5
  204. package/esm/array/unshiftUnique.js +13 -14
  205. package/esm/array/unshiftUnique.test.d.ts +2 -0
  206. package/esm/index.d.ts +56 -56
  207. package/esm/mixed/areEqual/areEqual.d.ts +4 -4
  208. package/esm/mixed/areEqual/areEqual.js +22 -23
  209. package/esm/mixed/areEqual/areEqual.test.d.ts +2 -0
  210. package/esm/mixed/clone/clone.d.ts +4 -4
  211. package/esm/mixed/clone/clone.js +11 -16
  212. package/esm/mixed/clone/clone.test.d.ts +2 -0
  213. package/esm/mixed/shuffle/shuffle.d.ts +4 -4
  214. package/esm/mixed/shuffle/shuffle.js +13 -14
  215. package/esm/mixed/shuffle/shuffle.test.d.ts +2 -0
  216. package/esm/number/round.d.ts +4 -4
  217. package/esm/number/round.js +8 -9
  218. package/esm/object/except.d.ts +4 -4
  219. package/esm/object/except.js +11 -13
  220. package/esm/object/except.test.d.ts +2 -0
  221. package/esm/object/flatten.d.ts +4 -4
  222. package/esm/object/flatten.js +37 -38
  223. package/esm/object/flatten.test.d.ts +2 -0
  224. package/esm/object/get.d.ts +4 -4
  225. package/esm/object/get.js +23 -24
  226. package/esm/object/get.test.d.ts +2 -0
  227. package/esm/object/map.d.ts +4 -4
  228. package/esm/object/map.js +9 -10
  229. package/esm/object/merge.d.ts +1 -1
  230. package/esm/object/merge.js +94 -96
  231. package/esm/object/merge.test.d.ts +2 -0
  232. package/esm/object/only.d.ts +4 -4
  233. package/esm/object/only.js +16 -18
  234. package/esm/object/only.test.d.ts +2 -0
  235. package/esm/object/set.d.ts +5 -5
  236. package/esm/object/set.js +27 -28
  237. package/esm/object/set.test.d.ts +2 -0
  238. package/esm/object/sort.d.ts +4 -4
  239. package/esm/object/sort.js +14 -15
  240. package/esm/object/unset.d.ts +4 -4
  241. package/esm/object/unset.js +22 -24
  242. package/esm/object/unset.test.d.ts +2 -0
  243. package/esm/string/capitalize.d.ts +6 -6
  244. package/esm/string/capitalize.js +14 -16
  245. package/esm/string/extension.d.ts +4 -4
  246. package/esm/string/extension.js +10 -11
  247. package/esm/string/initials.d.ts +4 -4
  248. package/esm/string/initials.js +14 -15
  249. package/esm/string/initials.test.d.ts +2 -0
  250. package/esm/string/ltrim.d.ts +7 -7
  251. package/esm/string/ltrim.js +14 -16
  252. package/esm/string/readMoreChars.d.ts +5 -5
  253. package/esm/string/readMoreChars.js +10 -11
  254. package/esm/string/readMoreWords.d.ts +5 -5
  255. package/esm/string/readMoreWords.js +13 -14
  256. package/esm/string/removeFirst.d.ts +7 -7
  257. package/esm/string/removeFirst.js +12 -14
  258. package/esm/string/removeLast.d.ts +7 -7
  259. package/esm/string/removeLast.js +12 -14
  260. package/esm/string/repeatsOf.d.ts +7 -7
  261. package/esm/string/repeatsOf.js +16 -17
  262. package/esm/string/replaceAll.d.ts +8 -8
  263. package/esm/string/replaceAll.js +13 -15
  264. package/esm/string/replaceFirst.d.ts +8 -8
  265. package/esm/string/replaceFirst.js +13 -15
  266. package/esm/string/replaceLast.d.ts +8 -8
  267. package/esm/string/replaceLast.js +20 -21
  268. package/esm/string/rtrim.d.ts +7 -7
  269. package/esm/string/rtrim.js +14 -16
  270. package/esm/string/startsWithArabic.d.ts +2 -2
  271. package/esm/string/startsWithArabic.js +10 -12
  272. package/esm/string/toCamelCase.d.ts +1 -1
  273. package/esm/string/toCamelCase.js +10 -12
  274. package/esm/string/toCamelCase.test.d.ts +2 -0
  275. package/esm/string/toInputName.d.ts +5 -5
  276. package/esm/string/toInputName.js +20 -22
  277. package/esm/string/toKebabCase.d.ts +4 -4
  278. package/esm/string/toKebabCase.js +9 -11
  279. package/esm/string/toKebabCase.test.d.ts +2 -0
  280. package/esm/string/toSnakeCase.d.ts +7 -7
  281. package/esm/string/toSnakeCase.js +19 -20
  282. package/esm/string/toSnakeCase.test.d.ts +2 -0
  283. package/esm/string/toStudlyCase.d.ts +9 -9
  284. package/esm/string/toStudlyCase.js +18 -20
  285. package/esm/string/trim.d.ts +7 -7
  286. package/esm/string/trim.js +18 -20
  287. package/esm/string/ucfirst.d.ts +6 -6
  288. package/esm/string/ucfirst.js +10 -11
  289. package/esm/types.d.ts +1 -1
  290. package/esm/utils/debounce.d.ts +8 -8
  291. package/esm/utils/debounce.js +15 -16
  292. package/esm/utils/escapeRegex.d.ts +4 -4
  293. package/esm/utils/escapeRegex.js +7 -8
  294. package/esm/utils/escapeRegex.test.d.ts +2 -0
  295. package/package.json +1 -1
package/README.md CHANGED
@@ -2057,6 +2057,8 @@ To run tests run `npm run test` or `yarn test`
2057
2057
 
2058
2058
  ## Change Log
2059
2059
 
2060
+ - 2.3.2 (06 May 2023)
2061
+ - Fixed clone function array cloning does not lose reference for nested objects.
2060
2062
  - 2.3.0 (25 Mar 2023)
2061
2063
  - Added [Range](#range) function.
2062
2064
  - Exposed typings.
@@ -1,36 +1,36 @@
1
- declare const Random: {
2
- /**
3
- * Get a random integer
4
- */
5
- int(min?: number, max?: number): number;
6
- /**
7
- * @alias Random.int
8
- */
9
- integer(min?: number, max?: number): number;
10
- /**
11
- * Generate random string
12
- */
13
- string(length?: number): string;
14
- /**
15
- * Generate random id
16
- */
17
- id(length?: number, startsWith?: string): string;
18
- /**
19
- * Generate random boolean value
20
- */
21
- bool(): boolean;
22
- /**
23
- * Alias to bool method
24
- */
25
- boolean(): boolean;
26
- /**
27
- * Get random date
28
- */
29
- date(minDate?: Date, maxDate?: Date): Date;
30
- /**
31
- * Get random color
32
- */
33
- color(): string;
34
- };
35
- export default Random;
1
+ declare const Random: {
2
+ /**
3
+ * Get a random integer
4
+ */
5
+ int(min?: number, max?: number): number;
6
+ /**
7
+ * @alias Random.int
8
+ */
9
+ integer(min?: number, max?: number): number;
10
+ /**
11
+ * Generate random string
12
+ */
13
+ string(length?: number): string;
14
+ /**
15
+ * Generate random id
16
+ */
17
+ id(length?: number, startsWith?: string): string;
18
+ /**
19
+ * Generate random boolean value
20
+ */
21
+ bool(): boolean;
22
+ /**
23
+ * Alias to bool method
24
+ */
25
+ boolean(): boolean;
26
+ /**
27
+ * Get random date
28
+ */
29
+ date(minDate?: Date, maxDate?: Date): Date;
30
+ /**
31
+ * Get random color
32
+ */
33
+ color(): string;
34
+ };
35
+ export default Random;
36
36
  //# sourceMappingURL=random.d.ts.map
@@ -1,67 +1,65 @@
1
- "use strict";
2
-
3
- const possible =
4
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
5
- const Random = {
6
- /**
7
- * Get a random integer
8
- */
9
- int(min = 1, max = 9999999) {
10
- return Math.floor(Math.random() * (max - min + 1)) + min;
11
- },
12
- /**
13
- * @alias Random.int
14
- */
15
- integer(min = 1, max = 9999999) {
16
- return this.int(min, max);
17
- },
18
- /**
19
- * Generate random string
20
- */
21
- string(length = 32) {
22
- let text = "";
23
- for (let i = 0; i < length; i++) {
24
- text += possible.charAt(Math.floor(Math.random() * possible.length));
25
- }
26
- return text;
27
- },
28
- /**
29
- * Generate random id
30
- */
31
- id(length = 6, startsWith = "el-") {
32
- return startsWith + Random.string(length);
33
- },
34
- /**
35
- * Generate random boolean value
36
- */
37
- bool() {
38
- return Random.int(0, 1) === 1;
39
- },
40
- /**
41
- * Alias to bool method
42
- */
43
- boolean() {
44
- return Random.int(0, 1) === 1;
45
- },
46
- /**
47
- * Get random date
48
- */
49
- date(minDate, maxDate) {
50
- if (minDate && !maxDate) {
51
- return new Date(Random.int(minDate.getTime(), Date.now()));
52
- }
53
- if (!minDate && maxDate) {
54
- return new Date(Random.int(0, maxDate.getTime()));
55
- }
56
- const now = Date.now();
57
- return new Date(Random.int(now - 100000000000, now));
58
- },
59
- /**
60
- * Get random color
61
- */
62
- color() {
63
- return "#" + Math.floor(Math.random() * 16777215).toString(16);
64
- },
65
- };
66
-
67
- module.exports = Random;
1
+ "use strict";
2
+ const possible =
3
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
4
+ const Random = {
5
+ /**
6
+ * Get a random integer
7
+ */
8
+ int(min = 1, max = 9999999) {
9
+ return Math.floor(Math.random() * (max - min + 1)) + min;
10
+ },
11
+ /**
12
+ * @alias Random.int
13
+ */
14
+ integer(min = 1, max = 9999999) {
15
+ return this.int(min, max);
16
+ },
17
+ /**
18
+ * Generate random string
19
+ */
20
+ string(length = 32) {
21
+ let text = "";
22
+ for (let i = 0; i < length; i++) {
23
+ text += possible.charAt(Math.floor(Math.random() * possible.length));
24
+ }
25
+ return text;
26
+ },
27
+ /**
28
+ * Generate random id
29
+ */
30
+ id(length = 6, startsWith = "el-") {
31
+ return startsWith + Random.string(length);
32
+ },
33
+ /**
34
+ * Generate random boolean value
35
+ */
36
+ bool() {
37
+ return Random.int(0, 1) === 1;
38
+ },
39
+ /**
40
+ * Alias to bool method
41
+ */
42
+ boolean() {
43
+ return Random.int(0, 1) === 1;
44
+ },
45
+ /**
46
+ * Get random date
47
+ */
48
+ date(minDate, maxDate) {
49
+ if (minDate && !maxDate) {
50
+ return new Date(Random.int(minDate.getTime(), Date.now()));
51
+ }
52
+ if (!minDate && maxDate) {
53
+ return new Date(Random.int(0, maxDate.getTime()));
54
+ }
55
+ const now = Date.now();
56
+ return new Date(Random.int(now - 100000000000, now));
57
+ },
58
+ /**
59
+ * Get random color
60
+ */
61
+ color() {
62
+ return "#" + Math.floor(Math.random() * 16777215).toString(16);
63
+ },
64
+ };
65
+ module.exports = Random;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=random.test.d.ts.map
@@ -1,7 +1,7 @@
1
- /**
2
- * Get the average value of the given array or the given array of objects using the given key
3
- *
4
- * The key supports dot notation. syntax: "key1.key2.key3"
5
- */
6
- export default function average(array: any[], key?: string): number;
1
+ /**
2
+ * Get the average value of the given array or the given array of objects using the given key
3
+ *
4
+ * The key supports dot notation. syntax: "key1.key2.key3"
5
+ */
6
+ export default function average(array: any[], key?: string): number;
7
7
  //# sourceMappingURL=average.d.ts.map
@@ -1,15 +1,12 @@
1
- "use strict";
2
-
3
- var sum = require("./sum.js");
4
-
5
- /**
6
- * Get the average value of the given array or the given array of objects using the given key
7
- *
8
- * The key supports dot notation. syntax: "key1.key2.key3"
9
- */
10
- function average(array, key) {
11
- if (!Array.isArray(array)) return 0;
12
- return sum(array, key) / array.length;
13
- }
14
-
15
- module.exports = average;
1
+ "use strict";
2
+ var sum = require("./sum.js");
3
+ /**
4
+ * Get the average value of the given array or the given array of objects using the given key
5
+ *
6
+ * The key supports dot notation. syntax: "key1.key2.key3"
7
+ */
8
+ function average(array, key) {
9
+ if (!Array.isArray(array)) return 0;
10
+ return sum(array, key) / array.length;
11
+ }
12
+ module.exports = average;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=average.test.d.ts.map
@@ -1,5 +1,5 @@
1
- /**
2
- * Chunk array|string by the given size
3
- */
4
- export default function chunk(array: any[] | string, size: number): any[];
1
+ /**
2
+ * Chunk array|string by the given size
3
+ */
4
+ export default function chunk(array: any[] | string, size: number): any[];
5
5
  //# sourceMappingURL=chunk.d.ts.map
@@ -1,15 +1,13 @@
1
- "use strict";
2
-
3
- /**
4
- * Chunk array|string by the given size
5
- */
6
- function chunk(array, size) {
7
- if (!Array.isArray(array) && typeof array !== "string") return [];
8
- const result = [];
9
- for (let i = 0; i < array.length; i += size) {
10
- result.push(array.slice(i, i + size));
11
- }
12
- return result;
13
- }
14
-
15
- module.exports = chunk;
1
+ "use strict";
2
+ /**
3
+ * Chunk array|string by the given size
4
+ */
5
+ function chunk(array, size) {
6
+ if (!Array.isArray(array) && typeof array !== "string") return [];
7
+ const result = [];
8
+ for (let i = 0; i < array.length; i += size) {
9
+ result.push(array.slice(i, i + size));
10
+ }
11
+ return result;
12
+ }
13
+ module.exports = chunk;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=chunk.test.d.ts.map
@@ -1,5 +1,5 @@
1
- /**
2
- * Count data by the given key or callback
3
- */
4
- export default function count(data: any[], key: string | Parameters<typeof Array.prototype.filter>[0]): number;
1
+ /**
2
+ * Count data by the given key or callback
3
+ */
4
+ export default function count(data: any[], key: string | Parameters<typeof Array.prototype.filter>[0]): number;
5
5
  //# sourceMappingURL=count.d.ts.map
@@ -1,17 +1,14 @@
1
- "use strict";
2
-
3
- var get = require("../object/get.js");
4
-
5
- const notFound = Symbol("notFound");
6
- /**
7
- * Count data by the given key or callback
8
- */
9
- function count(data, key) {
10
- if (!Array.isArray(data)) return 0;
11
- if (typeof key === "string") {
12
- return data.filter(item => get(item, key, notFound) !== notFound).length;
13
- }
14
- return data.filter(key).length;
15
- }
16
-
17
- module.exports = count;
1
+ "use strict";
2
+ var get = require("../object/get.js");
3
+ const notFound = Symbol("notFound");
4
+ /**
5
+ * Count data by the given key or callback
6
+ */
7
+ function count(data, key) {
8
+ if (!Array.isArray(data)) return 0;
9
+ if (typeof key === "string") {
10
+ return data.filter(item => get(item, key, notFound) !== notFound).length;
11
+ }
12
+ return data.filter(key).length;
13
+ }
14
+ module.exports = count;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=count.test.d.ts.map
@@ -1,7 +1,7 @@
1
- /**
2
- * Count the occurrences of values in an array for the given key
3
- */
4
- export default function countBy(array: any[], key: string): {
5
- [key: string]: number;
6
- };
1
+ /**
2
+ * Count the occurrences of values in an array for the given key
3
+ */
4
+ export default function countBy(array: any[], key: string): {
5
+ [key: string]: number;
6
+ };
7
7
  //# sourceMappingURL=countBy.d.ts.map
@@ -1,23 +1,20 @@
1
- "use strict";
2
-
3
- var get = require("../object/get.js");
4
-
5
- /**
6
- * Count the occurrences of values in an array for the given key
7
- */
8
- function countBy(array, key) {
9
- if (!Array.isArray(array)) {
10
- return {};
11
- }
12
- return array.reduce((result, item) => {
13
- const value = get(item, key);
14
- if (result[value]) {
15
- result[value]++;
16
- } else {
17
- result[value] = 1;
18
- }
19
- return result;
20
- }, {});
21
- }
22
-
23
- module.exports = countBy;
1
+ "use strict";
2
+ var get = require("../object/get.js");
3
+ /**
4
+ * Count the occurrences of values in an array for the given key
5
+ */
6
+ function countBy(array, key) {
7
+ if (!Array.isArray(array)) {
8
+ return {};
9
+ }
10
+ return array.reduce((result, item) => {
11
+ const value = get(item, key);
12
+ if (result[value]) {
13
+ result[value]++;
14
+ } else {
15
+ result[value] = 1;
16
+ }
17
+ return result;
18
+ }, {});
19
+ }
20
+ module.exports = countBy;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=countBy.test.d.ts.map
@@ -1,7 +1,7 @@
1
- /**
2
- * Get the even values of the given array or the given array of objects using the given key
3
- *
4
- * The key supports dot notation. syntax: "key1.key2.key3"
5
- */
6
- export default function even(array: any[], key?: string): any[];
1
+ /**
2
+ * Get the even values of the given array or the given array of objects using the given key
3
+ *
4
+ * The key supports dot notation. syntax: "key1.key2.key3"
5
+ */
6
+ export default function even(array: any[], key?: string): any[];
7
7
  //# sourceMappingURL=even.d.ts.map
package/cjs/array/even.js CHANGED
@@ -1,18 +1,15 @@
1
- "use strict";
2
-
3
- var get = require("../object/get.js");
4
-
5
- /**
6
- * Get the even values of the given array or the given array of objects using the given key
7
- *
8
- * The key supports dot notation. syntax: "key1.key2.key3"
9
- */
10
- function even(array, key) {
11
- if (!Array.isArray(array)) return [];
12
- return array.filter(item => {
13
- const value = key ? get(item, key) : item;
14
- return typeof value !== "number" ? false : value % 2 === 0;
15
- });
16
- }
17
-
18
- module.exports = even;
1
+ "use strict";
2
+ var get = require("../object/get.js");
3
+ /**
4
+ * Get the even values of the given array or the given array of objects using the given key
5
+ *
6
+ * The key supports dot notation. syntax: "key1.key2.key3"
7
+ */
8
+ function even(array, key) {
9
+ if (!Array.isArray(array)) return [];
10
+ return array.filter(item => {
11
+ const value = key ? get(item, key) : item;
12
+ return typeof value !== "number" ? false : value % 2 === 0;
13
+ });
14
+ }
15
+ module.exports = even;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=even.test.d.ts.map
@@ -1,5 +1,5 @@
1
- /**
2
- * Get the values of the given array by the even indexes or the given array of objects using the given key
3
- */
4
- export default function evenIndexes(array: any[]): any[];
1
+ /**
2
+ * Get the values of the given array by the even indexes or the given array of objects using the given key
3
+ */
4
+ export default function evenIndexes(array: any[]): any[];
5
5
  //# sourceMappingURL=evenIndexes.d.ts.map
@@ -1,11 +1,9 @@
1
- "use strict";
2
-
3
- /**
4
- * Get the values of the given array by the even indexes or the given array of objects using the given key
5
- */
6
- function evenIndexes(array) {
7
- if (!Array.isArray(array)) return [];
8
- return array.filter((_item, index) => index % 2 === 0);
9
- }
10
-
11
- module.exports = evenIndexes;
1
+ "use strict";
2
+ /**
3
+ * Get the values of the given array by the even indexes or the given array of objects using the given key
4
+ */
5
+ function evenIndexes(array) {
6
+ if (!Array.isArray(array)) return [];
7
+ return array.filter((_item, index) => index % 2 === 0);
8
+ }
9
+ module.exports = evenIndexes;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=evenIndexes.test.d.ts.map
@@ -1,8 +1,8 @@
1
- import { GenericObject } from "../types";
2
- /**
3
- * Group the given array by the given key(s).
4
- *
5
- * The key(s) support dot notation.
6
- */
7
- export default function groupBy(array: GenericObject[], groupByKey: string | string[], listAs?: string): GenericObject[];
1
+ import { GenericObject } from "../types";
2
+ /**
3
+ * Group the given array by the given key(s).
4
+ *
5
+ * The key(s) support dot notation.
6
+ */
7
+ export default function groupBy(array: GenericObject[], groupByKey: string | string[], listAs?: string): GenericObject[];
8
8
  //# sourceMappingURL=groupBy.d.ts.map
@@ -1,48 +1,45 @@
1
- "use strict";
2
-
3
- var get = require("../object/get.js");
4
- require("../object/merge.js");
5
-
6
- /**
7
- * Group the given array by the given key(s).
8
- *
9
- * The key(s) support dot notation.
10
- */
11
- function groupBy(array, groupByKey, listAs = "data") {
12
- const groupedData = {};
13
- const groupByKeys =
14
- typeof groupByKey === "string" ? [groupByKey] : groupByKey;
15
- for (const item of array) {
16
- const baseKeys = [];
17
- for (const groupByKey of groupByKeys) {
18
- const value = get(item, groupByKey);
19
- if (!value) break;
20
- baseKeys.push({
21
- key: groupByKey,
22
- value,
23
- });
24
- }
25
- const dataKey = JSON.stringify(baseKeys);
26
- if (!groupedData[dataKey]) {
27
- const groupedDataList = {
28
- data: [],
29
- };
30
- for (const groupByKeyData of baseKeys) {
31
- groupedDataList[groupByKeyData.key] = groupByKeyData.value;
32
- }
33
- groupedData[dataKey] = groupedDataList;
34
- }
35
- groupedData[dataKey]?.data?.push(item);
36
- }
37
- const finalData = [];
38
- for (const groupedKeyWithValue in groupedData) {
39
- const { data, ...otherGroupedKeys } = groupedData[groupedKeyWithValue];
40
- finalData.push({
41
- ...otherGroupedKeys,
42
- [listAs]: data,
43
- });
44
- }
45
- return finalData;
46
- }
47
-
48
- module.exports = groupBy;
1
+ "use strict";
2
+ var get = require("../object/get.js");
3
+ require("../object/merge.js");
4
+ /**
5
+ * Group the given array by the given key(s).
6
+ *
7
+ * The key(s) support dot notation.
8
+ */
9
+ function groupBy(array, groupByKey, listAs = "data") {
10
+ const groupedData = {};
11
+ const groupByKeys =
12
+ typeof groupByKey === "string" ? [groupByKey] : groupByKey;
13
+ for (const item of array) {
14
+ const baseKeys = [];
15
+ for (const groupByKey of groupByKeys) {
16
+ const value = get(item, groupByKey);
17
+ if (!value) break;
18
+ baseKeys.push({
19
+ key: groupByKey,
20
+ value,
21
+ });
22
+ }
23
+ const dataKey = JSON.stringify(baseKeys);
24
+ if (!groupedData[dataKey]) {
25
+ const groupedDataList = {
26
+ data: [],
27
+ };
28
+ for (const groupByKeyData of baseKeys) {
29
+ groupedDataList[groupByKeyData.key] = groupByKeyData.value;
30
+ }
31
+ groupedData[dataKey] = groupedDataList;
32
+ }
33
+ groupedData[dataKey]?.data?.push(item);
34
+ }
35
+ const finalData = [];
36
+ for (const groupedKeyWithValue in groupedData) {
37
+ const { data, ...otherGroupedKeys } = groupedData[groupedKeyWithValue];
38
+ finalData.push({
39
+ ...otherGroupedKeys,
40
+ [listAs]: data,
41
+ });
42
+ }
43
+ return finalData;
44
+ }
45
+ module.exports = groupBy;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=groupBy.test.d.ts.map
@@ -1,7 +1,7 @@
1
- /**
2
- * Get the max value of the given array or the given array of objects using the given key
3
- *
4
- * The key supports dot notation. syntax: "key1.key2.key3"
5
- */
6
- export default function max(array: any[], key?: string): number;
1
+ /**
2
+ * Get the max value of the given array or the given array of objects using the given key
3
+ *
4
+ * The key supports dot notation. syntax: "key1.key2.key3"
5
+ */
6
+ export default function max(array: any[], key?: string): number;
7
7
  //# sourceMappingURL=max.d.ts.map