@oscarpalmer/atoms 0.99.0 → 0.100.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 (235) hide show
  1. package/dist/array/flatten.cjs +9 -0
  2. package/dist/array/flatten.js +5 -0
  3. package/dist/array/group-by.cjs +2 -27
  4. package/dist/array/group-by.js +2 -26
  5. package/dist/array/index.cjs +13 -19
  6. package/dist/array/index.js +6 -17
  7. package/dist/array/insert.cjs +2 -28
  8. package/dist/array/insert.js +2 -27
  9. package/dist/array/push.cjs +11 -0
  10. package/dist/array/push.js +7 -0
  11. package/dist/array/sort.cjs +38 -38
  12. package/dist/array/sort.js +38 -38
  13. package/dist/array/splice.cjs +2 -2
  14. package/dist/array/splice.js +1 -1
  15. package/dist/array/to-map.cjs +1 -1
  16. package/dist/array/to-map.js +1 -1
  17. package/dist/array/to-record.cjs +2 -2
  18. package/dist/array/to-record.js +1 -1
  19. package/dist/array/unique.cjs +1 -4
  20. package/dist/array/unique.js +1 -4
  21. package/dist/color/constants.cjs +33 -0
  22. package/dist/color/constants.js +22 -0
  23. package/dist/color/get.cjs +50 -0
  24. package/dist/color/get.js +46 -0
  25. package/dist/color/index.cjs +98 -0
  26. package/dist/color/index.js +85 -0
  27. package/dist/color/is.cjs +58 -0
  28. package/dist/color/is.js +51 -0
  29. package/dist/color/misc.cjs +16 -0
  30. package/dist/color/misc.js +12 -0
  31. package/dist/color/models.cjs +2 -0
  32. package/dist/color/models.js +1 -0
  33. package/dist/color/value.cjs +90 -0
  34. package/dist/color/value.js +83 -0
  35. package/dist/emitter.cjs +8 -8
  36. package/dist/emitter.js +1 -1
  37. package/dist/function.cjs +52 -41
  38. package/dist/function.js +51 -39
  39. package/dist/i18n.cjs +6 -4
  40. package/dist/i18n.js +6 -4
  41. package/dist/index.cjs +78 -71
  42. package/dist/index.js +34 -27
  43. package/dist/internal/array/callbacks.cjs +1 -4
  44. package/dist/internal/array/callbacks.js +1 -4
  45. package/dist/internal/array/find.cjs +4 -4
  46. package/dist/internal/array/find.js +4 -4
  47. package/dist/internal/array/group.cjs +32 -0
  48. package/dist/internal/array/group.js +28 -0
  49. package/dist/internal/array/insert.cjs +33 -0
  50. package/dist/internal/array/insert.js +29 -0
  51. package/dist/{array → internal/array}/shuffle.cjs +4 -4
  52. package/dist/{array → internal/array}/shuffle.js +1 -1
  53. package/dist/internal/function.cjs +29 -0
  54. package/dist/internal/function.js +25 -0
  55. package/dist/internal/is.cjs +45 -0
  56. package/dist/internal/is.js +37 -0
  57. package/dist/internal/math/aggregate.cjs +4 -0
  58. package/dist/internal/math/aggregate.js +4 -1
  59. package/dist/internal/number.cjs +67 -0
  60. package/dist/internal/number.js +61 -0
  61. package/dist/internal/random.cjs +23 -0
  62. package/dist/internal/random.js +18 -0
  63. package/dist/internal/string.cjs +50 -0
  64. package/dist/internal/string.js +41 -0
  65. package/dist/{value → internal/value}/compare.cjs +8 -8
  66. package/dist/{value → internal/value}/compare.js +3 -3
  67. package/dist/{value → internal/value}/equal.cjs +3 -3
  68. package/dist/{value → internal/value}/get.cjs +6 -4
  69. package/dist/{value → internal/value}/get.js +4 -2
  70. package/dist/internal/value/misc.cjs +34 -0
  71. package/dist/internal/value/misc.js +29 -0
  72. package/dist/{value → internal/value}/set.cjs +8 -5
  73. package/dist/{value → internal/value}/set.js +5 -2
  74. package/dist/is.cjs +10 -31
  75. package/dist/is.js +4 -24
  76. package/dist/logger.cjs +9 -9
  77. package/dist/logger.js +1 -1
  78. package/dist/math.cjs +1 -4
  79. package/dist/math.js +2 -4
  80. package/dist/number.cjs +6 -49
  81. package/dist/number.js +1 -48
  82. package/dist/query.cjs +32 -33
  83. package/dist/query.js +29 -30
  84. package/dist/random.cjs +9 -22
  85. package/dist/random.js +4 -16
  86. package/dist/sized.cjs +24 -30
  87. package/dist/sized.js +23 -29
  88. package/dist/string/case.cjs +5 -5
  89. package/dist/string/case.js +1 -1
  90. package/dist/string/index.cjs +4 -3
  91. package/dist/string/index.js +2 -1
  92. package/dist/string/misc.cjs +2 -26
  93. package/dist/string/misc.js +3 -24
  94. package/dist/string/template.cjs +4 -4
  95. package/dist/string/template.js +2 -2
  96. package/dist/value/clone.cjs +12 -2
  97. package/dist/value/clone.js +11 -1
  98. package/dist/value/diff.cjs +13 -10
  99. package/dist/value/diff.js +7 -4
  100. package/dist/value/index.cjs +11 -21
  101. package/dist/value/index.js +5 -19
  102. package/dist/value/merge.cjs +24 -7
  103. package/dist/value/merge.js +24 -7
  104. package/dist/value/partial.cjs +18 -0
  105. package/dist/value/partial.js +14 -0
  106. package/dist/value/smush.cjs +6 -6
  107. package/dist/value/smush.js +2 -2
  108. package/dist/value/unsmush.cjs +4 -4
  109. package/dist/value/unsmush.js +2 -2
  110. package/package.json +1 -2
  111. package/src/array/models.ts +32 -9
  112. package/src/array/sort.ts +124 -76
  113. package/src/function.ts +11 -8
  114. package/src/internal/array/shuffle.ts +1 -1
  115. package/src/internal/function.ts +36 -0
  116. package/types/array/count.d.cts +6 -0
  117. package/types/array/exists.d.cts +6 -0
  118. package/types/array/filter.d.cts +6 -0
  119. package/types/array/find.d.cts +6 -0
  120. package/types/array/flatten.d.cts +9 -0
  121. package/types/array/flatten.d.ts +5 -0
  122. package/types/array/group-by.d.cts +7 -2
  123. package/types/array/group-by.d.ts +0 -1
  124. package/types/array/index-of.d.cts +6 -0
  125. package/types/array/index.d.cts +59 -29
  126. package/types/array/index.d.ts +9 -17
  127. package/types/array/insert.d.cts +0 -2
  128. package/types/array/insert.d.ts +0 -2
  129. package/types/array/models.d.cts +26 -16
  130. package/types/array/models.d.ts +26 -15
  131. package/types/array/push.d.cts +10 -0
  132. package/types/array/push.d.ts +6 -0
  133. package/types/array/sort.d.cts +42 -16
  134. package/types/array/sort.d.ts +14 -14
  135. package/types/array/to-map.d.cts +6 -0
  136. package/types/array/to-record.d.cts +7 -1
  137. package/types/array/unique.d.cts +6 -0
  138. package/types/color/constants.d.cts +23 -0
  139. package/types/color/constants.d.ts +9 -0
  140. package/types/color/get.d.cts +23 -0
  141. package/types/color/get.d.ts +5 -0
  142. package/types/{color.d.ts → color/index.d.ts} +3 -26
  143. package/types/color/is.d.cts +53 -0
  144. package/types/color/is.d.ts +18 -0
  145. package/types/color/misc.d.cts +8 -0
  146. package/types/color/misc.d.ts +4 -0
  147. package/types/color/models.d.cts +20 -0
  148. package/types/color/models.d.ts +16 -0
  149. package/types/color/value.d.cts +32 -0
  150. package/types/color/value.d.ts +19 -0
  151. package/types/function.d.cts +14 -17
  152. package/types/function.d.ts +7 -13
  153. package/types/index.d.cts +201 -157
  154. package/types/index.d.ts +1 -1
  155. package/types/internal/array/callbacks.d.cts +1 -1
  156. package/types/internal/array/callbacks.d.ts +6 -1
  157. package/types/internal/array/find.d.ts +3 -1
  158. package/types/internal/array/group.d.cts +9 -0
  159. package/types/internal/array/group.d.ts +2 -0
  160. package/types/internal/array/insert.d.cts +5 -0
  161. package/types/internal/array/insert.d.ts +1 -0
  162. package/types/internal/function.d.cts +12 -0
  163. package/types/internal/function.d.ts +8 -0
  164. package/types/internal/is.d.cts +37 -0
  165. package/types/internal/is.d.ts +21 -0
  166. package/types/internal/math/aggregate.d.cts +19 -0
  167. package/types/internal/math/aggregate.d.ts +16 -0
  168. package/types/internal/number.d.cts +20 -0
  169. package/types/internal/number.d.ts +16 -0
  170. package/types/internal/random.d.cts +12 -0
  171. package/types/internal/random.d.ts +8 -0
  172. package/types/internal/string.d.cts +19 -0
  173. package/types/internal/string.d.ts +15 -0
  174. package/types/{value → internal/value}/get.d.cts +9 -3
  175. package/types/{value → internal/value}/get.d.ts +1 -1
  176. package/types/internal/value/{handle.d.cts → misc.d.cts} +4 -0
  177. package/types/internal/value/{handle.d.ts → misc.d.ts} +1 -0
  178. package/types/{value → internal/value}/set.d.cts +9 -3
  179. package/types/{value → internal/value}/set.d.ts +1 -1
  180. package/types/is.d.cts +25 -13
  181. package/types/is.d.ts +2 -18
  182. package/types/math.d.cts +15 -12
  183. package/types/math.d.ts +2 -16
  184. package/types/models.d.cts +20 -5
  185. package/types/models.d.ts +14 -2
  186. package/types/number.d.cts +2 -1
  187. package/types/number.d.ts +1 -15
  188. package/types/query.d.cts +3 -0
  189. package/types/random.d.cts +8 -8
  190. package/types/random.d.ts +1 -8
  191. package/types/sized.d.cts +8 -10
  192. package/types/sized.d.ts +8 -10
  193. package/types/string/index.d.cts +15 -12
  194. package/types/string/index.d.ts +1 -0
  195. package/types/string/misc.d.cts +0 -12
  196. package/types/string/misc.d.ts +0 -12
  197. package/types/string/template.d.cts +3 -0
  198. package/types/value/index.d.cts +59 -42
  199. package/types/value/index.d.ts +5 -9
  200. package/types/value/merge.d.cts +13 -2
  201. package/types/value/merge.d.ts +8 -3
  202. package/types/value/partial.d.cts +12 -0
  203. package/types/value/partial.d.ts +5 -0
  204. package/types/value/smush.d.cts +9 -3
  205. package/types/value/unsmush.d.cts +3 -0
  206. package/dist/atoms.full.js +0 -2745
  207. package/dist/attoms.full.js +0 -2840
  208. package/dist/color.cjs +0 -276
  209. package/dist/color.js +0 -263
  210. package/dist/internal/string/key.cjs +0 -10
  211. package/dist/internal/string/key.js +0 -6
  212. package/dist/internal/value/handle.cjs +0 -26
  213. package/dist/internal/value/handle.js +0 -22
  214. package/dist/internal/value/paths.cjs +0 -11
  215. package/dist/internal/value/paths.js +0 -7
  216. package/types/internal/string/key.d.cts +0 -5
  217. package/types/internal/string/key.d.ts +0 -1
  218. package/types/internal/value/paths.d.cts +0 -5
  219. package/types/internal/value/paths.d.ts +0 -1
  220. package/dist/{array → internal/array}/chunk.cjs +0 -0
  221. package/dist/{array → internal/array}/chunk.js +0 -0
  222. package/dist/{array → internal/array}/compact.cjs +0 -0
  223. package/dist/{array → internal/array}/compact.js +0 -0
  224. package/dist/{value → internal/value}/equal.js +0 -0
  225. package/types/{color.d.cts → color/index.d.cts} +16 -16
  226. /package/types/{array → internal/array}/chunk.d.cts +0 -0
  227. /package/types/{array → internal/array}/chunk.d.ts +0 -0
  228. /package/types/{array → internal/array}/compact.d.cts +0 -0
  229. /package/types/{array → internal/array}/compact.d.ts +0 -0
  230. /package/types/{array → internal/array}/shuffle.d.cts +0 -0
  231. /package/types/{array → internal/array}/shuffle.d.ts +0 -0
  232. /package/types/{value → internal/value}/compare.d.cts +0 -0
  233. /package/types/{value → internal/value}/compare.d.ts +0 -0
  234. /package/types/{value → internal/value}/equal.d.cts +0 -0
  235. /package/types/{value → internal/value}/equal.d.ts +0 -0
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ function flatten(array) {
6
+ return Array.isArray(array) ? array.flat(Number.POSITIVE_INFINITY) : [];
7
+ }
8
+
9
+ exports.flatten = flatten;
@@ -0,0 +1,5 @@
1
+ function flatten(array) {
2
+ return Array.isArray(array) ? array.flat(Number.POSITIVE_INFINITY) : [];
3
+ }
4
+
5
+ export { flatten };
@@ -2,40 +2,15 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const internal_array_callbacks = require('../internal/array/callbacks.cjs');
5
+ const internal_array_group = require('../internal/array/group.cjs');
6
6
 
