@oscarpalmer/atoms 0.159.0 → 0.160.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 (112) hide show
  1. package/dist/array/difference.js +2 -0
  2. package/dist/array/exists.js +2 -0
  3. package/dist/array/filter.js +2 -0
  4. package/dist/array/find.js +2 -0
  5. package/dist/array/flatten.js +2 -0
  6. package/dist/array/from.js +2 -0
  7. package/dist/array/get.js +2 -0
  8. package/dist/array/group-by.js +2 -0
  9. package/dist/array/index-of.js +2 -0
  10. package/dist/array/index.js +2 -1
  11. package/dist/array/insert.js +2 -0
  12. package/dist/array/intersection.js +2 -0
  13. package/dist/array/partition.js +2 -0
  14. package/dist/array/position.js +58 -0
  15. package/dist/array/push.js +2 -0
  16. package/dist/array/select.js +2 -0
  17. package/dist/array/slice.js +2 -0
  18. package/dist/array/sort.js +2 -0
  19. package/dist/array/splice.js +2 -0
  20. package/dist/array/to-map.js +2 -0
  21. package/dist/array/to-record.js +2 -0
  22. package/dist/array/to-set.js +2 -0
  23. package/dist/array/toggle.js +2 -0
  24. package/dist/array/union.js +2 -0
  25. package/dist/array/unique.js +2 -0
  26. package/dist/array/update.js +2 -0
  27. package/dist/atoms.full.js +62 -8
  28. package/dist/beacon.js +2 -0
  29. package/dist/color/constants.js +35 -33
  30. package/dist/color/index.js +2 -0
  31. package/dist/color/instance.js +2 -0
  32. package/dist/color/misc/alpha.js +2 -0
  33. package/dist/color/misc/get.js +2 -0
  34. package/dist/color/misc/index.js +2 -0
  35. package/dist/color/misc/is.js +2 -0
  36. package/dist/color/misc/state.js +2 -0
  37. package/dist/color/space/hex.js +2 -0
  38. package/dist/color/space/hsl.js +2 -0
  39. package/dist/color/space/rgb.js +2 -0
  40. package/dist/function/assert.js +2 -0
  41. package/dist/function/index.js +2 -0
  42. package/dist/function/memoize.js +2 -0
  43. package/dist/function/once.js +2 -0
  44. package/dist/function/retry.js +2 -0
  45. package/dist/function/work.js +2 -0
  46. package/dist/index.js +2 -1
  47. package/dist/internal/array/callbacks.js +2 -0
  48. package/dist/internal/array/chunk.js +2 -0
  49. package/dist/internal/array/compact.js +2 -0
  50. package/dist/internal/array/find.js +6 -4
  51. package/dist/internal/array/group.js +2 -0
  52. package/dist/internal/array/insert.js +2 -0
  53. package/dist/internal/array/sets.js +8 -6
  54. package/dist/internal/array/shuffle.js +3 -1
  55. package/dist/internal/array/update.js +2 -0
  56. package/dist/internal/function/misc.js +2 -0
  57. package/dist/internal/function/timer.js +5 -3
  58. package/dist/internal/is.js +2 -0
  59. package/dist/internal/math/aggregate.js +2 -0
  60. package/dist/internal/number.js +2 -0
  61. package/dist/internal/random.js +2 -0
  62. package/dist/internal/result.js +2 -0
  63. package/dist/internal/sized.js +2 -0
  64. package/dist/internal/string.js +2 -0
  65. package/dist/internal/value/compare.js +2 -0
  66. package/dist/internal/value/equal.js +2 -0
  67. package/dist/internal/value/get.js +2 -0
  68. package/dist/internal/value/handlers.js +2 -0
  69. package/dist/internal/value/has.js +2 -0
  70. package/dist/internal/value/misc.js +2 -0
  71. package/dist/internal/value/partial.js +2 -0
  72. package/dist/internal/value/set.js +2 -0
  73. package/dist/is.js +2 -0
  74. package/dist/logger.js +2 -0
  75. package/dist/math.js +2 -0
  76. package/dist/promise/delay.js +2 -0
  77. package/dist/promise/helpers.js +2 -0
  78. package/dist/promise/index.js +2 -0
  79. package/dist/promise/misc.js +2 -0
  80. package/dist/promise/models.js +14 -12
  81. package/dist/promise/timed.js +2 -0
  82. package/dist/query.js +2 -0
  83. package/dist/queue.js +2 -0
  84. package/dist/random.js +2 -0
  85. package/dist/result/index.js +2 -0
  86. package/dist/result/match.js +2 -0
  87. package/dist/result/misc.js +2 -0
  88. package/dist/result/work/flow.js +2 -0
  89. package/dist/result/work/pipe.js +2 -0
  90. package/dist/sized/map.js +2 -0
  91. package/dist/sized/set.js +2 -0
  92. package/dist/string/case.js +2 -0
  93. package/dist/string/index.js +2 -0
  94. package/dist/string/match.js +2 -0
  95. package/dist/string/template.js +2 -0
  96. package/dist/value/clone.js +3 -1
  97. package/dist/value/diff.js +2 -0
  98. package/dist/value/merge.js +2 -0
  99. package/dist/value/omit.js +2 -0
  100. package/dist/value/pick.js +2 -0
  101. package/dist/value/smush.js +3 -1
  102. package/dist/value/unsmush.js +3 -1
  103. package/package.json +3 -3
  104. package/src/array/index.ts +1 -0
  105. package/src/array/position.ts +303 -0
  106. package/src/internal/array/sets.ts +3 -3
  107. package/src/internal/array/shuffle.ts +1 -1
  108. package/src/value/clone.ts +1 -1
  109. package/src/value/smush.ts +1 -1
  110. package/src/value/unsmush.ts +1 -1
  111. package/types/array/index.d.ts +1 -0
  112. package/types/array/position.d.ts +117 -0
