@valkyriestudios/utils 12.6.0 → 12.7.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 (162) hide show
  1. package/array/groupBy.d.ts +23 -0
  2. package/{dist/array → array}/groupBy.js +6 -6
  3. package/package.json +1 -47
  4. package/dist/array/groupBy.d.ts +0 -3
  5. package/publish.sh +0 -27
  6. /package/{dist/array → array}/dedupe.d.ts +0 -0
  7. /package/{dist/array → array}/dedupe.js +0 -0
  8. /package/{dist/array → array}/index.d.ts +0 -0
  9. /package/{dist/array → array}/index.js +0 -0
  10. /package/{dist/array → array}/is.d.ts +0 -0
  11. /package/{dist/array → array}/is.js +0 -0
  12. /package/{dist/array → array}/isNotEmpty.d.ts +0 -0
  13. /package/{dist/array → array}/isNotEmpty.js +0 -0
  14. /package/{dist/array → array}/join.d.ts +0 -0
  15. /package/{dist/array → array}/join.js +0 -0
  16. /package/{dist/array → array}/mapFn.d.ts +0 -0
  17. /package/{dist/array → array}/mapFn.js +0 -0
  18. /package/{dist/array → array}/mapKey.d.ts +0 -0
  19. /package/{dist/array → array}/mapKey.js +0 -0
  20. /package/{dist/array → array}/mapPrimitive.d.ts +0 -0
  21. /package/{dist/array → array}/mapPrimitive.js +0 -0
  22. /package/{dist/array → array}/shuffle.d.ts +0 -0
  23. /package/{dist/array → array}/shuffle.js +0 -0
  24. /package/{dist/array → array}/sort.d.ts +0 -0
  25. /package/{dist/array → array}/sort.js +0 -0
  26. /package/{dist/boolean → boolean}/index.d.ts +0 -0
  27. /package/{dist/boolean → boolean}/index.js +0 -0
  28. /package/{dist/boolean → boolean}/is.d.ts +0 -0
  29. /package/{dist/boolean → boolean}/is.js +0 -0
  30. /package/{dist/caching → caching}/index.d.ts +0 -0
  31. /package/{dist/caching → caching}/index.js +0 -0
  32. /package/{dist/caching → caching}/memoize.d.ts +0 -0
  33. /package/{dist/caching → caching}/memoize.js +0 -0
  34. /package/{dist/date → date}/addUTC.d.ts +0 -0
  35. /package/{dist/date → date}/addUTC.js +0 -0
  36. /package/{dist/date → date}/diff.d.ts +0 -0
  37. /package/{dist/date → date}/diff.js +0 -0
  38. /package/{dist/date → date}/endOfUTC.d.ts +0 -0
  39. /package/{dist/date → date}/endOfUTC.js +0 -0
  40. /package/{dist/date → date}/format.d.ts +0 -0
  41. /package/{dist/date → date}/format.js +0 -0
  42. /package/{dist/date → date}/index.d.ts +0 -0
  43. /package/{dist/date → date}/index.js +0 -0
  44. /package/{dist/date → date}/is.d.ts +0 -0
  45. /package/{dist/date → date}/is.js +0 -0
  46. /package/{dist/date → date}/nowUnix.d.ts +0 -0
  47. /package/{dist/date → date}/nowUnix.js +0 -0
  48. /package/{dist/date → date}/nowUnixMs.d.ts +0 -0
  49. /package/{dist/date → date}/nowUnixMs.js +0 -0
  50. /package/{dist/date → date}/startOfUTC.d.ts +0 -0
  51. /package/{dist/date → date}/startOfUTC.js +0 -0
  52. /package/{dist/date → date}/toUTC.d.ts +0 -0
  53. /package/{dist/date → date}/toUTC.js +0 -0
  54. /package/{dist/date → date}/toUnix.d.ts +0 -0
  55. /package/{dist/date → date}/toUnix.js +0 -0
  56. /package/{dist/deep → deep}/freeze.d.ts +0 -0
  57. /package/{dist/deep → deep}/freeze.js +0 -0
  58. /package/{dist/deep → deep}/get.d.ts +0 -0
  59. /package/{dist/deep → deep}/get.js +0 -0
  60. /package/{dist/deep → deep}/index.d.ts +0 -0
  61. /package/{dist/deep → deep}/index.js +0 -0
  62. /package/{dist/deep → deep}/seal.d.ts +0 -0
  63. /package/{dist/deep → deep}/seal.js +0 -0
  64. /package/{dist/deep → deep}/set.d.ts +0 -0
  65. /package/{dist/deep → deep}/set.js +0 -0
  66. /package/{dist/equal.d.ts → equal.d.ts} +0 -0
  67. /package/{dist/equal.js → equal.js} +0 -0
  68. /package/{dist/formdata → formdata}/index.d.ts +0 -0
  69. /package/{dist/formdata → formdata}/index.js +0 -0
  70. /package/{dist/formdata → formdata}/is.d.ts +0 -0
  71. /package/{dist/formdata → formdata}/is.js +0 -0
  72. /package/{dist/function → function}/index.d.ts +0 -0
  73. /package/{dist/function → function}/index.js +0 -0
  74. /package/{dist/function → function}/is.d.ts +0 -0
  75. /package/{dist/function → function}/is.js +0 -0
  76. /package/{dist/function → function}/isAsync.d.ts +0 -0
  77. /package/{dist/function → function}/isAsync.js +0 -0
  78. /package/{dist/function → function}/noop.d.ts +0 -0
  79. /package/{dist/function → function}/noop.js +0 -0
  80. /package/{dist/function → function}/noopresolve.d.ts +0 -0
  81. /package/{dist/function → function}/noopresolve.js +0 -0
  82. /package/{dist/function → function}/noopreturn.d.ts +0 -0
  83. /package/{dist/function → function}/noopreturn.js +0 -0
  84. /package/{dist/function → function}/sleep.d.ts +0 -0
  85. /package/{dist/function → function}/sleep.js +0 -0
  86. /package/{dist/hash → hash}/fnv1A.d.ts +0 -0
  87. /package/{dist/hash → hash}/fnv1A.js +0 -0
  88. /package/{dist/hash → hash}/guid.d.ts +0 -0
  89. /package/{dist/hash → hash}/guid.js +0 -0
  90. /package/{dist/hash → hash}/index.d.ts +0 -0
  91. /package/{dist/hash → hash}/index.js +0 -0
  92. /package/{dist/index.d.ts → index.d.ts} +0 -0
  93. /package/{dist/is.d.ts → is.d.ts} +0 -0
  94. /package/{dist/is.js → is.js} +0 -0
  95. /package/{dist/number → number}/index.d.ts +0 -0
  96. /package/{dist/number → number}/index.js +0 -0
  97. /package/{dist/number → number}/is.d.ts +0 -0
  98. /package/{dist/number → number}/is.js +0 -0
  99. /package/{dist/number → number}/isAbove.d.ts +0 -0
  100. /package/{dist/number → number}/isAbove.js +0 -0
  101. /package/{dist/number → number}/isAboveOrEqual.d.ts +0 -0
  102. /package/{dist/number → number}/isAboveOrEqual.js +0 -0
  103. /package/{dist/number → number}/isBelow.d.ts +0 -0
  104. /package/{dist/number → number}/isBelow.js +0 -0
  105. /package/{dist/number → number}/isBelowOrEqual.d.ts +0 -0
  106. /package/{dist/number → number}/isBelowOrEqual.js +0 -0
  107. /package/{dist/number → number}/isBetween.d.ts +0 -0
  108. /package/{dist/number → number}/isBetween.js +0 -0
  109. /package/{dist/number → number}/isInteger.d.ts +0 -0
  110. /package/{dist/number → number}/isInteger.js +0 -0
  111. /package/{dist/number → number}/isIntegerAbove.d.ts +0 -0
  112. /package/{dist/number → number}/isIntegerAbove.js +0 -0
  113. /package/{dist/number → number}/isIntegerAboveOrEqual.d.ts +0 -0
  114. /package/{dist/number → number}/isIntegerAboveOrEqual.js +0 -0
  115. /package/{dist/number → number}/isIntegerBelow.d.ts +0 -0
  116. /package/{dist/number → number}/isIntegerBelow.js +0 -0
  117. /package/{dist/number → number}/isIntegerBelowOrEqual.d.ts +0 -0
  118. /package/{dist/number → number}/isIntegerBelowOrEqual.js +0 -0
  119. /package/{dist/number → number}/isIntegerBetween.d.ts +0 -0
  120. /package/{dist/number → number}/isIntegerBetween.js +0 -0
  121. /package/{dist/number → number}/isNumericalNaN.d.ts +0 -0
  122. /package/{dist/number → number}/isNumericalNaN.js +0 -0
  123. /package/{dist/number → number}/randomBetween.d.ts +0 -0
  124. /package/{dist/number → number}/randomBetween.js +0 -0
  125. /package/{dist/number → number}/randomIntBetween.d.ts +0 -0
  126. /package/{dist/number → number}/randomIntBetween.js +0 -0
  127. /package/{dist/number → number}/round.d.ts +0 -0
  128. /package/{dist/number → number}/round.js +0 -0
  129. /package/{dist/number → number}/toPercentage.d.ts +0 -0
  130. /package/{dist/number → number}/toPercentage.js +0 -0
  131. /package/{dist/object → object}/define.d.ts +0 -0
  132. /package/{dist/object → object}/define.js +0 -0
  133. /package/{dist/object → object}/index.d.ts +0 -0
  134. /package/{dist/object → object}/index.js +0 -0
  135. /package/{dist/object → object}/is.d.ts +0 -0
  136. /package/{dist/object → object}/is.js +0 -0
  137. /package/{dist/object → object}/isNotEmpty.d.ts +0 -0
  138. /package/{dist/object → object}/isNotEmpty.js +0 -0
  139. /package/{dist/object → object}/merge.d.ts +0 -0
  140. /package/{dist/object → object}/merge.js +0 -0
  141. /package/{dist/object → object}/pick.d.ts +0 -0
  142. /package/{dist/object → object}/pick.js +0 -0
  143. /package/{dist/regexp → regexp}/index.d.ts +0 -0
  144. /package/{dist/regexp → regexp}/index.js +0 -0
  145. /package/{dist/regexp → regexp}/is.d.ts +0 -0
  146. /package/{dist/regexp → regexp}/is.js +0 -0
  147. /package/{dist/regexp → regexp}/sanitize.d.ts +0 -0
  148. /package/{dist/regexp → regexp}/sanitize.js +0 -0
  149. /package/{dist/string → string}/humanizeBytes.d.ts +0 -0
  150. /package/{dist/string → string}/humanizeBytes.js +0 -0
  151. /package/{dist/string → string}/humanizeNumber.d.ts +0 -0
  152. /package/{dist/string → string}/humanizeNumber.js +0 -0
  153. /package/{dist/string → string}/index.d.ts +0 -0
  154. /package/{dist/string → string}/index.js +0 -0
  155. /package/{dist/string → string}/is.d.ts +0 -0
  156. /package/{dist/string → string}/is.js +0 -0
  157. /package/{dist/string → string}/isBetween.d.ts +0 -0
  158. /package/{dist/string → string}/isBetween.js +0 -0
  159. /package/{dist/string → string}/isNotEmpty.d.ts +0 -0
  160. /package/{dist/string → string}/isNotEmpty.js +0 -0
  161. /package/{dist/string → string}/shorten.d.ts +0 -0
  162. /package/{dist/string → string}/shorten.js +0 -0
