@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.
- package/dist/array/difference.js +2 -0
- package/dist/array/exists.js +2 -0
- package/dist/array/filter.js +2 -0
- package/dist/array/find.js +2 -0
- package/dist/array/flatten.js +2 -0
- package/dist/array/from.js +2 -0
- package/dist/array/get.js +2 -0
- package/dist/array/group-by.js +2 -0
- package/dist/array/index-of.js +2 -0
- package/dist/array/index.js +2 -1
- package/dist/array/insert.js +2 -0
- package/dist/array/intersection.js +2 -0
- package/dist/array/partition.js +2 -0
- package/dist/array/position.js +58 -0
- package/dist/array/push.js +2 -0
- package/dist/array/select.js +2 -0
- package/dist/array/slice.js +2 -0
- package/dist/array/sort.js +2 -0
- package/dist/array/splice.js +2 -0
- package/dist/array/to-map.js +2 -0
- package/dist/array/to-record.js +2 -0
- package/dist/array/to-set.js +2 -0
- package/dist/array/toggle.js +2 -0
- package/dist/array/union.js +2 -0
- package/dist/array/unique.js +2 -0
- package/dist/array/update.js +2 -0
- package/dist/atoms.full.js +223 -162
- package/dist/beacon.js +2 -0
- package/dist/color/constants.js +35 -33
- package/dist/color/index.js +2 -0
- package/dist/color/instance.js +2 -0
- package/dist/color/misc/alpha.js +2 -0
- package/dist/color/misc/get.js +2 -0
- package/dist/color/misc/index.js +2 -0
- package/dist/color/misc/is.js +2 -0
- package/dist/color/misc/state.js +2 -0
- package/dist/color/space/hex.js +2 -0
- package/dist/color/space/hsl.js +2 -0
- package/dist/color/space/rgb.js +2 -0
- package/dist/function/assert.js +2 -0
- package/dist/function/index.js +2 -0
- package/dist/function/memoize.js +2 -0
- package/dist/function/once.js +2 -0
- package/dist/function/retry.js +2 -0
- package/dist/function/work.js +2 -0
- package/dist/index.js +5 -4
- package/dist/internal/array/callbacks.js +2 -0
- package/dist/internal/array/chunk.js +2 -0
- package/dist/internal/array/compact.js +2 -0
- package/dist/internal/array/find.js +6 -4
- package/dist/internal/array/group.js +2 -0
- package/dist/internal/array/insert.js +2 -0
- package/dist/internal/array/sets.js +8 -6
- package/dist/internal/array/shuffle.js +3 -1
- package/dist/internal/array/update.js +2 -0
- package/dist/internal/function/misc.js +2 -0
- package/dist/internal/function/timer.js +5 -3
- package/dist/internal/is.js +2 -0
- package/dist/internal/math/aggregate.js +2 -0
- package/dist/internal/number.js +2 -0
- package/dist/internal/random.js +2 -0
- package/dist/internal/result.js +2 -0
- package/dist/internal/sized.js +2 -0
- package/dist/internal/string.js +2 -0
- package/dist/internal/value/compare.js +2 -0
- package/dist/internal/value/equal.js +2 -0
- package/dist/internal/value/get.js +2 -0
- package/dist/internal/value/handlers.js +2 -0
- package/dist/internal/value/has.js +2 -0
- package/dist/internal/value/misc.js +2 -0
- package/dist/internal/value/partial.js +2 -0
- package/dist/internal/value/set.js +2 -0
- package/dist/is.js +2 -0
- package/dist/logger.js +2 -0
- package/dist/math.js +2 -0
- package/dist/promise/delay.js +3 -1
- package/dist/promise/helpers.js +8 -1
- package/dist/promise/index.js +9 -3
- package/dist/promise/misc.js +3 -1
- package/dist/promise/models.js +14 -12
- package/dist/promise/timed.js +3 -1
- package/dist/query.js +2 -0
- package/dist/queue.js +2 -0
- package/dist/random.js +2 -0
- package/dist/result/index.js +5 -3
- package/dist/result/match.js +2 -0
- package/dist/result/misc.js +2 -0
- package/dist/result/work/flow.js +2 -0
- package/dist/result/work/pipe.js +2 -0
- package/dist/sized/map.js +2 -0
- package/dist/sized/set.js +2 -0
- package/dist/string/case.js +2 -0
- package/dist/string/index.js +2 -0
- package/dist/string/match.js +2 -0
- package/dist/string/template.js +2 -0
- package/dist/value/clone.js +3 -1
- package/dist/value/diff.js +2 -0
- package/dist/value/merge.js +2 -0
- package/dist/value/omit.js +2 -0
- package/dist/value/pick.js +2 -0
- package/dist/value/smush.js +3 -1
- package/dist/value/unsmush.js +3 -1
- package/package.json +3 -3
- package/src/array/index.ts +1 -0
- package/src/array/position.ts +303 -0
- package/src/internal/array/sets.ts +3 -3
- package/src/internal/array/shuffle.ts +1 -1
- package/src/promise/helpers.ts +13 -3
- package/src/promise/index.ts +89 -19
- package/src/promise/misc.ts +1 -4
- package/src/promise/models.ts +18 -12
- package/src/value/clone.ts +1 -1
- package/src/value/smush.ts +1 -1
- package/src/value/unsmush.ts +1 -1
- package/types/array/index.d.ts +1 -0
- package/types/array/position.d.ts +117 -0
- package/types/promise/helpers.d.ts +3 -1
- package/types/promise/index.d.ts +52 -5
- package/types/promise/misc.d.ts +1 -1
- package/types/promise/models.d.ts +15 -11
package/dist/array/difference.js
CHANGED
|
@@ -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 };
|
package/dist/array/exists.js
CHANGED
|
@@ -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 };
|
package/dist/array/filter.js
CHANGED
|
@@ -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 };
|
package/dist/array/find.js
CHANGED
package/dist/array/flatten.js
CHANGED
|
@@ -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 };
|
package/dist/array/from.js
CHANGED
|
@@ -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 };
|
package/dist/array/group-by.js
CHANGED
|
@@ -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 };
|
package/dist/array/index-of.js
CHANGED
package/dist/array/index.js
CHANGED
|
@@ -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 };
|
package/dist/array/insert.js
CHANGED
|
@@ -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 };
|
package/dist/array/partition.js
CHANGED
|
@@ -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 };
|
package/dist/array/push.js
CHANGED
|
@@ -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 };
|
package/dist/array/select.js
CHANGED
package/dist/array/slice.js
CHANGED
|
@@ -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 };
|
package/dist/array/sort.js
CHANGED
|
@@ -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 };
|
package/dist/array/splice.js
CHANGED
|
@@ -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 };
|
package/dist/array/to-map.js
CHANGED
|
@@ -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 };
|
package/dist/array/to-record.js
CHANGED
|
@@ -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 };
|
package/dist/array/to-set.js
CHANGED
|
@@ -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 };
|
package/dist/array/toggle.js
CHANGED
package/dist/array/union.js
CHANGED
package/dist/array/unique.js
CHANGED
|
@@ -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 };
|