@@ -1,5 +1,7 @@
1
1
  import { COMPARE_SETS_DIFFERENCE, compareSets } from "../internal/array/sets.js";
2
+ //#region src/array/difference.ts
2
3
  function difference(first, second, key) {
3
4
  return compareSets(COMPARE_SETS_DIFFERENCE, first, second, key);
4
5
  }
6
+ //#endregion
5
7
  export { difference };
@@ -1,6 +1,8 @@
1
1
  import { FIND_VALUE_INDEX, findValue } from "../internal/array/find.js";
2
+ //#region src/array/exists.ts
2
3
  function exists(array, ...parameters) {
3
4
  if (parameters.length === 1 && typeof parameters[0] !== "function") return Array.isArray(array) ? array.includes(parameters[0]) : false;
4
5
  return findValue(FIND_VALUE_INDEX, array, parameters) > -1;
5
6
  }
7
+ //#endregion
6
8
  export { exists };
@@ -1,4 +1,5 @@
1
1
  import { findValues } from "../internal/array/find.js";
2
+ //#region src/array/filter.ts
2
3
  function filter(array, ...parameters) {
3
4
  return findValues("all", array, parameters).matched;
4
5
  }
@@ -6,4 +7,5 @@ filter.remove = removeFiltered;
6
7
  function removeFiltered(array, ...parameters) {
7
8
  return findValues("all", array, parameters).notMatched;
8
9
  }
10
+ //#endregion
9
11
  export { filter };
@@ -1,5 +1,7 @@
1
1
  import { FIND_VALUE_VALUE, findValue } from "../internal/array/find.js";
2
+ //#region src/array/find.ts
2
3
  function find(array, ...parameters) {
3
4
  return findValue(FIND_VALUE_VALUE, array, parameters);
4
5
  }
6
+ //#endregion
5
7
  export { find };