@@ -0,0 +1,23 @@
1
+ type Handler<T> = (val: T) => string | number | boolean;
2
+ /**
3
+ * Return a grouped object from an array.
4
+ * Take Note: This function will automatically filter out any non/empty objects from the array
5
+ *
6
+ * Example:
7
+ * const group = groupBy([
8
+ * {tally: 20, name: 'Peter'},
9
+ * {tally: 40, name: 'Jake'},
10
+ * {tally: 5, name: 'Bob'},
11
+ * ], el => el.tally > 15);
12
+ * Output:
13
+ * {
14
+ * false: [{tally: 5, name: 'Bob'}],
15
+ * true: [{tally: 20, name: 'Peter'}, {tally: 40, name: 'Jake'}],
16
+ * }
17
+ *
18
+ * @param {T[]} arr - Array to group
19
+ * @param {Handler<T>|string} handler - String or a function, determines what to group by
20
+ * @returns {Record<string, T[]>}
21
+ */
22
+ declare function groupBy<T extends Record<string, any>>(arr: T[], handler: Handler<T> | string): Record<string, T[]>;
23
+ export { groupBy, groupBy as default };
@@ -10,23 +10,23 @@ function groupBy(arr, handler) {
10
10
  const acc = {};
11
11
  const n_handler = typeof handler === 'function'
12
12
  ? handler
13
- : typeof handler === 'string' && handler.length
14
- ? ((el) => el[handler] ?? FALLBACK)
13
+ : typeof handler === 'string'
14
+ ? ((el) => el[handler])
15
15
  : defaultHandler;
16
16
  let key;
17
- const set = new Set();
18
- for (const el of arr) {
17
+ let el;
18
+ for (let i = 0; i < arr.length; i++) {
19
+ el = arr[i];
19
20
  if (!(0, isNotEmpty_1.isNotEmptyObject)(el))
20
21
  continue;
21
22
  key = n_handler(el);
22
23
  if (key === undefined || (typeof key === 'string' && !key.length))
23
24
  key = FALLBACK;
24
- if (set.has(key)) {
25
+ if (Array.isArray(acc[key])) {
25
26
  acc[key].push(el);
26
27
  continue;
27
28
  }
28
29
  acc[key] = [el];
29
- set.add(key);
30
30
  }
31
31
  return acc;
32
32
  }
package/package.json CHANGED
@@ -1,47 +1 @@
1
- {
2
- "name": "@valkyriestudios/utils",
3
- "version": "12.6.0",
4
- "description": "A collection of single-function utilities for common tasks",
5
- "author": {
6
- "name": "Peter Vermeulen",
7
- "url": "https://www.linkedin.com/in/petervermeulen1/"
8
- },
9
- "keywords": [
10
- "utility",
11
- "library",
12
- "javascript",
13
- "js",
14
- "node",
15
- "bun"
16
- ],
17
- "license": "MIT",
18
- "scripts": {
19
- "build": "npm run lint && npm run test && tsc -p ./tsconfig.build.json && tsc -p ./tsconfig.types.json && tsc -p ./tsconfig.types_all.json",
20
- "test": "node --icu-data-dir=node_modules/full-icu --require esbuild-register --test ./test/lib/**/*.ts ./test/lib/*.ts",
21
- "test:only": "node --icu-data-dir=node_modules/full-icu --require esbuild-register --test --test-only ./test/lib/**/*.ts ./test/lib/*.ts",
22
- "test:coverage": "nyc npm run test",
23
- "lint": "npm run lint:src && npm run lint:test",
24
- "lint:src": "./node_modules/.bin/eslint --ext .js,.ts,.mjs ./lib",
25
- "lint:test": "./node_modules/.bin/eslint --ext .js,.ts,.mjs ./test",
26
- "codecov": "codecov",
27
- "benchmark": "node --require esbuild-register ./test/benchmark.ts"
28
- },
29
- "repository": {
30
- "type": "git",
31
- "url": "git+https://github.com/ValkyrieStudios/utils.git"
32
- },
33
- "bugs": {
34
- "url": "https://github.com/ValkyrieStudios/utils/issues"
35
- },
36
- "homepage": "https://github.com/ValkyrieStudios/utils#readme",
37
- "devDependencies": {
38
- "@types/node": "^20.12.7",
39
- "@typescript-eslint/eslint-plugin": "^7.8.0",
40
- "@typescript-eslint/parser": "^7.8.0",
41
- "esbuild-register": "^3.5.0",
42
- "eslint": "^8.57.0",
43
- "full-icu": "^1.5.0",
44
- "nyc": "^15.1.0",
45
- "typescript": "^5.4.5"
46
- }
47
- }
1
+ { "name": "@valkyriestudios/utils", "version": "12.7.0", "description": "A collection of single-function utilities for common tasks", "author": { "name": "Peter Vermeulen", "url": "https://www.linkedin.com/in/petervermeulen1/" }, "keywords": [ "utility", "library", "javascript", "js", "node", "bun" ], "license": "MIT", "repository": { "type": "git", "url": "git+https://github.com/ValkyrieStudios/utils.git" }, "bugs": { "url": "https://github.com/ValkyrieStudios/utils/issues" }, "homepage": "https://github.com/ValkyrieStudios/utils#readme", "types": "index.d.ts" }
@@ -1,3 +0,0 @@
1
- type Handler<T> = (val: T) => string | number | boolean;
2
- declare function groupBy<T extends Record<string, any>>(arr: T[], handler: Handler<T> | string): Record<string, T[]>;
3
- export { groupBy, groupBy as default };
package/publish.sh DELETED
@@ -1,27 +0,0 @@
1
- rm -rf ./dist
2
- mkdir ./dist
3
-
4
- # Main build
5
- npx tsc -p ./tsconfig.build.json
6
-
7
- # Main - Declaration file
8
- npx tsc -p ./tsconfig.types.json
9
-
10
- # Single Declaration file
11
- npx tsc -p ./tsconfig.types_all.json
12
-
13
- # Copy files over
14
- cp package.json README.md LICENSE.md .npmignore ./dist
15
-
16
- # Edit package.json to remove scripts/devDependencies
17
- echo $(cat ./dist/package.json | jq 'del(.scripts)') > ./dist/package.json
18
- echo $(cat ./dist/package.json | jq 'del(.devDependencies)') > ./dist/package.json
19
- echo $(cat ./dist/package.json | jq '.+={types:"index.d.ts"}') > ./dist/package.json
20
-
21
- cd ./dist
22
-
23
- npm publish
24
-
25
- cd ..
26
-
27
- rm -rf ./dist/
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes