@oscarpalmer/atoms 0.200.0 → 0.202.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/group-by.d.mts +13 -181
- package/dist/array/index.d.mts +2 -2
- package/dist/array/index.mjs +2 -2
- package/dist/array/select.d.mts +71 -64
- package/dist/array/select.mjs +17 -2
- package/dist/array/to-map.d.mts +15 -171
- package/dist/array/to-record.d.mts +15 -171
- package/dist/index.d.mts +132 -589
- package/dist/index.mjs +32 -6
- package/dist/internal/array/find.d.mts +5 -1
- package/dist/internal/array/find.mjs +16 -4
- package/dist/internal/subscription.d.mts +6 -6
- package/dist/models.d.mts +17 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -68,12 +68,16 @@ function findValues(type, array, parameters, mapper) {
|
|
|
68
68
|
result.matched = [...new Set(array)];
|
|
69
69
|
return result;
|
|
70
70
|
}
|
|
71
|
-
const mapCallback = getArrayCallback(mapper);
|
|
71
|
+
const mapCallback = getArrayCallback(mapper?.callback);
|
|
72
|
+
const mapReverse = mapper?.reverse ?? false;
|
|
73
|
+
const mapAfter = mapCallback == null ? void 0 : mapReverse ? void 0 : mapCallback;
|
|
74
|
+
const mapBefore = mapCallback == null ? void 0 : mapReverse ? mapCallback : void 0;
|
|
72
75
|
if (callbacks?.bool != null || type === "all" && key == null) {
|
|
73
76
|
const callback = callbacks?.bool ?? ((item) => Object.is(item, value));
|
|
74
77
|
for (let index = 0; index < length; index += 1) {
|
|
75
78
|
const item = array[index];
|
|
76
|
-
|
|
79
|
+
const transformed = mapBefore?.(item, index, array) ?? item;
|
|
80
|
+
if (callback(transformed, index, array)) result.matched.push(mapAfter?.(item, index, array) ?? transformed);
|
|
77
81
|
else result.notMatched.push(item);
|
|
78
82
|
}
|
|
79
83
|
return result;
|
|
@@ -81,10 +85,18 @@ function findValues(type, array, parameters, mapper) {
|
|
|
81
85
|
const keys = /* @__PURE__ */ new Set();
|
|
82
86
|
for (let index = 0; index < length; index += 1) {
|
|
83
87
|
const item = array[index];
|
|
84
|
-
|
|
88
|
+
let keyed;
|
|
89
|
+
let transformed;
|
|
90
|
+
if (mapBefore == null) {
|
|
91
|
+
keyed = callbacks?.keyed?.(item, index, array) ?? item;
|
|
92
|
+
transformed = item;
|
|
93
|
+
} else {
|
|
94
|
+
transformed = mapBefore(item, index, array);
|
|
95
|
+
keyed = callbacks?.keyed?.(transformed, index, array) ?? transformed;
|
|
96
|
+
}
|
|
85
97
|
if (type === "all" && Object.is(keyed, value) || type === "unique" && !keys.has(keyed)) {
|
|
86
98
|
keys.add(keyed);
|
|
87
|
-
result.matched.push(
|
|
99
|
+
result.matched.push(mapAfter?.(item, index, array) ?? transformed);
|
|
88
100
|
} else result.notMatched.push(item);
|
|
89
101
|
}
|
|
90
102
|
return result;
|
|
@@ -661,9 +673,23 @@ function reverse(array) {
|
|
|
661
673
|
}
|
|
662
674
|
//#endregion
|
|
663
675
|
//#region src/array/select.ts
|
|
676
|
+
function reverseSelect(array, ...parameters) {
|
|
677
|
+
return findValues("all", array, parameters, {
|
|
678
|
+
callback: parameters.shift(),
|
|
679
|
+
reverse: true
|
|
680
|
+
}).matched;
|
|
681
|
+
}
|
|
664
682
|
function select(array, ...parameters) {
|
|
665
|
-
return
|
|
683
|
+
return selectValues(array, parameters);
|
|
684
|
+
}
|
|
685
|
+
function selectValues(array, parameters) {
|
|
686
|
+
return findValues("all", array, parameters, {
|
|
687
|
+
callback: parameters.pop(),
|
|
688
|
+
reverse: false
|
|
689
|
+
}).matched;
|
|
666
690
|
}
|
|
691
|
+
select.reverse = reverseSelect;
|
|
692
|
+
Object.defineProperty(select, "reverse", { value: reverseSelect });
|
|
667
693
|
//#endregion
|
|
668
694
|
//#region src/array/single.ts
|
|
669
695
|
function single(array, ...parameters) {
|
|
@@ -6488,4 +6514,4 @@ var SizedSet = class extends Set {
|
|
|
6488
6514
|
}
|
|
6489
6515
|
};
|
|
6490
6516
|
//#endregion
|
|
6491
|
-
export { CancelablePromise, Logger, PromiseTimeoutError, QueueError, RetryError, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SizedMap, SizedSet, assert, assertCondition, assertDefined, assertInstanceOf, assertIs, assertProperty, assign, asyncAttempt, asyncDebounce, asyncFlow, asyncMatchResult, asyncOnce, asyncPipe, asyncThrottle, attempt, attemptAsyncFlow, attemptAsyncPipe, attemptFlow, attemptPipe, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, copy, count, debounce, deburr, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, filter, find, findLast, first, firstOrDefault, flatFreeze, flatten, floor, flow, freeze, fromQuery, toPromise as fromResult, toPromise, fuzzy, fuzzyMatch, getArray, getArrayComparison, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getHwbColor, getHwbaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloatingNumber as getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getSortedIndex, getString, getTimedPromise, getUuid, getValue, groupArraysBy, groupBy, handleResult, hasValue, hasValueResult, herald, hexToHsl, hexToHsla, hexToHwb, hexToHwba, hexToRgb, hexToRgba, hslToHex, hslToHwb, hslToHwba, hslToRgb, hslToRgba, hwbToHex, hwbToHsl, hwbToHsla, hwbToRgb, hwbToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, initializeAssigner, initializeCloner, initializeEqualizer, initializeMerger, initializeNormalizer, initializeSorter, initializeTemplater, initializeTransformer, insert, interpolate, intersection, isArrayOrPlainObject, isBeacon, isBeaconSubscription, isColor, isConstructor, isEmpty, isError, isFrozen, isFulfilled, isHerald, isHeraldEvents, isHeraldSubscription, isHexColor, isHslColor, isHslaColor, isHwbColor, isHwbaColor, isInstanceOf, isKey, isKeyedQueue, isLogger, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isObservable, isOk, isPlainObject, isPrimitive, isQueue, isQueueInstance, isRejected, isResult, isRgbColor, isRgbaColor, isSorted, isSubscription, isSubscriptions, isTimedLogger, isTypedArray, join, kebabCase, keyedQueue, last, lastIndexOf, lastOrDefault, lowerCase, matchResult, max, median, memoize, merge, min, move, moveIndices, moveToIndex, noop, normalize, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, registerCloner, registerComparator, registerEqualizer, resultPromises, retry, reverse, rgbToHex, rgbToHsl, rgbToHsla, rgbToHwb, rgbToHwba, round, select, setValue, settlePromise, shake, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, subscriptions, sum, swap, take, template, throttle, timed, times, titleCase, toMap, toMapArrays, toQuery, toRecord, toRecordArrays, toResult, toSet, toggle, transform, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
|
|
6517
|
+
export { CancelablePromise, Logger, PromiseTimeoutError, QueueError, RetryError, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SizedMap, SizedSet, assert, assertCondition, assertDefined, assertInstanceOf, assertIs, assertProperty, assign, asyncAttempt, asyncDebounce, asyncFlow, asyncMatchResult, asyncOnce, asyncPipe, asyncThrottle, attempt, attemptAsyncFlow, attemptAsyncPipe, attemptFlow, attemptPipe, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, copy, count, debounce, deburr, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, filter, find, findLast, first, firstOrDefault, flatFreeze, flatten, floor, flow, freeze, fromQuery, toPromise as fromResult, toPromise, fuzzy, fuzzyMatch, getArray, getArrayComparison, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getHwbColor, getHwbaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloatingNumber as getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getSortedIndex, getString, getTimedPromise, getUuid, getValue, groupArraysBy, groupBy, handleResult, hasValue, hasValueResult, herald, hexToHsl, hexToHsla, hexToHwb, hexToHwba, hexToRgb, hexToRgba, hslToHex, hslToHwb, hslToHwba, hslToRgb, hslToRgba, hwbToHex, hwbToHsl, hwbToHsla, hwbToRgb, hwbToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, initializeAssigner, initializeCloner, initializeEqualizer, initializeMerger, initializeNormalizer, initializeSorter, initializeTemplater, initializeTransformer, insert, interpolate, intersection, isArrayOrPlainObject, isBeacon, isBeaconSubscription, isColor, isConstructor, isEmpty, isError, isFrozen, isFulfilled, isHerald, isHeraldEvents, isHeraldSubscription, isHexColor, isHslColor, isHslaColor, isHwbColor, isHwbaColor, isInstanceOf, isKey, isKeyedQueue, isLogger, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isObservable, isOk, isPlainObject, isPrimitive, isQueue, isQueueInstance, isRejected, isResult, isRgbColor, isRgbaColor, isSorted, isSubscription, isSubscriptions, isTimedLogger, isTypedArray, join, kebabCase, keyedQueue, last, lastIndexOf, lastOrDefault, lowerCase, matchResult, max, median, memoize, merge, min, move, moveIndices, moveToIndex, noop, normalize, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, registerCloner, registerComparator, registerEqualizer, resultPromises, retry, reverse, reverseSelect, rgbToHex, rgbToHsl, rgbToHsla, rgbToHwb, rgbToHwba, round, select, setValue, settlePromise, shake, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, subscriptions, sum, swap, take, template, throttle, timed, times, titleCase, toMap, toMapArrays, toQuery, toRecord, toRecordArrays, toResult, toSet, toggle, transform, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
//#region src/internal/array/find.d.ts
|
|
2
|
+
type FindMapper = {
|
|
3
|
+
callback: unknown;
|
|
4
|
+
reverse: boolean;
|
|
5
|
+
};
|
|
2
6
|
type FindValueType = 'index' | 'item';
|
|
3
7
|
type FindValuesResult = {
|
|
4
8
|
matched: unknown[];
|
|
@@ -14,7 +18,7 @@ declare function createFindParameters(original: unknown[]): Parameters;
|
|
|
14
18
|
declare function findValue(type: Exclude<FindValueType, 'item'>, array: unknown[], parameters: unknown[], reversed: boolean): number;
|
|
15
19
|
declare function findValue(type: Exclude<FindValueType, 'index'>, array: unknown[], parameters: unknown[], reversed: boolean): unknown;
|
|
16
20
|
declare function findAbsoluteValueOrDefault(array: unknown[], parameters: unknown[], defaultValue: unknown, useDefaultValue: boolean, reversed: boolean): unknown;
|
|
17
|
-
declare function findValues(type: FindValuesType, array: unknown[], parameters: unknown[], mapper?:
|
|
21
|
+
declare function findValues(type: FindValuesType, array: unknown[], parameters: unknown[], mapper?: FindMapper): FindValuesResult;
|
|
18
22
|
declare const FIND_VALUE_INDEX = "index";
|
|
19
23
|
declare const FIND_VALUE_ITEM = "item";
|
|
20
24
|
declare const FIND_VALUES_ALL: FindValuesType;
|
|
@@ -52,12 +52,16 @@ function findValues(type, array, parameters, mapper) {
|
|
|
52
52
|
result.matched = [...new Set(array)];
|
|
53
53
|
return result;
|
|
54
54
|
}
|
|
55
|
-
const mapCallback = getArrayCallback(mapper);
|
|
55
|
+
const mapCallback = getArrayCallback(mapper?.callback);
|
|
56
|
+
const mapReverse = mapper?.reverse ?? false;
|
|
57
|
+
const mapAfter = mapCallback == null ? void 0 : mapReverse ? void 0 : mapCallback;
|
|
58
|
+
const mapBefore = mapCallback == null ? void 0 : mapReverse ? mapCallback : void 0;
|
|
56
59
|
if (callbacks?.bool != null || type === "all" && key == null) {
|
|
57
60
|
const callback = callbacks?.bool ?? ((item) => Object.is(item, value));
|
|
58
61
|
for (let index = 0; index < length; index += 1) {
|
|
59
62
|
const item = array[index];
|
|
60
|
-
|
|
63
|
+
const transformed = mapBefore?.(item, index, array) ?? item;
|
|
64
|
+
if (callback(transformed, index, array)) result.matched.push(mapAfter?.(item, index, array) ?? transformed);
|
|
61
65
|
else result.notMatched.push(item);
|
|
62
66
|
}
|
|
63
67
|
return result;
|
|
@@ -65,10 +69,18 @@ function findValues(type, array, parameters, mapper) {
|
|
|
65
69
|
const keys = /* @__PURE__ */ new Set();
|
|
66
70
|
for (let index = 0; index < length; index += 1) {
|
|
67
71
|
const item = array[index];
|
|
68
|
-
|
|
72
|
+
let keyed;
|
|
73
|
+
let transformed;
|
|
74
|
+
if (mapBefore == null) {
|
|
75
|
+
keyed = callbacks?.keyed?.(item, index, array) ?? item;
|
|
76
|
+
transformed = item;
|
|
77
|
+
} else {
|
|
78
|
+
transformed = mapBefore(item, index, array);
|
|
79
|
+
keyed = callbacks?.keyed?.(transformed, index, array) ?? transformed;
|
|
80
|
+
}
|
|
69
81
|
if (type === "all" && Object.is(keyed, value) || type === "unique" && !keys.has(keyed)) {
|
|
70
82
|
keys.add(keyed);
|
|
71
|
-
result.matched.push(
|
|
83
|
+
result.matched.push(mapAfter?.(item, index, array) ?? transformed);
|
|
72
84
|
} else result.notMatched.push(item);
|
|
73
85
|
}
|
|
74
86
|
return result;
|
|
@@ -44,7 +44,7 @@ type SubscriptionProperty = {
|
|
|
44
44
|
*/
|
|
45
45
|
value: unknown;
|
|
46
46
|
};
|
|
47
|
-
type Subscriptions = {
|
|
47
|
+
type Subscriptions<Value = unknown> = {
|
|
48
48
|
/**
|
|
49
49
|
* Items of the subscriptions store
|
|
50
50
|
*
|
|
@@ -60,7 +60,7 @@ type Subscriptions = {
|
|
|
60
60
|
* - `to.any` - Map of subscriptions to values _(for unkeyed subscriptions)_
|
|
61
61
|
* - `to.keyed` - Map of keys to maps of subscriptions to values _(for keyed subscriptions)_
|
|
62
62
|
*/
|
|
63
|
-
readonly values: Readonly<SubscriptionsValues
|
|
63
|
+
readonly values: Readonly<SubscriptionsValues<Value>>;
|
|
64
64
|
/**
|
|
65
65
|
* Clear all subscriptions
|
|
66
66
|
*/
|
|
@@ -90,9 +90,9 @@ type SubscriptionsItems = {
|
|
|
90
90
|
any: Set<Subscription>;
|
|
91
91
|
keyed?: Map<Key, Set<Subscription>>;
|
|
92
92
|
};
|
|
93
|
-
type SubscriptionsValues = {
|
|
94
|
-
from: SubscriptionsValuesItem<
|
|
95
|
-
to: SubscriptionsValuesItem<Subscription,
|
|
93
|
+
type SubscriptionsValues<Value = unknown> = {
|
|
94
|
+
from: SubscriptionsValuesItem<Value, Subscription>;
|
|
95
|
+
to: SubscriptionsValuesItem<Subscription, Value>;
|
|
96
96
|
};
|
|
97
97
|
type SubscriptionsValuesItem<MapKey, MapValue> = {
|
|
98
98
|
any: Map<MapKey, MapValue>;
|
|
@@ -118,7 +118,7 @@ declare function isSubscriptions(value: unknown): value is Subscriptions;
|
|
|
118
118
|
* @param parameters Store parameters
|
|
119
119
|
* @returns Subscription store
|
|
120
120
|
*/
|
|
121
|
-
declare function subscriptions(parameters?: SubscriptionsParameters): Subscriptions
|
|
121
|
+
declare function subscriptions<Value = unknown>(parameters?: SubscriptionsParameters): Subscriptions<Value>;
|
|
122
122
|
declare const SUBSCRIPTION_NAME = "subscription";
|
|
123
123
|
//#endregion
|
|
124
124
|
export { SUBSCRIPTION_NAME, Subscription, SubscriptionParameters, SubscriptionProperty, Subscriptions, SubscriptionsParameters, isSubscription, isSubscriptions, subscriptions };
|
package/dist/models.d.mts
CHANGED
|
@@ -43,7 +43,23 @@ type GenericCallback = (...args: any[]) => any;
|
|
|
43
43
|
* A generic key type
|
|
44
44
|
*/
|
|
45
45
|
type Key = number | string;
|
|
46
|
+
/**
|
|
47
|
+
* The `PropertyKey`-safe value of `Item`'s `ItemKey` property
|
|
48
|
+
*/
|
|
46
49
|
type KeyedValue<Item, ItemKey extends keyof Item> = Item[ItemKey] extends PropertyKey ? Item[ItemKey] : never;
|
|
50
|
+
/**
|
|
51
|
+
* A key of `Item`, or a callback returning `Return`, used to derive a value from an item
|
|
52
|
+
*/
|
|
53
|
+
type KeyOrCallback<Item, Return = unknown> = ((item: Item, index: number, array: Item[]) => Return) | (Item extends PlainObject ? keyof Item : never);
|
|
54
|
+
/**
|
|
55
|
+
* The `PropertyKey`-safe value resolved from a `KeyOrCallback<Item, Key>` argument, for use as a
|
|
56
|
+
* `Record` or `Map` key
|
|
57
|
+
*/
|
|
58
|
+
type KeyOrCallbackKey<Item, Arg extends KeyOrCallback<Item, Key>> = Arg extends ((item: Item, index: number, array: Item[]) => Key) ? ReturnType<Arg> : Arg extends keyof Item ? KeyedValue<Item, Arg> : never;
|
|
59
|
+
/**
|
|
60
|
+
* The value resolved from a `KeyOrCallback` argument against `Item`
|
|
61
|
+
*/
|
|
62
|
+
type KeyOrCallbackValue<Item, Arg extends KeyOrCallback<Item>> = Arg extends ((item: Item, index: number, array: Item[]) => unknown) ? ReturnType<Arg> : Arg extends keyof Item ? Item[Arg] : never;
|
|
47
63
|
/**
|
|
48
64
|
* A nested array
|
|
49
65
|
*/
|
|
@@ -154,4 +170,4 @@ type UnionToIntersection<Union> = (Union extends unknown ? (distributedUnion: Un
|
|
|
154
170
|
*/
|
|
155
171
|
type Unsubscriber = () => void;
|
|
156
172
|
//#endregion
|
|
157
|
-
export { ArrayOrPlainObject, AsyncCancelableCallback, BuiltIns, CancelableCallback, Constructor, GenericAsyncCallback, GenericCallback, Key, KeyedValue, NestedArray, NestedKeys, NestedPartial, NestedValue, NestedValues, NumericalKeys, NumericalValues, OnceAsyncCallback, OnceCallback, PlainObject, Primitive, RequiredKeys, Simplify, ToString, TypedArray, UnionToIntersection, Unsubscriber };
|
|
173
|
+
export { ArrayOrPlainObject, AsyncCancelableCallback, BuiltIns, CancelableCallback, Constructor, GenericAsyncCallback, GenericCallback, Key, KeyOrCallback, KeyOrCallbackKey, KeyOrCallbackValue, KeyedValue, NestedArray, NestedKeys, NestedPartial, NestedValue, NestedValues, NumericalKeys, NumericalValues, OnceAsyncCallback, OnceCallback, PlainObject, Primitive, RequiredKeys, Simplify, ToString, TypedArray, UnionToIntersection, Unsubscriber };
|