@@ -1,3 +1,4 @@
1
+ //#region src/array/flatten.ts
1
2
  /**
2
3
  * Flatten an array _(using native `flat` and maximum depth)_
3
4
  * @param array Array to flatten
@@ -6,4 +7,5 @@
6
7
  function flatten(array) {
7
8
  return Array.isArray(array) ? array.flat(Number.POSITIVE_INFINITY) : [];
8
9
  }
10
+ //#endregion
9
11
  export { flatten };
@@ -1,3 +1,4 @@
1
+ //#region src/array/from.ts
1
2
  function range(first, second, third) {
2
3
  const start = typeof second === "number" ? first : 0;
3
4
  const end = typeof second === "number" ? second : first;
@@ -15,4 +16,5 @@ function times(length, value) {
15
16
  for (let index = 0; index < length; index += 1) values.push(isFunction ? value(index) : value ?? index);
16
17
  return values;
17
18
  }
19
+ //#endregion
18
20
  export { range, times };
package/dist/array/get.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { isPlainObject } from "../internal/is.js";
2
+ //#region src/array/get.ts
2
3
  function getArray(value, indiced) {
3
4
  if (Array.isArray(value)) return value;
4
5
  if (value instanceof Map || value instanceof Set) return [...value.values()];
@@ -13,4 +14,5 @@ function getArray(value, indiced) {
13
14
  }
14
15
  return array;
15
16
  }
17
+ //#endregion
16
18
  export { getArray };
@@ -1,4 +1,5 @@
1
1
  import { groupValues } from "../internal/array/group.js";
2
+ //#region src/array/group-by.ts
2
3
  function groupBy(array, first, second) {
3
4
  return groupValues(array, first, second, false);
4
5
  }
@@ -6,4 +7,5 @@ groupBy.arrays = groupArraysBy;
6
7
  function groupArraysBy(array, first, second) {
7
8
  return groupValues(array, first, second, true);
8
9
  }
10
+ //#endregion
9
11
  export { groupBy };
@@ -1,5 +1,7 @@
1
1
  import { FIND_VALUE_INDEX, findValue } from "../internal/array/find.js";
2
+ //#region src/array/index-of.ts
2
3
  function indexOf(array, ...parameters) {
3
4
  return findValue(FIND_VALUE_INDEX, array, parameters);
4
5
  }
6
+ //#endregion
5
7
  export { indexOf };
@@ -12,6 +12,7 @@ import { shuffle } from "../internal/array/shuffle.js";
12
12
  import { insert } from "./insert.js";
13
13
  import { intersection } from "./intersection.js";
14
14
  import { partition } from "./partition.js";
15
+ import { endsWithArray, getArrayPosition, includesArray, indexOfArray, startsWithArray } from "./position.js";
15
16
  import { push } from "./push.js";
16
17
  import { select } from "./select.js";
17
18
  import { drop, slice, take } from "./slice.js";
@@ -21,4 +22,4 @@ import { toSet } from "./to-set.js";
21
22
  import { toggle } from "./toggle.js";
22
23
  import { union } from "./union.js";
23
24
  import { update } from "./update.js";
24
- export { chunk, compact, difference, drop, exists, filter, find, flatten, getArray, indexOf, insert, intersection, partition, push, range, select, shuffle, slice, sort, splice, take, times, toSet, toggle, union, update };
25
+ export { chunk, compact, difference, drop, endsWithArray, exists, filter, find, flatten, getArray, getArrayPosition, includesArray, indexOf, indexOfArray, insert, intersection, partition, push, range, select, shuffle, slice, sort, splice, startsWithArray, take, times, toSet, toggle, union, update };
@@ -1,5 +1,7 @@
1
1
  import { insertValues } from "../internal/array/insert.js";
2
+ //#region src/array/insert.ts
2
3
  function insert(array, indexOrItems, items) {
3
4
  return insertValues("insert", array, items == null ? indexOrItems : items, typeof indexOrItems === "number" ? indexOrItems : array?.length, 0);
4
5
  }
6
+ //#endregion
5
7
  export { insert };
@@ -1,5 +1,7 @@
1
1
  import { COMPARE_SETS_INTERSECTION, compareSets } from "../internal/array/sets.js";
2
+ //#region src/array/intersection.ts
2
3
  function intersection(first, second, key) {
3
4
  return compareSets(COMPARE_SETS_INTERSECTION, first, second, key);
4
5
  }
6
+ //#endregion
5
7
  export { intersection };
@@ -1,6 +1,8 @@
1
1
  import { findValues } from "../internal/array/find.js";
2
+ //#region src/array/partition.ts
2
3
  function partition(array, ...parameters) {
3
4
  const { matched, notMatched } = findValues("all", array, parameters);
4
5
  return [matched, notMatched];
5
6
  }
7
+ //#endregion
6
8
  export { partition };
@@ -0,0 +1,58 @@
1
+ import { getArrayCallback } from "../internal/array/callbacks.js";
2
+ //#region src/array/position.ts
3
+ function endsWithArray(haystack, needle, key) {
4
+ return endings.has(getPosition(haystack, needle, key)[1]);
5
+ }
6
+ function getArrayPosition(haystack, needle, key) {
7
+ return getPosition(haystack, needle, key)[1];
8
+ }
9
+ function getName(start, haystack, needle) {
10
+ if (start === 0) return haystack === needle ? POSITION_SAME : POSITION_START;
11
+ return start + needle === haystack ? POSITION_END : POSITION_INSIDE;
12
+ }
13
+ function getPosition(haystack, needle, key) {
14
+ if (!Array.isArray(haystack) || !Array.isArray(needle)) return invalid;
15
+ const haystackLength = haystack.length;
16
+ const needleLength = needle.length;
17
+ if (haystackLength === 0 || needleLength === 0) return outside;
18
+ if (needleLength > haystackLength) return outside;
19
+ const callback = getArrayCallback(key);
20
+ const limit = haystackLength - needleLength + 1;
21
+ let needleValues = callback == null ? needle : needle.slice();
22
+ if (callback != null) for (let needleIndex = 0; needleIndex < needleLength; needleIndex += 1) needleValues[needleIndex] = callback(needle[needleIndex], needleIndex, needle);
23
+ for (let haystackIndex = 0; haystackIndex < limit; haystackIndex += 1) {
24
+ let haystackItem = haystack[haystackIndex];
25
+ let haystackValue = callback?.(haystackItem, haystackIndex, haystack) ?? haystackItem;
26
+ if (!Object.is(haystackValue, needleValues[0])) continue;
27
+ if (needleLength === 1) return [haystackIndex, getName(haystackIndex, haystackLength, needleLength)];
28
+ for (let needleIndex = 1; needleIndex < needleLength; needleIndex += 1) {
29
+ haystackItem = haystack[haystackIndex + needleIndex];
30
+ haystackValue = callback?.(haystackItem, haystackIndex + needleIndex, haystack) ?? haystackItem;
31
+ if (!Object.is(haystackValue, needleValues[needleIndex])) break;
32
+ if (needleIndex === needleLength - 1) return [haystackIndex, getName(haystackIndex, haystackLength, needleLength)];
33
+ }
34
+ }
35
+ return outside;
36
+ }
37
+ function includesArray(haystack, needle, key) {
38
+ return !outsides.has(getPosition(haystack, needle, key)[1]);
39
+ }
40
+ function indexOfArray(haystack, needle, key) {
41
+ return getPosition(haystack, needle, key)[0];
42
+ }
43
+ function startsWithArray(haystack, needle, key) {
44
+ return starts.has(getPosition(haystack, needle, key)[1]);
45
+ }
46
+ var POSITION_END = "end";
47
+ var POSITION_INSIDE = "inside";
48
+ var POSITION_INVALID = "invalid";
49
+ var POSITION_OUTSIDE = "outside";
50
+ var POSITION_SAME = "same";
51
+ var POSITION_START = "start";
52
+ var endings = new Set([POSITION_END, POSITION_SAME]);
53
+ var invalid = [-1, POSITION_INVALID];
54
+ var outside = [-1, POSITION_OUTSIDE];
55
+ var outsides = new Set([POSITION_INVALID, POSITION_OUTSIDE]);
56
+ var starts = new Set([POSITION_START, POSITION_SAME]);
57
+ //#endregion
58
+ export { endsWithArray, getArrayPosition, includesArray, indexOfArray, startsWithArray };
@@ -1,4 +1,5 @@
1
1
  import { insertValues } from "../internal/array/insert.js";
2
+ //#region src/array/push.ts
2
3
  /**
3
4
  * Push items into an array _(at the end)_
4
5
  * @param array Original array
@@ -8,4 +9,5 @@ import { insertValues } from "../internal/array/insert.js";
8
9
  function push(array, pushed) {
9
10
  return insertValues("push", array, pushed, array.length, 0);
10
11
  }
12
+ //#endregion
11
13
  export { push };
@@ -1,5 +1,7 @@
1
1
  import { findValues } from "../internal/array/find.js";
2
+ //#region src/array/select.ts
2
3
  function select(array, ...parameters) {
3
4
  return findValues("all", array, parameters, parameters.pop()).matched;
4
5
  }
6
+ //#endregion
5
7
  export { select };
@@ -1,4 +1,5 @@
1
1
  import { getArrayCallbacks } from "../internal/array/callbacks.js";
2
+ //#region src/array/slice.ts
2
3
  function drop(array, first, second) {
3
4
  return extract(EXTRACT_DROP, array, first, second);
4
5
  }
@@ -48,4 +49,5 @@ function take(array, first, second) {
48
49
  }
49
50
  var EXTRACT_DROP = "drop";
50
51
  var EXTRACT_TAKE = "take";
52
+ //#endregion
51
53
  export { drop, slice, take };
@@ -1,5 +1,6 @@
1
1
  import { isPlainObject } from "../internal/is.js";
2
2
  import { compare } from "../internal/value/compare.js";
3
+ //#region src/array/sort.ts
3
4
  function getCallback(value, key, forObject) {
4
5
  if (key != null) return;
5
6
  if (forObject && typeof value.value === "function") return value.value;
@@ -57,4 +58,5 @@ function sort(array, first, second) {
57
58
  return 0;
58
59
  });
59
60
  }
61
+ //#endregion
60
62
  export { sort };
@@ -1,5 +1,7 @@
1
1
  import { insertValues } from "../internal/array/insert.js";
2
+ //#region src/array/splice.ts
2
3
  function splice(array, start, deleteCountOrItems, items) {
3
4
  return insertValues("splice", array, typeof deleteCountOrItems === "number" ? items : deleteCountOrItems, start, typeof deleteCountOrItems === "number" ? deleteCountOrItems : 0);
4
5
  }
6
+ //#endregion
5
7
  export { splice };
@@ -1,4 +1,5 @@
1
1
  import { getArrayCallbacks } from "../internal/array/callbacks.js";
2
+ //#region src/array/to-map.ts
2
3
  function getMapValues(array, first, second, arrays) {
3
4
  if (!Array.isArray(array)) return /* @__PURE__ */ new Map();
