@oscarpalmer/atoms 0.158.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 (120) 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 +223 -162
  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 +5 -4
  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 +3 -1
  77. package/dist/promise/helpers.js +8 -1
  78. package/dist/promise/index.js +9 -3
  79. package/dist/promise/misc.js +3 -1
  80. package/dist/promise/models.js +14 -12
  81. package/dist/promise/timed.js +3 -1
  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 +5 -3
  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/promise/helpers.ts +13 -3
  109. package/src/promise/index.ts +89 -19
  110. package/src/promise/misc.ts +1 -4
  111. package/src/promise/models.ts +18 -12
  112. package/src/value/clone.ts +1 -1
  113. package/src/value/smush.ts +1 -1
  114. package/src/value/unsmush.ts +1 -1
  115. package/types/array/index.d.ts +1 -0
  116. package/types/array/position.d.ts +117 -0
  117. package/types/promise/helpers.d.ts +3 -1
  118. package/types/promise/index.d.ts +52 -5
  119. package/types/promise/misc.d.ts +1 -1
  120. package/types/promise/models.d.ts +15 -11
@@ -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 };