7
7
  function groupBy(array, key, valueOrArrays, arrays) {
8
- return groupValues(
8
+ return internal_array_group.groupValues(
9
9
  array,
10
10
  key,
11
11
  valueOrArrays,
12
12
  key === true || valueOrArrays === true || arrays === true
13
13
  );
14
14
  }
15
- function groupValues(array, key, value, arrays) {
16
- if (!Array.isArray(array) || array.length === 0) {
17
- return {};
18
- }
19
- const callbacks = internal_array_callbacks.getCallbacks(void 0, key, value);
20
- const record = {};
21
- const { length } = array;
22
- for (let index = 0; index < length; index += 1) {
23
- const item = array[index];
24
- const keyed = callbacks?.key?.(item, index, array) ?? index;
25
- const valued = callbacks?.value?.(item, index, array) ?? item;
26
- if (arrays) {
27
- const existing = record[keyed];
28
- if (existing == null) {
29
- record[keyed] = [valued];
30
- } else {
31
- existing.push(valued);
32
- }
33
- } else {
34
- record[keyed] = valued;
35
- }
36
- }
37
- return record;
38
- }
39
15
 
40
16
  exports.groupBy = groupBy;
41
- exports.groupValues = groupValues;
@@ -1,4 +1,4 @@
1
- import { getCallbacks } from '../internal/array/callbacks.js';
1
+ import { groupValues } from '../internal/array/group.js';
2
2
 
3
3
  function groupBy(array, key, valueOrArrays, arrays) {
4
4
  return groupValues(
@@ -8,29 +8,5 @@ function groupBy(array, key, valueOrArrays, arrays) {
8
8
  key === true || valueOrArrays === true || arrays === true
9
9
  );
10
10
  }
11
- function groupValues(array, key, value, arrays) {
12
- if (!Array.isArray(array) || array.length === 0) {
13
- return {};
14
- }
15
- const callbacks = getCallbacks(void 0, key, value);
16
- const record = {};
17
- const { length } = array;
18
- for (let index = 0; index < length; index += 1) {
19
- const item = array[index];
20
- const keyed = callbacks?.key?.(item, index, array) ?? index;
21
- const valued = callbacks?.value?.(item, index, array) ?? item;
22
- if (arrays) {
23
- const existing = record[keyed];
24
- if (existing == null) {
25
- record[keyed] = [valued];
26
- } else {
27
- existing.push(valued);
28
- }
29
- } else {
30
- record[keyed] = valued;
31
- }
32
- }
33
- return record;
34
- }
35
11
 
36
- export { groupBy, groupValues };
12
+ export { groupBy };
@@ -2,46 +2,40 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const array_insert = require('./insert.cjs');
6
- const array_chunk = require('./chunk.cjs');
7
- const array_compact = require('./compact.cjs');
5
+ const internal_array_chunk = require('../internal/array/chunk.cjs');
6
+ const internal_array_compact = require('../internal/array/compact.cjs');
7
+ const internal_array_shuffle = require('../internal/array/shuffle.cjs');
8
8
  const array_count = require('./count.cjs');
9
9
  const array_exists = require('./exists.cjs');
10
10
  const array_filter = require('./filter.cjs');
11
11
  const array_find = require('./find.cjs');
12
+ const array_flatten = require('./flatten.cjs');
12
13
  const array_groupBy = require('./group-by.cjs');
13
14
  const array_indexOf = require('./index-of.cjs');
14
- const array_shuffle = require('./shuffle.cjs');
15
+ const array_insert = require('./insert.cjs');
16
+ const array_push = require('./push.cjs');
15
17
  const array_sort = require('./sort.cjs');
16
18
  const array_splice = require('./splice.cjs');
17
19
  const array_toMap = require('./to-map.cjs');
18
20
  const array_toRecord = require('./to-record.cjs');
19
21
  const array_unique = require('./unique.cjs');
20
22
 
21
- function flatten(array) {
22
- if (!Array.isArray(array)) {
23
- return [];
24
- }
25
- return array.flat(Number.POSITIVE_INFINITY);
26
- }
27
- function push(array, pushed) {
28
- return array_insert.insertValues("push", array, pushed, array.length, 0);
29
- }
30
23
 
31
- exports.insert = array_insert.insert;
32
- exports.chunk = array_chunk.chunk;
33
- exports.compact = array_compact.compact;
24
+
25
+ exports.chunk = internal_array_chunk.chunk;
26
+ exports.compact = internal_array_compact.compact;
27
+ exports.shuffle = internal_array_shuffle.shuffle;
34
28
  exports.count = array_count.count;
35
29
  exports.exists = array_exists.exists;
36
30
  exports.filter = array_filter.filter;
37
31
  exports.find = array_find.find;
32
+ exports.flatten = array_flatten.flatten;
38
33
  exports.groupBy = array_groupBy.groupBy;
39
34
  exports.indexOf = array_indexOf.indexOf;
40
- exports.shuffle = array_shuffle.shuffle;
35
+ exports.insert = array_insert.insert;
36
+ exports.push = array_push.push;
41
37
  exports.sort = array_sort.sort;
42
38
  exports.splice = array_splice.splice;
43
39
  exports.toMap = array_toMap.toMap;
44
40
  exports.toRecord = array_toRecord.toRecord;
45
41
  exports.unique = array_unique.unique;
46
- exports.flatten = flatten;
47
- exports.push = push;
@@ -1,28 +1,17 @@
1
- import { insertValues } from './insert.js';
2
- export { insert } from './insert.js';
3
- export { chunk } from './chunk.js';
4
- export { compact } from './compact.js';
1
+ export { chunk } from '../internal/array/chunk.js';
2
+ export { compact } from '../internal/array/compact.js';
3
+ export { shuffle } from '../internal/array/shuffle.js';
5
4
  export { count } from './count.js';
6
5
  export { exists } from './exists.js';
7
6
  export { filter } from './filter.js';
8
7
  export { find } from './find.js';
8
+ export { flatten } from './flatten.js';
9
9
  export { groupBy } from './group-by.js';
10
10
  export { indexOf } from './index-of.js';
11
- export { shuffle } from './shuffle.js';
11
+ export { insert } from './insert.js';
12
+ export { push } from './push.js';
12
13
  export { sort } from './sort.js';
13
14
  export { splice } from './splice.js';
14
15
  export { toMap } from './to-map.js';
15
16
  export { toRecord } from './to-record.js';
16
17
  export { unique } from './unique.js';
17
-
18
- function flatten(array) {
19
- if (!Array.isArray(array)) {
20
- return [];
21
- }
22
- return array.flat(Number.POSITIVE_INFINITY);
23
- }
24
- function push(array, pushed) {
25
- return insertValues("push", array, pushed, array.length, 0);
26
- }
27
-
28
- export { flatten, push };
@@ -2,10 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const array_chunk = require('./chunk.cjs');
5
+ const internal_array_insert = require('../internal/array/insert.cjs');
6
6
 
7
7
  function insert(array, indexOrItems, items) {
8
- return insertValues(
8
+ return internal_array_insert.insertValues(
9
9
  "insert",
10
10
  array,
11
11
  items == null ? indexOrItems : items,
@@ -13,31 +13,5 @@ function insert(array, indexOrItems, items) {
13
13
  0
14
14
  );
15
15
  }
16
- function insertValues(type, array, items, start, deleteCount) {
17
- const splice = type === "insert" || type === "splice";
18
- if (!Array.isArray(array) || typeof start !== "number") {
19
- return splice ? [] : 0;
20
- }
21
- if (!Array.isArray(items) || items.length === 0) {
22
- return splice ? [] : 0;
23
- }
24
- const actualStart = Math.min(Math.max(0, start), array.length);
25
- const chunked = array_chunk.chunk(items);
26
- const lastIndex = chunked.length - 1;
27
- let index = Number(chunked.length);
28
- let returned;
29
- while (--index >= 0) {
30
- const result = array.splice(
31
- actualStart,
32
- index === lastIndex ? deleteCount < 0 ? 0 : deleteCount : 0,
33
- ...chunked[index]
34
- );
35
- if (returned == null) {
36
- returned = result;
37
- }
38
- }
39
- return type === "insert" ? array : type === "splice" ? returned : array.length;
40
- }
41
16
 
42
17
  exports.insert = insert;
43
- exports.insertValues = insertValues;
@@ -1,4 +1,4 @@
1
- import { chunk } from './chunk.js';
1
+ import { insertValues } from '../internal/array/insert.js';
2
2
 
3
3
  function insert(array, indexOrItems, items) {
4
4
  return insertValues(
@@ -9,30 +9,5 @@ function insert(array, indexOrItems, items) {
9
9
  0
10
10
  );
11
11
  }
12
- function insertValues(type, array, items, start, deleteCount) {
13
- const splice = type === "insert" || type === "splice";
14
- if (!Array.isArray(array) || typeof start !== "number") {
15
- return splice ? [] : 0;
16
- }
17
- if (!Array.isArray(items) || items.length === 0) {
18
- return splice ? [] : 0;
19
- }
20
- const actualStart = Math.min(Math.max(0, start), array.length);
21
- const chunked = chunk(items);
22
- const lastIndex = chunked.length - 1;
23
- let index = Number(chunked.length);
24
- let returned;
25
- while (--index >= 0) {
26
- const result = array.splice(
27
- actualStart,
28
- index === lastIndex ? deleteCount < 0 ? 0 : deleteCount : 0,
29
- ...chunked[index]
30
- );
31
- if (returned == null) {
32
- returned = result;
33
- }
34
- }
35
- return type === "insert" ? array : type === "splice" ? returned : array.length;
36
- }
37
12
 
38
- export { insert, insertValues };
13
+ export { insert };
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const internal_array_insert = require('../internal/array/insert.cjs');
6
+
7
+ function push(array, pushed) {
8
+ return internal_array_insert.insertValues("push", array, pushed, array.length, 0);
9
+ }
10
+
11
+ exports.push = push;
@@ -0,0 +1,7 @@
1
+ import { insertValues } from '../internal/array/insert.js';
2
+
3
+ function push(array, pushed) {
4
+ return insertValues("push", array, pushed, array.length, 0);
5
+ }
6
+
7
+ export { push };
@@ -2,9 +2,26 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const is = require('../is.cjs');
6
- const value_compare = require('../value/compare.cjs');
5
+ const internal_value_compare = require('../internal/value/compare.cjs');
6
+ const internal_is = require('../internal/is.cjs');
7
7
 
8
+ function getSorter(value, modifier) {
9
+ const isObject = internal_is.isPlainObject(value);
10
+ const sorter = {
11
+ identifier: "",
12
+ modifier
13
+ };
14
+ sorter.compare = isObject && typeof value.compare === "function" ? value.compare : void 0;
15
+ sorter.key = isObject && typeof value.key === "string" ? value.key : typeof value === "string" ? value : void 0;
16
+ sorter.callback = sorter.key == null ? isObject && typeof value.value === "function" ? value.value : typeof value === "function" ? value : void 0 : void 0;
17
+ if (isObject && typeof value.direction === "string") {
18
+ sorter.modifier = value.direction === "ascending" ? 1 : value.direction === "descending" ? -1 : modifier;
19
+ }
20
+ if (sorter.key != null || sorter.callback != null) {
21
+ sorter.identifier = `${sorter.key ?? sorter.callback}`;
22
+ return sorter;
23
+ }
24
+ }
8
25
  function sort(array, first, second) {
9
26
  if (!Array.isArray(array)) {
10
27
  return [];
@@ -13,55 +30,38 @@ function sort(array, first, second) {
13
30
  return array;
14
31
  }
15
32
  const direction = first === true || second === true ? "desc" : "asc";
16
- const unknownKeys = Array.isArray(first) ? first : [first];
17
- let { length } = unknownKeys;
18
- const keys = [];
19
- for (let index = 0; index < length; index += 1) {
20
- const key = unknownKeys[index];
21
- const keyWithCallback = {
22
- direction,
23
- callback: void 0
24
- };
25
- if (is.isKey(key)) {
26
- keyWithCallback.callback = (value) => value[key];
27
- } else if (typeof key === "function") {
28
- keyWithCallback.callback = key;
29
- } else if (typeof key?.value === "function" || is.isKey(key?.value)) {
30
- keyWithCallback.direction = key?.direction ?? direction;
31
- keyWithCallback.callback = typeof key.value === "function" ? key.value : (value) => value[key.value];
32
- }
33
- if (typeof keyWithCallback.callback === "function") {
34
- const existing = keys.findIndex(
35
- (existing2) => existing2.callback.toString() === keyWithCallback.callback.toString()
36
- );
37
- if (existing > -1) {
38
- keys.splice(existing, 1);
39
- }
40
- keys.push(keyWithCallback);
41
- }
42
- }
43
- length = keys.length;
33
+ const modifier = direction === "asc" ? 1 : -1;
34
+ const sorters = (Array.isArray(first) ? first : [first]).map((item) => getSorter(item, modifier)).filter((sorter) => sorter != null).filter(
35
+ (current, index, sorters2) => sorters2.findIndex((next) => next.identifier === current.identifier) === index
36
+ );
37
+ const { length } = sorters;
44
38
  if (length === 0) {
45
39
  return array.sort(
46
- (first2, second2) => value_compare.compare(first2, second2) * (direction === "asc" ? 1 : -1)
40
+ (first2, second2) => internal_value_compare.compare(first2, second2) * modifier
47
41
  );
48
42
  }
49
43
  if (length === 1) {
50
- return array.sort(
51
- (first2, second2) => value_compare.compare(keys[0].callback(first2), keys[0].callback(second2)) * (keys[0].direction === "asc" ? 1 : -1)
52
- );
44
+ const sorter = sorters[0];
45
+ const { callback, key, modifier: modifier2 } = sorter;
46
+ return array.sort((first2, second2) => {
47
+ const firstValue = key == null ? callback?.(first2) : first2[key];
48
+ const secondValue = key == null ? callback?.(second2) : second2[key];
49
+ return (sorter.compare?.(first2, firstValue, second2, secondValue) ?? internal_value_compare.compare(firstValue, secondValue)) * modifier2;
50
+ });
53
51
  }
54
- const sorted = array.sort((first2, second2) => {
52
+ return array.sort((first2, second2) => {
55
53
  for (let index = 0; index < length; index += 1) {
56
- const { callback, direction: direction2 } = keys[index];
57
- const compared = value_compare.compare(callback(first2), callback(second2)) * (direction2 === "asc" ? 1 : -1);
54
+ const sorter = sorters[index];
55
+ const { callback, key, modifier: modifier2 } = sorter;
56
+ const firstValue = key == null ? callback?.(first2) : first2[key];
57
+ const secondValue = key == null ? callback?.(second2) : second2[key];
58
+ const compared = (sorter.compare?.(first2, firstValue, second2, secondValue) ?? internal_value_compare.compare(firstValue, secondValue)) * modifier2;
58
59
  if (compared !== 0) {
59
60
  return compared;
60
61
  }
61
62
  }
62
63
  return 0;
63
64
  });
64
- return sorted;
65
65
  }
66
66
 
67
67
  exports.sort = sort;
@@ -1,6 +1,23 @@
1
- import { isKey } from '../is.js';
2
- import { compare } from '../value/compare.js';
1
+ import { compare } from '../internal/value/compare.js';
2
+ import { isPlainObject } from '../internal/is.js';
3
3
 
4
+ function getSorter(value, modifier) {
5
+ const isObject = isPlainObject(value);
6
+ const sorter = {
7
+ identifier: "",
8
+ modifier
9
+ };
10
+ sorter.compare = isObject && typeof value.compare === "function" ? value.compare : void 0;
11
+ sorter.key = isObject && typeof value.key === "string" ? value.key : typeof value === "string" ? value : void 0;
12
+ sorter.callback = sorter.key == null ? isObject && typeof value.value === "function" ? value.value : typeof value === "function" ? value : void 0 : void 0;
13
+ if (isObject && typeof value.direction === "string") {
14
+ sorter.modifier = value.direction === "ascending" ? 1 : value.direction === "descending" ? -1 : modifier;
15
+ }
16
+ if (sorter.key != null || sorter.callback != null) {
17
+ sorter.identifier = `${sorter.key ?? sorter.callback}`;
18
+ return sorter;
19
+ }
20
+ }
4
21
  function sort(array, first, second) {
5
22
  if (!Array.isArray(array)) {
6
23
  return [];
@@ -9,55 +26,38 @@ function sort(array, first, second) {
9
26
  return array;
10
27
  }
11
28
  const direction = first === true || second === true ? "desc" : "asc";
12
- const unknownKeys = Array.isArray(first) ? first : [first];
13
- let { length } = unknownKeys;
14
- const keys = [];
15
- for (let index = 0; index < length; index += 1) {
16
- const key = unknownKeys[index];
17
- const keyWithCallback = {
18
- direction,
19
- callback: void 0
20
- };
21
- if (isKey(key)) {
22
- keyWithCallback.callback = (value) => value[key];
23
- } else if (typeof key === "function") {
24
- keyWithCallback.callback = key;
25
- } else if (typeof key?.value === "function" || isKey(key?.value)) {
26
- keyWithCallback.direction = key?.direction ?? direction;
27
- keyWithCallback.callback = typeof key.value === "function" ? key.value : (value) => value[key.value];
28
- }
29
- if (typeof keyWithCallback.callback === "function") {
30
- const existing = keys.findIndex(
31
- (existing2) => existing2.callback.toString() === keyWithCallback.callback.toString()
32
- );
33
- if (existing > -1) {
34
- keys.splice(existing, 1);
35
- }
36
- keys.push(keyWithCallback);
37
- }
38
- }
39
- length = keys.length;
29
+ const modifier = direction === "asc" ? 1 : -1;
30
+ const sorters = (Array.isArray(first) ? first : [first]).map((item) => getSorter(item, modifier)).filter((sorter) => sorter != null).filter(
31
+ (current, index, sorters2) => sorters2.findIndex((next) => next.identifier === current.identifier) === index
32
+ );
33
+ const { length } = sorters;
40
34
  if (length === 0) {
41
35
  return array.sort(
42
- (first2, second2) => compare(first2, second2) * (direction === "asc" ? 1 : -1)
36
+ (first2, second2) => compare(first2, second2) * modifier
43
37
  );
44
38
  }
45
39
  if (length === 1) {
46
- return array.sort(
47
- (first2, second2) => compare(keys[0].callback(first2), keys[0].callback(second2)) * (keys[0].direction === "asc" ? 1 : -1)
48
- );
40
+ const sorter = sorters[0];
41
+ const { callback, key, modifier: modifier2 } = sorter;
42
+ return array.sort((first2, second2) => {
43
+ const firstValue = key == null ? callback?.(first2) : first2[key];
44
+ const secondValue = key == null ? callback?.(second2) : second2[key];
45
+ return (sorter.compare?.(first2, firstValue, second2, secondValue) ?? compare(firstValue, secondValue)) * modifier2;
46
+ });
49
47
  }
50
- const sorted = array.sort((first2, second2) => {
48
+ return array.sort((first2, second2) => {
51
49
  for (let index = 0; index < length; index += 1) {
52
- const { callback, direction: direction2 } = keys[index];
53
- const compared = compare(callback(first2), callback(second2)) * (direction2 === "asc" ? 1 : -1);
50
+ const sorter = sorters[index];
51
+ const { callback, key, modifier: modifier2 } = sorter;
52
+ const firstValue = key == null ? callback?.(first2) : first2[key];
53
+ const secondValue = key == null ? callback?.(second2) : second2[key];
54
+ const compared = (sorter.compare?.(first2, firstValue, second2, secondValue) ?? compare(firstValue, secondValue)) * modifier2;
54
55
  if (compared !== 0) {
55
56
  return compared;
56
57
  }
57
58
  }
58
59
  return 0;
59
60
  });
60
- return sorted;
61
61
  }
62
62
 
63
63
  export { sort };
@@ -2,10 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const array_insert = require('./insert.cjs');
5
+ const internal_array_insert = require('../internal/array/insert.cjs');
6
6
 
7
7
  function splice(array, start, deleteCountOrItems, items) {
8
- return array_insert.insertValues(
8
+ return internal_array_insert.insertValues(
9
9
  "splice",
10
10
  array,
11
11
  typeof deleteCountOrItems === "number" ? items : deleteCountOrItems,
@@ -1,4 +1,4 @@
1
- import { insertValues } from './insert.js';
1
+ import { insertValues } from '../internal/array/insert.js';
2
2
 
3
3
  function splice(array, start, deleteCountOrItems, items) {
4
4
  return insertValues(
@@ -14,7 +14,7 @@ function toMap(array, keyOrArrays, valueOrArrays, arrays) {
14
14
  const { length } = array;
15
15
  for (let index = 0; index < length; index += 1) {
16
16
  const item = array[index];
17
- const key = callbacks?.key?.(item, index, array) ?? index;
17
+ const key = callbacks?.keyed?.(item, index, array) ?? index;
18
18
  const value = callbacks?.value?.(item, index, array) ?? item;
19
19
  if (asArrays) {
20
20
  const existing = map.get(key);
@@ -10,7 +10,7 @@ function toMap(array, keyOrArrays, valueOrArrays, arrays) {
10
10
  const { length } = array;
11
11
  for (let index = 0; index < length; index += 1) {
12
12
  const item = array[index];
13
- const key = callbacks?.key?.(item, index, array) ?? index;
13
+ const key = callbacks?.keyed?.(item, index, array) ?? index;
14
14
  const value = callbacks?.value?.(item, index, array) ?? item;
15
15
  if (asArrays) {
16
16
  const existing = map.get(key);
@@ -2,10 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const array_groupBy = require('./group-by.cjs');
5
+ const internal_array_group = require('../internal/array/group.cjs');
6
6
 
7
7
  function toRecord(array, key, valueOrArrays, arrays) {
8
- return array_groupBy.groupValues(
8
+ return internal_array_group.groupValues(
9
9
  array,
10
10
  key,
11
11
  valueOrArrays,
@@ -1,4 +1,4 @@
1
- import { groupValues } from './group-by.js';
1
+ import { groupValues } from '../internal/array/group.js';
2
2
 
3
3
  function toRecord(array, key, valueOrArrays, arrays) {
4
4
  return groupValues(
@@ -8,10 +8,7 @@ function unique(array, key) {
8
8
  if (!Array.isArray(array)) {
9
9
  return [];
10
10
  }
11
- if (array.length < 2) {
12
- return array;
13
- }
14
- return internal_array_find.findValues("unique", array, [key, void 0]);
11
+ return array.length > 1 ? internal_array_find.findValues("unique", array, [key, void 0]) : array;
15
12
  }
16
13
 
17
14
  exports.unique = unique;
@@ -4,10 +4,7 @@ function unique(array, key) {
4
4
  if (!Array.isArray(array)) {
5
5
  return [];
6
6
  }
7
- if (array.length < 2) {
8
- return array;
9
- }
10
- return findValues("unique", array, [key, void 0]);
7
+ return array.length > 1 ? findValues("unique", array, [key, void 0]) : array;
11
8
  }
12
9
 
13
10
  export { unique };
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const anyPattern = /^#?([a-f0-9]{3}){1,2}$/i;
6
+ const defaultHex = "000000";
7
+ const defaultHsl = {
8
+ hue: 0,
9
+ lightness: 0,
10
+ saturation: 0
11
+ };
12
+ const defaultRgb = {
13
+ blue: 0,
14
+ green: 0,
15
+ red: 0
16
+ };
17
+ const groupedPattern = /^#?([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i;
18
+ const hslKeys = /* @__PURE__ */ new Set([
19
+ "hue",
20
+ "lightness",
21
+ "saturation"
22
+ ]);
23
+ const prefixPattern = /^#/;
24
+ const rgbKeys = /* @__PURE__ */ new Set(["blue", "green", "red"]);
25
+
26
+ exports.anyPattern = anyPattern;
27
+ exports.defaultHex = defaultHex;
28
+ exports.defaultHsl = defaultHsl;
29
+ exports.defaultRgb = defaultRgb;
30
+ exports.groupedPattern = groupedPattern;
31
+ exports.hslKeys = hslKeys;
32
+ exports.prefixPattern = prefixPattern;
33
+ exports.rgbKeys = rgbKeys;
@@ -0,0 +1,22 @@
1
+ const anyPattern = /^#?([a-f0-9]{3}){1,2}$/i;
2
+ const defaultHex = "000000";
3
+ const defaultHsl = {
4
+ hue: 0,
5
+ lightness: 0,
6
+ saturation: 0
7
+ };
8
+ const defaultRgb = {
9
+ blue: 0,
10
+ green: 0,
11
+ red: 0
12
+ };
13
+ const groupedPattern = /^#?([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i;
14
+ const hslKeys = /* @__PURE__ */ new Set([
15
+ "hue",
16
+ "lightness",
17
+ "saturation"
18
+ ]);
19
+ const prefixPattern = /^#/;
20
+ const rgbKeys = /* @__PURE__ */ new Set(["blue", "green", "red"]);
21
+
22
+ export { anyPattern, defaultHex, defaultHsl, defaultRgb, groupedPattern, hslKeys, prefixPattern, rgbKeys };