4
5
  const { length } = array;
@@ -23,4 +24,5 @@ toMap.arrays = toMapArrays;
23
24
  function toMapArrays(array, first, second) {
24
25
  return getMapValues(array, first, second, true);
25
26
  }
27
+ //#endregion
26
28
  export { toMap };
@@ -1,4 +1,5 @@
1
1
  import { groupValues } from "../internal/array/group.js";
2
+ //#region src/array/to-record.ts
2
3
  function toRecord(array, first, second) {
3
4
  return groupValues(array, first, second, false);
4
5
  }
@@ -6,4 +7,5 @@ toRecord.arrays = toRecordArrays;
6
7
  function toRecordArrays(array, first, second) {
7
8
  return groupValues(array, first, second, true);
8
9
  }
10
+ //#endregion
9
11
  export { toRecord };
@@ -1,4 +1,5 @@
1
1
  import { getArrayCallbacks } from "../internal/array/callbacks.js";
2
+ //#region src/array/to-set.ts
2
3
  function toSet(array, value) {
3
4
  if (!Array.isArray(array)) return /* @__PURE__ */ new Set();
4
5
  const callbacks = getArrayCallbacks(void 0, void 0, value);
@@ -8,4 +9,5 @@ function toSet(array, value) {
8
9
  for (let index = 0; index < length; index += 1) set.add(callbacks.value(array[index], index, array));
9
10
  return set;
10
11
  }
12
+ //#endregion
11
13
  export { toSet };
@@ -1,5 +1,7 @@
1
1
  import { updateInArray } from "../internal/array/update.js";
2
+ //#region src/array/toggle.ts
2
3
  function toggle(array, values, key) {
3
4
  return updateInArray(array, values, key, false);
4
5
  }
6
+ //#endregion
5
7
  export { toggle };
@@ -1,5 +1,7 @@
1
1
  import { COMPARE_SETS_UNION, compareSets } from "../internal/array/sets.js";
2
+ //#region src/array/union.ts
2
3
  function union(first, second, key) {
3
4
  return compareSets(COMPARE_SETS_UNION, first, second, key);
4
5
  }
6
+ //#endregion
5
7
  export { union };
@@ -1,6 +1,8 @@
1
1
  import { FIND_VALUES_UNIQUE, findValues } from "../internal/array/find.js";
2
+ //#region src/array/unique.ts
2
3
  function unique(array, key) {
3
4
  if (!Array.isArray(array)) return [];
4
5
  return array.length > 1 ? findValues(FIND_VALUES_UNIQUE, array, [key, void 0]).matched : array;
5
6
  }
7
+ //#endregion
6
8
  export { unique };
@@ -1,5 +1,7 @@
1
1
  import { updateInArray } from "../internal/array/update.js";
2
+ //#region src/array/update.ts
2
3
  function update(array, values, key) {
3
4
  return updateInArray(array, values, key, true);
4
5
  }
6
+ //#endregion
5
7
  export { update };
@@ -175,7 +175,7 @@ function getRandomInteger(minimum, maximum) {
175
175
  */
176
176
  function shuffle(array) {
177
177
  if (!Array.isArray(array)) return [];
178
- const shuffled = [...array];
178
+ const shuffled = array.slice();
179
179
  if (shuffled.length < 2) return shuffled;
180
180
  let index = Number(shuffled.length);
181
181
  while (--index >= 0) {
@@ -189,8 +189,8 @@ function compareSets(type, first, second, key) {
189
189
  const isDifference = type === COMPARE_SETS_DIFFERENCE;
190
190
  const isIntersection = type === COMPARE_SETS_INTERSECTION;
191
191
  const isUnion = type === COMPARE_SETS_UNION;
192
- if (first.length === 0) return isDifference ? [...first] : isIntersection ? [] : [...second];
193
- if (!Array.isArray(second) || second.length === 0) return isIntersection ? [] : [...first];
192
+ if (first.length === 0) return isDifference ? first.slice() : isIntersection ? [] : second.slice();
193
+ if (!Array.isArray(second) || second.length === 0) return isIntersection ? [] : first.slice();
194
194
  const callback = getArrayCallback(key);
195
195
  const values = isUnion ? first : second;
196
196
  let { length } = values;
@@ -201,7 +201,7 @@ function compareSets(type, first, second, key) {
201
201
  }
202
202
  const source = isUnion ? second : first;
203
203
  length = source.length;
204
- const result = isUnion ? [...first] : [];
204
+ const result = isUnion ? first.slice() : [];
205
205
  for (let index = 0; index < length; index += 1) {
206
206
  const item = source[index];
207
207
  const value = callback?.(item, index, source) ?? item;
@@ -368,6 +368,60 @@ function partition(array, ...parameters) {
368
368
  const { matched, notMatched } = findValues("all", array, parameters);
369
369
  return [matched, notMatched];
370
370
  }
371
+ function endsWithArray(haystack, needle, key) {
372
+ return endings.has(getPosition(haystack, needle, key)[1]);
373
+ }
374
+ function getArrayPosition(haystack, needle, key) {
375
+ return getPosition(haystack, needle, key)[1];
376
+ }
377
+ function getName(start, haystack, needle) {
378
+ if (start === 0) return haystack === needle ? POSITION_SAME : POSITION_START;
379
+ return start + needle === haystack ? POSITION_END : POSITION_INSIDE;
380
+ }
381
+ function getPosition(haystack, needle, key) {
382
+ if (!Array.isArray(haystack) || !Array.isArray(needle)) return invalid;
383
+ const haystackLength = haystack.length;
384
+ const needleLength = needle.length;
385
+ if (haystackLength === 0 || needleLength === 0) return outside;
386
+ if (needleLength > haystackLength) return outside;
387
+ const callback = getArrayCallback(key);
388
+ const limit = haystackLength - needleLength + 1;
389
+ let needleValues = callback == null ? needle : needle.slice();
390
+ if (callback != null) for (let needleIndex = 0; needleIndex < needleLength; needleIndex += 1) needleValues[needleIndex] = callback(needle[needleIndex], needleIndex, needle);
391
+ for (let haystackIndex = 0; haystackIndex < limit; haystackIndex += 1) {
392
+ let haystackItem = haystack[haystackIndex];
393
+ let haystackValue = callback?.(haystackItem, haystackIndex, haystack) ?? haystackItem;
394
+ if (!Object.is(haystackValue, needleValues[0])) continue;
395
+ if (needleLength === 1) return [haystackIndex, getName(haystackIndex, haystackLength, needleLength)];
396
+ for (let needleIndex = 1; needleIndex < needleLength; needleIndex += 1) {
397
+ haystackItem = haystack[haystackIndex + needleIndex];
398
+ haystackValue = callback?.(haystackItem, haystackIndex + needleIndex, haystack) ?? haystackItem;
399
+ if (!Object.is(haystackValue, needleValues[needleIndex])) break;
400
+ if (needleIndex === needleLength - 1) return [haystackIndex, getName(haystackIndex, haystackLength, needleLength)];
401
+ }
402
+ }
403
+ return outside;
404
+ }
405
+ function includesArray(haystack, needle, key) {
406
+ return !outsides.has(getPosition(haystack, needle, key)[1]);
407
+ }
408
+ function indexOfArray(haystack, needle, key) {
409
+ return getPosition(haystack, needle, key)[0];
410
+ }
411
+ function startsWithArray(haystack, needle, key) {
412
+ return starts.has(getPosition(haystack, needle, key)[1]);
413
+ }
414
+ const POSITION_END = "end";
415
+ const POSITION_INSIDE = "inside";
416
+ const POSITION_INVALID = "invalid";
417
+ const POSITION_OUTSIDE = "outside";
418
+ const POSITION_SAME = "same";
419
+ const POSITION_START = "start";
420
+ const endings = new Set([POSITION_END, POSITION_SAME]);
421
+ const invalid = [-1, POSITION_INVALID];
422
+ const outside = [-1, POSITION_OUTSIDE];
423
+ const outsides = new Set([POSITION_INVALID, POSITION_OUTSIDE]);
424
+ const starts = new Set([POSITION_START, POSITION_SAME]);
371
425
  /**
372
426
  * Push items into an array _(at the end)_
373
427
  * @param array Original array
@@ -1906,7 +1960,7 @@ function cloneNode(node, depth, references) {
1906
1960
  return cloned;
1907
1961
  }
1908
1962
  function clonePlainObject(value, depth, references) {
1909
- if (depth >= MAX_CLONE_DEPTH) return Array.isArray(value) ? [...value] : { ...value };
1963
+ if (depth >= MAX_CLONE_DEPTH) return Array.isArray(value) ? value.slice() : { ...value };
1910
1964
  const cloned = Array.isArray(value) ? [] : {};
1911
1965
  const keys = [...Object.keys(value), ...Object.getOwnPropertySymbols(value)];
1912
1966
  const { length } = keys;
@@ -2102,7 +2156,7 @@ function flattenObject(value, depth, smushed, prefix) {
2102
2156
  const val = value[key];
2103
2157
  if (isArrayOrPlainObject(val)) {
2104
2158
  const prefixedKey = join([prefix, key], ".");
2105
- flattened[prefixedKey] = Array.isArray(val) ? [...val] : { ...val };
2159
+ flattened[prefixedKey] = Array.isArray(val) ? val.slice() : { ...val };
2106
2160
  const nested = flattenObject(val, depth + 1, smushed, prefixedKey);
2107
2161
  const nestedKeys = Object.keys(nested);
2108
2162
  const nestedLength = nestedKeys.length;
@@ -2151,7 +2205,7 @@ function unsmush(value) {
2151
2205
  const key = keys[index].value;
2152
2206
  const val = value[key];
2153
2207
  let next = val;
2154
- if (isArrayOrPlainObject(val)) next = Array.isArray(val) ? [...val] : { ...val };
2208
+ if (isArrayOrPlainObject(val)) next = Array.isArray(val) ? val.slice() : { ...val };
2155
2209
  setValue(unsmushed, key, next);
2156
2210
  }
2157
2211
  return unsmushed;
@@ -4010,4 +4064,4 @@ var SizedSet = class extends Set {
4010
4064
  }
4011
4065
  }
4012
4066
  };
4013
- export { CancelablePromise, PromiseTimeoutError, QueueError, RetryError, SizedMap, SizedSet, attempt, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, delay, diff, difference, drop, endsWith, equal, error, exists, filter, find, flatten, floor, flow, toResult as fromPromise, toResult, fromQuery, toPromise as fromResult, toPromise, getArray, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getUuid, getValue, groupBy, hasValue, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, includes, indexOf, insert, intersection, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonNullable, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isTypedArray, join, kebabCase, logger, lowerCase, max, median, memoize, merge, min, noop, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, retry, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, shuffle, slice, smush, snakeCase, sort, splice, startsWith, sum, take, template, throttle, timed, times, titleCase, toMap, toQuery, toRecord, toSet, toggle, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
4067
+ export { CancelablePromise, PromiseTimeoutError, QueueError, RetryError, SizedMap, SizedSet, attempt, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, delay, diff, difference, drop, endsWith, endsWithArray, equal, error, exists, filter, find, flatten, floor, flow, toResult as fromPromise, toResult, fromQuery, toPromise as fromResult, toPromise, getArray, getArrayPosition, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getUuid, getValue, groupBy, hasValue, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, includes, includesArray, indexOf, indexOfArray, insert, intersection, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonNullable, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isTypedArray, join, kebabCase, logger, lowerCase, max, median, memoize, merge, min, noop, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, retry, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, shuffle, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, sum, take, template, throttle, timed, times, titleCase, toMap, toQuery, toRecord, toSet, toggle, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
package/dist/beacon.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { isPlainObject } from "./internal/is.js";
2
2
  import { noop } from "./internal/function/misc.js";
3
+ //#region src/beacon.ts
3
4
  var Beacon = class {
4
5
  #options;
5
6
  #state;
@@ -170,4 +171,5 @@ function getObserver(first, second, third) {
170
171
  }
171
172
  var MESSAGE_BEACON = "Cannot retrieve observable from a destroyed beacon";
172
173
  var MESSAGE_OBSERVABLE = "Cannot subscribe to a destroyed observable";
174
+ //#endregion
173
175
  export { beacon };
@@ -1,53 +1,55 @@
1
- const ALPHA_FULL_HEX_SHORT = "f";
2
- const ALPHA_FULL_HEX_LONG = `ff`;
3
- const ALPHA_FULL_VALUE = 1;
4
- const ALPHA_NONE_HEX = "00";
5
- const ALPHA_NONE_VALUE = 0;
6
- const DEFAULT_ALPHA = {
1
+ //#region src/color/constants.ts
2
+ var ALPHA_FULL_HEX_SHORT = "f";
3
+ var ALPHA_FULL_HEX_LONG = `ff`;
4
+ var ALPHA_FULL_VALUE = 1;
5
+ var ALPHA_NONE_HEX = "00";
6
+ var ALPHA_NONE_VALUE = 0;
7
+ var DEFAULT_ALPHA = {
7
8
  hex: ALPHA_FULL_HEX_LONG,
8
9
  value: 1
9
10
  };
10
- const DEFAULT_HSL = {
11
+ var DEFAULT_HSL = {
11
12
  hue: 0,
12
13
  lightness: 0,
13
14
  saturation: 0
14
15
  };
15
- const DEFAULT_RGB = {
16
+ var DEFAULT_RGB = {
16
17
  blue: 0,
17
18
  green: 0,
18
19
  red: 0
19
20
  };
20
- const EXPRESSION_HEX_LONG = /^#?([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})?$/i;
21
- const EXPRESSION_HEX_SHORT = /^#?([a-f0-9]{3,4})$/i;
22
- const EXPRESSION_PREFIX = /^#/;
23
- const HEX_BLACK = "000000";
24
- const HEX_WHITE = "ffffff";
25
- const LENGTH_LONG = 6;
26
- const LENGTH_SHORT = 3;
27
- const KEYS_HSL = [
21
+ var EXPRESSION_HEX_LONG = /^#?([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})?$/i;
22
+ var EXPRESSION_HEX_SHORT = /^#?([a-f0-9]{3,4})$/i;
23
+ var EXPRESSION_PREFIX = /^#/;
24
+ var HEX_BLACK = "000000";
25
+ var HEX_WHITE = "ffffff";
26
+ var LENGTH_LONG = 6;
27
+ var LENGTH_SHORT = 3;
28
+ var KEYS_HSL = [
28
29
  "hue",
29
30
  "saturation",
30
31
  "lightness"
31
32
  ];
32
- const KEYS_HSLA = [...KEYS_HSL, "alpha"];
33
- const KEYS_RGB = [
33
+ var KEYS_HSLA = [...KEYS_HSL, "alpha"];
34
+ var KEYS_RGB = [
34
35
  "red",
35
36
  "green",
36
37
  "blue"
37
38
  ];
38
- const KEYS_RGBA = [...KEYS_RGB, "alpha"];
39
- const MAX_DEGREE = 360;
40
- const MAX_HEX = 255;
41
- const MAX_PERCENT = 100;
42
- const SPACE_HSL = "hsl";
43
- const SPACE_RGB = "rgb";
44
- const SRGB_LUMINANCE_BLUE = .0722;
45
- const SRGB_LUMINANCE_EXPONENT = 2.4;
46
- const SRGB_LUMINANCE_GREEN = .7152;
47
- const SRGB_LUMINANCE_MINIMUM = .03928;
48
- const SRGB_LUMINANCE_MODIFIER = 1.055;
49
- const SRGB_LUMINANCE_MULTIPLIER = 12.92;
50
- const SRGB_LUMINANCE_OFFSET = .055;
51
- const SRGB_LUMINANCE_RED = .2126;
52
- const SRGB_LUMINANCE_THRESHOLD = .625;
39
+ var KEYS_RGBA = [...KEYS_RGB, "alpha"];
40
+ var MAX_DEGREE = 360;
41
+ var MAX_HEX = 255;
42
+ var MAX_PERCENT = 100;
43
+ var SPACE_HSL = "hsl";
44
+ var SPACE_RGB = "rgb";
45
+ var SRGB_LUMINANCE_BLUE = .0722;
46
+ var SRGB_LUMINANCE_EXPONENT = 2.4;
47
+ var SRGB_LUMINANCE_GREEN = .7152;
48
+ var SRGB_LUMINANCE_MINIMUM = .03928;
49
+ var SRGB_LUMINANCE_MODIFIER = 1.055;
50
+ var SRGB_LUMINANCE_MULTIPLIER = 12.92;
51
+ var SRGB_LUMINANCE_OFFSET = .055;
52
+ var SRGB_LUMINANCE_RED = .2126;
53
+ var SRGB_LUMINANCE_THRESHOLD = .625;
54
+ //#endregion
53
55
  export { ALPHA_FULL_HEX_LONG, ALPHA_FULL_HEX_SHORT, ALPHA_FULL_VALUE, ALPHA_NONE_HEX, ALPHA_NONE_VALUE, DEFAULT_ALPHA, DEFAULT_HSL, DEFAULT_RGB, EXPRESSION_HEX_LONG, EXPRESSION_HEX_SHORT, EXPRESSION_PREFIX, HEX_BLACK, HEX_WHITE, KEYS_HSL, KEYS_HSLA, KEYS_RGB, KEYS_RGBA, LENGTH_LONG, LENGTH_SHORT, MAX_DEGREE, MAX_HEX, MAX_PERCENT, SPACE_HSL, SPACE_RGB, SRGB_LUMINANCE_BLUE, SRGB_LUMINANCE_EXPONENT, SRGB_LUMINANCE_GREEN, SRGB_LUMINANCE_MINIMUM, SRGB_LUMINANCE_MODIFIER, SRGB_LUMINANCE_MULTIPLIER, SRGB_LUMINANCE_OFFSET, SRGB_LUMINANCE_RED, SRGB_LUMINANCE_THRESHOLD };
@@ -4,6 +4,7 @@ import { rgbToHex, rgbToHsl, rgbToHsla } from "./space/rgb.js";
4
4
  import { getNormalizedHex, hexToHsl, hexToHsla, hexToRgb, hexToRgba } from "./space/hex.js";
5
5
  import { hslToHex, hslToRgb, hslToRgba } from "./space/hsl.js";
6
6
  import { Color } from "./instance.js";
7
+ //#region src/color/index.ts
7
8
  /**
8
9
  * Get a Color from any kind of value
9
10
  * @param value Original value
@@ -12,4 +13,5 @@ import { Color } from "./instance.js";
12
13
  function getColor(value) {
13
14
  return isColor(value) ? value : new Color(value);
14
15
  }
16
+ //#endregion
15
17
  export { getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getRgbColor, getRgbaColor, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, isColor, isHexColor, isHslColor, isHslLike, isHslaColor, isRgbColor, isRgbLike, isRgbaColor, rgbToHex, rgbToHsl, rgbToHsla };
@@ -1,6 +1,7 @@
1
1
  import { formatColor } from "./misc/index.js";
2
2
  import { getAlpha } from "./misc/alpha.js";
3
3
  import { getState, setHSLColor, setHexColor, setRGBColor } from "./misc/state.js";
4
+ //#region src/color/instance.ts
4
5
  var Color = class {
5
6
  #state;
6
7
  /**
@@ -110,4 +111,5 @@ var Color = class {
110
111
  return this.toHexString();
111
112
  }
112
113
  };
114
+ //#endregion
113
115
  export { Color };
@@ -1,4 +1,5 @@
1
1
  import { ALPHA_FULL_HEX_LONG, DEFAULT_ALPHA } from "../constants.js";
2
+ //#region src/color/misc/alpha.ts
2
3
  function getAlpha(value) {
3
4
  if (typeof value === "number") return getAlphaFromValue(value);
4
5
  if (typeof value === "string" && value !== ALPHA_FULL_HEX_LONG) return {
@@ -24,4 +25,5 @@ function getAlphaValue(original) {
24
25
  if (original < 0) return 0;
25
26
  return original <= 1 ? original : original / 100;
26
27
  }
28
+ //#endregion
27
29
  export { getAlpha, getAlphaHexadecimal, getAlphaValue };
@@ -2,6 +2,7 @@ import { HEX_BLACK, HEX_WHITE, SRGB_LUMINANCE_EXPONENT, SRGB_LUMINANCE_MODIFIER,
2
2
  import { clamp } from "../../internal/number.js";
3
3
  import { getState } from "./state.js";
4
4
  import { Color } from "../instance.js";
5
+ //#region src/color/misc/get.ts
5
6
  function getClampedValue(value, minimum, maximum) {
6
7
  return typeof value === "number" ? clamp(value, minimum, maximum) : minimum;
7
8
  }
@@ -91,4 +92,5 @@ function getRgbaColor(value) {
91
92
  function getRgbColor(value) {
92
93
  return getState(value).rgb;
93
94
  }
95
+ //#endregion
94
96
  export { getDegrees, getForegroundColor, getHexColor, getHexValue, getHexaColor, getHslColor, getHslaColor, getPercentage, getRgbColor, getRgbaColor };
@@ -1,5 +1,6 @@
1
1
  import { join } from "../../internal/string.js";
2
2
  import { KEYS_HSL, KEYS_RGB } from "../constants.js";
3
+ //#region src/color/misc/index.ts
3
4
  function formatColor(space, color, alpha) {
4
5
  const suffix = alpha ? ` / ${color.alpha}` : "";
5
6
  const value = color[space];
@@ -9,4 +10,5 @@ var formattingKeys = {
9
10
  hsl: KEYS_HSL,
10
11
  rgb: KEYS_RGB
11
12
  };
13
+ //#endregion
12
14
  export { formatColor };
@@ -1,5 +1,6 @@
1
1
  import { EXPRESSION_HEX_LONG, EXPRESSION_HEX_SHORT, KEYS_HSL, KEYS_HSLA, KEYS_RGB, KEYS_RGBA } from "../constants.js";
2
2
  import { between } from "../../internal/number.js";
3
+ //#region src/color/misc/is.ts
3
4
  function hasKeys(value, keys) {
4
5
  return typeof value === "object" && value !== null && keys.every((key) => key in value);
5
6
  }
@@ -93,4 +94,5 @@ var validators = {
93
94
  saturation: isPercentage,
94
95
  red: isBytey
95
96
  };
97
+ //#endregion
96
98
  export { isColor, isHexColor, isHslColor, isHslLike, isHslaColor, isRgbColor, isRgbLike, isRgbaColor };