@oscarpalmer/atoms 0.179.0 → 0.180.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/filter.d.mts +36 -28
- package/dist/array/filter.mjs +5 -5
- package/dist/array/first.d.mts +13 -5
- package/dist/array/first.mjs +1 -1
- package/dist/array/group-by.d.mts +13 -1
- package/dist/array/group-by.mjs +1 -1
- package/dist/array/last.d.mts +9 -1
- package/dist/array/last.mjs +1 -1
- package/dist/array/move.d.mts +9 -1
- package/dist/array/move.mjs +3 -1
- package/dist/array/reverse.d.mts +5 -0
- package/dist/array/reverse.mjs +5 -0
- package/dist/array/select.d.mts +2 -2
- package/dist/array/sort.d.mts +23 -9
- package/dist/array/sort.mjs +22 -22
- package/dist/array/swap.d.mts +2 -0
- package/dist/array/swap.mjs +2 -0
- package/dist/array/to-map.d.mts +13 -1
- package/dist/array/to-map.mjs +1 -1
- package/dist/array/to-record.d.mts +13 -1
- package/dist/array/to-record.mjs +1 -1
- package/dist/function/assert.d.mts +9 -1
- package/dist/function/assert.mjs +9 -1
- package/dist/function/limit.d.mts +5 -1
- package/dist/function/limit.mjs +5 -1
- package/dist/function/once.d.mts +3 -1
- package/dist/function/once.mjs +3 -1
- package/dist/function/retry.d.mts +4 -0
- package/dist/function/retry.mjs +2 -0
- package/dist/function/work.d.mts +49 -1
- package/dist/function/work.mjs +1 -1
- package/dist/index.d.mts +415 -242
- package/dist/index.mjs +224 -167
- package/dist/internal/array/index-of.mjs +1 -1
- package/dist/internal/function/timer.mjs +3 -1
- package/dist/internal/value/compare.d.mts +13 -9
- package/dist/internal/value/compare.mjs +13 -9
- package/dist/internal/value/equal.d.mts +29 -15
- package/dist/internal/value/equal.mjs +41 -35
- package/dist/internal/value/handlers.d.mts +4 -4
- package/dist/internal/value/handlers.mjs +19 -11
- package/dist/internal/value/has.d.mts +9 -8
- package/dist/internal/value/has.mjs +3 -3
- package/dist/internal/value/misc.d.mts +4 -8
- package/dist/internal/value/misc.mjs +6 -17
- package/dist/promise/index.d.mts +11 -1
- package/dist/promise/index.mjs +1 -1
- package/dist/result/index.d.mts +9 -1
- package/dist/result/index.mjs +1 -1
- package/dist/result/match.d.mts +5 -1
- package/dist/result/match.mjs +1 -1
- package/dist/result/misc.d.mts +3 -3
- package/dist/result/work/flow.d.mts +49 -1
- package/dist/result/work/flow.mjs +1 -1
- package/dist/result/work/pipe.d.mts +67 -155
- package/dist/result/work/pipe.mjs +3 -3
- package/dist/string/fuzzy.d.mts +11 -1
- package/dist/string/fuzzy.mjs +22 -6
- package/dist/string/template.d.mts +3 -1
- package/dist/string/template.mjs +3 -1
- package/dist/value/clone.d.mts +13 -9
- package/dist/value/clone.mjs +21 -17
- package/dist/value/merge.d.mts +9 -7
- package/dist/value/merge.mjs +7 -5
- package/package.json +3 -3
- package/plugin/helpers.js +2 -2
- package/src/array/filter.ts +44 -36
- package/src/array/first.ts +18 -9
- package/src/array/group-by.ts +22 -10
- package/src/array/last.ts +17 -5
- package/src/array/move.ts +18 -5
- package/src/array/reverse.ts +5 -0
- package/src/array/select.ts +2 -2
- package/src/array/sort.ts +110 -86
- package/src/array/swap.ts +2 -0
- package/src/array/to-map.ts +22 -10
- package/src/array/to-record.ts +22 -10
- package/src/function/assert.ts +12 -4
- package/src/function/limit.ts +6 -2
- package/src/function/once.ts +3 -1
- package/src/function/retry.ts +8 -2
- package/src/function/work.ts +92 -26
- package/src/internal/array/index-of.ts +1 -1
- package/src/internal/function/timer.ts +4 -2
- package/src/internal/string.ts +2 -0
- package/src/internal/value/compare.ts +14 -11
- package/src/internal/value/equal.ts +79 -67
- package/src/internal/value/handlers.ts +19 -11
- package/src/internal/value/has.ts +16 -16
- package/src/internal/value/misc.ts +10 -8
- package/src/promise/index.ts +14 -4
- package/src/result/index.ts +15 -5
- package/src/result/match.ts +7 -3
- package/src/result/misc.ts +3 -3
- package/src/result/work/flow.ts +68 -13
- package/src/result/work/pipe.ts +97 -392
- package/src/string/fuzzy.ts +34 -8
- package/src/string/template.ts +3 -1
- package/src/value/clone.ts +25 -22
- package/src/value/merge.ts +14 -12
package/dist/string/fuzzy.mjs
CHANGED
|
@@ -33,7 +33,7 @@ var Fuzzy = class {
|
|
|
33
33
|
this.#state = state;
|
|
34
34
|
}
|
|
35
35
|
search(value, options) {
|
|
36
|
-
return search(this.#state.items, this.#state.strings, value, options == null ? this.#state :
|
|
36
|
+
return search(this.#state.items, this.#state.strings, value, options == null ? this.#state : getFuzzyOptions(options, this.#state));
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
39
|
function getHandler(input) {
|
|
@@ -49,18 +49,17 @@ function getHandler(input) {
|
|
|
49
49
|
function getItems(items) {
|
|
50
50
|
return items.sort((first, second) => first.haystack.localeCompare(second.haystack)).map(({ item }) => item);
|
|
51
51
|
}
|
|
52
|
-
function
|
|
52
|
+
function getFuzzyOptions(input, state) {
|
|
53
53
|
const options = isPlainObject(input) ? input : {};
|
|
54
54
|
const limit = typeof input === "number" ? input : options.limit;
|
|
55
55
|
if (typeof limit === "number" && !Number.isNaN(limit) && limit >= 1) options.limit = Math.floor(limit);
|
|
56
56
|
else options.limit = state?.limit;
|
|
57
|
-
|
|
58
|
-
else options.tolerance = state?.tolerance ?? PROXIMITY_THRESHOLD;
|
|
57
|
+
options.tolerance = getTolerance(options.tolerance, state);
|
|
59
58
|
return options;
|
|
60
59
|
}
|
|
61
60
|
function getState(items, input) {
|
|
62
61
|
const handler = getHandler(input);
|
|
63
|
-
const options =
|
|
62
|
+
const options = getFuzzyOptions(input);
|
|
64
63
|
return {
|
|
65
64
|
handler,
|
|
66
65
|
items: items.slice(),
|
|
@@ -69,10 +68,27 @@ function getState(items, input) {
|
|
|
69
68
|
tolerance: options.tolerance
|
|
70
69
|
};
|
|
71
70
|
}
|
|
71
|
+
function getTolerance(input, state) {
|
|
72
|
+
if (typeof input === "number" && !Number.isNaN(input)) return input < 0 ? 0 : Math.floor(input);
|
|
73
|
+
return state?.tolerance ?? PROXIMITY_THRESHOLD;
|
|
74
|
+
}
|
|
72
75
|
function fuzzy(items, configuration) {
|
|
73
76
|
if (!Array.isArray(items)) throw new TypeError(MESSAGE_ARRAY);
|
|
74
77
|
return new Fuzzy(getState(items, configuration));
|
|
75
78
|
}
|
|
79
|
+
fuzzy.match = fuzzyMatch;
|
|
80
|
+
/**
|
|
81
|
+
* Does the needle match the haystack in a fuzzy way?
|
|
82
|
+
* @param haystack Haystack to search through
|
|
83
|
+
* @param needle Needle to search for
|
|
84
|
+
* @returns `true` if the needle matches the haystack in a fuzzy way, `false` otherwise
|
|
85
|
+
*/
|
|
86
|
+
function fuzzyMatch(haystack, needle) {
|
|
87
|
+
if (typeof haystack !== "string" || typeof needle !== "string") return false;
|
|
88
|
+
const trimmed = needle.trim();
|
|
89
|
+
if (includes(haystack, trimmed, true)) return true;
|
|
90
|
+
return getScore(haystack, trimmed) > -1;
|
|
91
|
+
}
|
|
76
92
|
function isSubsequence(haystack, needle) {
|
|
77
93
|
const lowerCaseHaystack = lowerCase(haystack);
|
|
78
94
|
const lowerCaseNeedle = lowerCase(needle);
|
|
@@ -162,4 +178,4 @@ const MESSAGE_ARRAY = "Fuzzy requires an array of items";
|
|
|
162
178
|
const MESSAGE_HANDLER = "Fuzzy requires a key or function to stringify items";
|
|
163
179
|
const PROXIMITY_THRESHOLD = 5;
|
|
164
180
|
//#endregion
|
|
165
|
-
export { fuzzy };
|
|
181
|
+
export { fuzzy, fuzzyMatch };
|
|
@@ -23,6 +23,8 @@ type TemplateOptions = {
|
|
|
23
23
|
type Templater = (value: string, variables?: PlainObject) => string;
|
|
24
24
|
/**
|
|
25
25
|
* Create a templater with predefined options
|
|
26
|
+
*
|
|
27
|
+
* Available as `initializeTemplater` and `template.initialize`
|
|
26
28
|
* @param options Templating options
|
|
27
29
|
* @returns Templater function
|
|
28
30
|
*/
|
|
@@ -39,4 +41,4 @@ declare namespace template {
|
|
|
39
41
|
var initialize: typeof initializeTemplater;
|
|
40
42
|
}
|
|
41
43
|
//#endregion
|
|
42
|
-
export { TemplateOptions, template };
|
|
44
|
+
export { TemplateOptions, initializeTemplater, template };
|
package/dist/string/template.mjs
CHANGED
|
@@ -23,6 +23,8 @@ function handleTemplate(value, pattern, ignoreCase, variables) {
|
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
25
|
* Create a templater with predefined options
|
|
26
|
+
*
|
|
27
|
+
* Available as `initializeTemplater` and `template.initialize`
|
|
26
28
|
* @param options Templating options
|
|
27
29
|
* @returns Templater function
|
|
28
30
|
*/
|
|
@@ -46,4 +48,4 @@ function template(value, variables, options) {
|
|
|
46
48
|
template.initialize = initializeTemplater;
|
|
47
49
|
const EXPRESSION_VARIABLE = /{{([\s\S]+?)}}/g;
|
|
48
50
|
//#endregion
|
|
49
|
-
export { template };
|
|
51
|
+
export { initializeTemplater, template };
|
package/dist/value/clone.d.mts
CHANGED
|
@@ -9,23 +9,27 @@ import { Constructor, GenericCallback } from "../models.mjs";
|
|
|
9
9
|
declare function clone<Value>(value: Value): Value;
|
|
10
10
|
declare namespace clone {
|
|
11
11
|
var handlers: {
|
|
12
|
-
|
|
13
|
-
unregister: (constructor: Constructor) => void;
|
|
12
|
+
deregister(constructor: Constructor): void;
|
|
14
13
|
handle(value: unknown, ...parameters: unknown[]): any;
|
|
14
|
+
register(constructor: Constructor, handler?: string | GenericCallback): void;
|
|
15
15
|
};
|
|
16
|
+
var deregister: typeof deregisterCloner;
|
|
16
17
|
var register: typeof registerCloner;
|
|
17
|
-
var unregister: typeof unregisterCloner;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
* Deregister a clone handler for a specific class
|
|
21
|
+
*
|
|
22
|
+
* Available as `deregisterCloner` and `template.deregister`
|
|
21
23
|
* @param constructor Class constructor
|
|
22
|
-
* @param handler Method name or clone function _(defaults to `clone`)_
|
|
23
24
|
*/
|
|
24
|
-
declare function
|
|
25
|
+
declare function deregisterCloner<Instance>(constructor: Constructor<Instance>): void;
|
|
25
26
|
/**
|
|
26
|
-
*
|
|
27
|
+
* Register a clone handler for a specific class
|
|
28
|
+
*
|
|
29
|
+
* Available as `registerCloner` and `template.register`
|
|
27
30
|
* @param constructor Class constructor
|
|
31
|
+
* @param handler Method name or clone function _(defaults to `clone`)_
|
|
28
32
|
*/
|
|
29
|
-
declare function
|
|
33
|
+
declare function registerCloner<Instance>(constructor: Constructor<Instance>, handler?: string | ((value: Instance) => Instance)): void;
|
|
30
34
|
//#endregion
|
|
31
|
-
export { clone };
|
|
35
|
+
export { clone, deregisterCloner, registerCloner };
|
package/dist/value/clone.mjs
CHANGED
|
@@ -9,23 +9,8 @@ clone.handlers = getSelfHandlers(clone, {
|
|
|
9
9
|
callback: tryStructuredClone,
|
|
10
10
|
method: CLONE_NAME
|
|
11
11
|
});
|
|
12
|
+
clone.deregister = deregisterCloner;
|
|
12
13
|
clone.register = registerCloner;
|
|
13
|
-
clone.unregister = unregisterCloner;
|
|
14
|
-
/**
|
|
15
|
-
* Register a clone handler for a specific class
|
|
16
|
-
* @param constructor Class constructor
|
|
17
|
-
* @param handler Method name or clone function _(defaults to `clone`)_
|
|
18
|
-
*/
|
|
19
|
-
function registerCloner(constructor, handler) {
|
|
20
|
-
clone.handlers.register(constructor, handler);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Unregister a clone handler for a specific class
|
|
24
|
-
* @param constructor Class constructor
|
|
25
|
-
*/
|
|
26
|
-
function unregisterCloner(constructor) {
|
|
27
|
-
clone.handlers.unregister(constructor);
|
|
28
|
-
}
|
|
29
14
|
function cloneArrayBuffer(value, depth, references) {
|
|
30
15
|
if (typeof depth === "number" && depth >= MAX_CLONE_DEPTH) return value;
|
|
31
16
|
const cloned = new ArrayBuffer(value.byteLength);
|
|
@@ -110,6 +95,25 @@ function cloneValue(value, depth, references) {
|
|
|
110
95
|
default: return clone.handlers.handle(value, depth, references);
|
|
111
96
|
}
|
|
112
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Deregister a clone handler for a specific class
|
|
100
|
+
*
|
|
101
|
+
* Available as `deregisterCloner` and `template.deregister`
|
|
102
|
+
* @param constructor Class constructor
|
|
103
|
+
*/
|
|
104
|
+
function deregisterCloner(constructor) {
|
|
105
|
+
clone.handlers.deregister(constructor);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Register a clone handler for a specific class
|
|
109
|
+
*
|
|
110
|
+
* Available as `registerCloner` and `template.register`
|
|
111
|
+
* @param constructor Class constructor
|
|
112
|
+
* @param handler Method name or clone function _(defaults to `clone`)_
|
|
113
|
+
*/
|
|
114
|
+
function registerCloner(constructor, handler) {
|
|
115
|
+
clone.handlers.register(constructor, handler);
|
|
116
|
+
}
|
|
113
117
|
function tryStructuredClone(value, depth, references) {
|
|
114
118
|
if (depth >= MAX_CLONE_DEPTH) return value;
|
|
115
119
|
try {
|
|
@@ -123,4 +127,4 @@ function tryStructuredClone(value, depth, references) {
|
|
|
123
127
|
}
|
|
124
128
|
const MAX_CLONE_DEPTH = 100;
|
|
125
129
|
//#endregion
|
|
126
|
-
export { clone };
|
|
130
|
+
export { clone, deregisterCloner, registerCloner };
|
package/dist/value/merge.d.mts
CHANGED
|
@@ -27,6 +27,14 @@ type MergeOptions = {
|
|
|
27
27
|
* @returns Merged value
|
|
28
28
|
*/
|
|
29
29
|
type Merger<Model extends ArrayOrPlainObject = ArrayOrPlainObject> = (values: NestedPartial<Model>[]) => Model;
|
|
30
|
+
/**
|
|
31
|
+
* Create a merger with predefined options
|
|
32
|
+
*
|
|
33
|
+
* Available as `initializeMerger` and `merge.initialize`
|
|
34
|
+
* @param options Merging options
|
|
35
|
+
* @returns Merger function
|
|
36
|
+
*/
|
|
37
|
+
declare function initializeMerger(options?: MergeOptions): Merger;
|
|
30
38
|
/**
|
|
31
39
|
* Merge multiple arrays or objects into a single one
|
|
32
40
|
* @param values Values to merge
|
|
@@ -44,11 +52,5 @@ declare function merge(values: NestedPartial<ArrayOrPlainObject>[], options?: Me
|
|
|
44
52
|
declare namespace merge {
|
|
45
53
|
var initialize: typeof initializeMerger;
|
|
46
54
|
}
|
|
47
|
-
/**
|
|
48
|
-
* Create a merger with predefined options
|
|
49
|
-
* @param options Merging options
|
|
50
|
-
* @returns Merger function
|
|
51
|
-
*/
|
|
52
|
-
declare function initializeMerger(options?: MergeOptions): Merger;
|
|
53
55
|
//#endregion
|
|
54
|
-
export { MergeOptions, Merger, merge };
|
|
56
|
+
export { MergeOptions, Merger, initializeMerger, merge };
|
package/dist/value/merge.mjs
CHANGED
|
@@ -20,12 +20,10 @@ function getReplaceableObjects(value) {
|
|
|
20
20
|
function handleMerge(values, options) {
|
|
21
21
|
return !Array.isArray(values) || values.length === 0 ? {} : mergeValues(values, options, true);
|
|
22
22
|
}
|
|
23
|
-
function merge(values, options) {
|
|
24
|
-
return handleMerge(values, getMergeOptions(options));
|
|
25
|
-
}
|
|
26
|
-
merge.initialize = initializeMerger;
|
|
27
23
|
/**
|
|
28
24
|
* Create a merger with predefined options
|
|
25
|
+
*
|
|
26
|
+
* Available as `initializeMerger` and `merge.initialize`
|
|
29
27
|
* @param options Merging options
|
|
30
28
|
* @returns Merger function
|
|
31
29
|
*/
|
|
@@ -33,6 +31,10 @@ function initializeMerger(options) {
|
|
|
33
31
|
const actual = getMergeOptions(options);
|
|
34
32
|
return (values) => handleMerge(values, actual);
|
|
35
33
|
}
|
|
34
|
+
function merge(values, options) {
|
|
35
|
+
return handleMerge(values, getMergeOptions(options));
|
|
36
|
+
}
|
|
37
|
+
merge.initialize = initializeMerger;
|
|
36
38
|
function mergeObjects(values, options, prefix) {
|
|
37
39
|
const { length } = values;
|
|
38
40
|
const isArray = values.every(Array.isArray);
|
|
@@ -58,4 +60,4 @@ function mergeValues(values, options, validate, prefix) {
|
|
|
58
60
|
return actual.length > 1 ? mergeObjects(actual, options, prefix) : actual[0] ?? {};
|
|
59
61
|
}
|
|
60
62
|
//#endregion
|
|
61
|
-
export { merge };
|
|
63
|
+
export { initializeMerger, merge };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oscarpalmer/atoms",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.180.0",
|
|
4
4
|
"description": "Atomic utilities for making your JavaScript better.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"helper",
|
|
@@ -245,7 +245,7 @@
|
|
|
245
245
|
"watch": "npx vite build --watch"
|
|
246
246
|
},
|
|
247
247
|
"devDependencies": {
|
|
248
|
-
"@oxlint/plugins": "^1.
|
|
248
|
+
"@oxlint/plugins": "^1.61",
|
|
249
249
|
"@types/node": "^25.6",
|
|
250
250
|
"@vitest/coverage-istanbul": "^4.1",
|
|
251
251
|
"eslint": "^10.2",
|
|
@@ -257,4 +257,4 @@
|
|
|
257
257
|
"vitest": "npm:@voidzero-dev/vite-plus-test@latest"
|
|
258
258
|
},
|
|
259
259
|
"packageManager": "npm@11.11.1"
|
|
260
|
-
}
|
|
260
|
+
}
|
package/plugin/helpers.js
CHANGED
|
@@ -177,7 +177,7 @@ function isInstanceMethod(type, context, node, methods) {
|
|
|
177
177
|
* @param {Set<string>} methods
|
|
178
178
|
* @returns {boolean}
|
|
179
179
|
*/
|
|
180
|
-
function isLiteralMethod(
|
|
180
|
+
function isLiteralMethod(_, __, ___, ____) {
|
|
181
181
|
// TODO: check literal value
|
|
182
182
|
|
|
183
183
|
return false;
|
|
@@ -190,7 +190,7 @@ function isLiteralMethod(type, context, node, methods) {
|
|
|
190
190
|
* @param {Set<string>} methods
|
|
191
191
|
* @returns {boolean}
|
|
192
192
|
*/
|
|
193
|
-
function isStaticMethod(type, context, node,
|
|
193
|
+
function isStaticMethod(type, context, node, _) {
|
|
194
194
|
const {object, property} = node.callee;
|
|
195
195
|
|
|
196
196
|
if (object.type !== identifierExpression || object.name !== objects[type]) {
|
package/src/array/filter.ts
CHANGED
|
@@ -4,101 +4,109 @@ import type {PlainObject} from '../models';
|
|
|
4
4
|
// #region Functions
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Get a filtered array of items
|
|
7
|
+
* Get a filtered array of items that do not match the filter
|
|
8
|
+
*
|
|
9
|
+
* Available as `exclude` and `filter.remove`
|
|
8
10
|
* @param array Array to search in
|
|
9
11
|
* @param callback Callback to get an item's value for matching
|
|
10
12
|
* @param value Value to match against
|
|
11
|
-
* @returns Filtered array of items
|
|
13
|
+
* @returns Filtered array of items that do not match the filter
|
|
12
14
|
*/
|
|
13
|
-
export function
|
|
15
|
+
export function exclude<
|
|
14
16
|
Item,
|
|
15
17
|
Callback extends (item: Item, index: number, array: Item[]) => unknown,
|
|
16
|
-
>(array: Item[], callback: Callback, value: ReturnType<Callback>):
|
|
18
|
+
>(array: Item[], callback: Callback, value: ReturnType<Callback>): unknown[];
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
|
-
* Get a filtered array of items
|
|
21
|
+
* Get a filtered array of items that do not match the filter
|
|
22
|
+
*
|
|
23
|
+
* Available as `exclude` and `filter.remove`
|
|
20
24
|
* @param array Array to search in
|
|
21
25
|
* @param key Key to get an item's value for matching
|
|
22
26
|
* @param value Value to match against
|
|
23
|
-
* @returns Filtered array of items
|
|
27
|
+
* @returns Filtered array of items that do not match the filter
|
|
24
28
|
*/
|
|
25
|
-
export function
|
|
29
|
+
export function exclude<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
26
30
|
array: Item[],
|
|
27
31
|
key: ItemKey,
|
|
28
32
|
value: Item[ItemKey],
|
|
29
|
-
):
|
|
33
|
+
): unknown[];
|
|
30
34
|
|
|
31
35
|
/**
|
|
32
|
-
* Get a filtered array of items
|
|
36
|
+
* Get a filtered array of items that do not match the filter
|
|
37
|
+
*
|
|
38
|
+
* Available as `exclude` and `filter.remove`
|
|
33
39
|
* @param array Array to search in
|
|
34
40
|
* @param filter Filter callback to match items
|
|
35
|
-
* @returns Filtered array of items
|
|
41
|
+
* @returns Filtered array of items that do not match the filter
|
|
36
42
|
*/
|
|
37
|
-
export function
|
|
43
|
+
export function exclude<Item>(
|
|
38
44
|
array: Item[],
|
|
39
45
|
filter: (item: Item, index: number, array: Item[]) => boolean,
|
|
40
|
-
):
|
|
46
|
+
): unknown[];
|
|
41
47
|
|
|
42
48
|
/**
|
|
43
|
-
* Get a filtered array of items
|
|
49
|
+
* Get a filtered array of items that do not match the given item
|
|
50
|
+
*
|
|
51
|
+
* Available as `exclude` and `filter.remove`
|
|
44
52
|
* @param array Array to search in
|
|
45
53
|
* @param item Item to match against
|
|
46
|
-
* @returns Filtered array of items
|
|
54
|
+
* @returns Filtered array of items that do not match the given item
|
|
47
55
|
*/
|
|
48
|
-
export function
|
|
56
|
+
export function exclude<Item>(array: Item[], item: Item): unknown[];
|
|
49
57
|
|
|
50
|
-
export function
|
|
51
|
-
return findValues(FIND_VALUES_ALL, array, parameters).
|
|
58
|
+
export function exclude(array: unknown[], ...parameters: unknown[]): unknown[] {
|
|
59
|
+
return findValues(FIND_VALUES_ALL, array, parameters).notMatched;
|
|
52
60
|
}
|
|
53
61
|
|
|
54
|
-
filter.remove = removeFiltered;
|
|
55
|
-
|
|
56
62
|
/**
|
|
57
|
-
* Get a filtered array of items
|
|
63
|
+
* Get a filtered array of items
|
|
58
64
|
* @param array Array to search in
|
|
59
65
|
* @param callback Callback to get an item's value for matching
|
|
60
66
|
* @param value Value to match against
|
|
61
|
-
* @returns Filtered array of items
|
|
67
|
+
* @returns Filtered array of items
|
|
62
68
|
*/
|
|
63
|
-
function
|
|
69
|
+
export function filter<
|
|
64
70
|
Item,
|
|
65
71
|
Callback extends (item: Item, index: number, array: Item[]) => unknown,
|
|
66
|
-
>(array: Item[], callback: Callback, value: ReturnType<Callback>):
|
|
72
|
+
>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item[];
|
|
67
73
|
|
|
68
74
|
/**
|
|
69
|
-
* Get a filtered array of items
|
|
75
|
+
* Get a filtered array of items
|
|
70
76
|
* @param array Array to search in
|
|
71
77
|
* @param key Key to get an item's value for matching
|
|
72
78
|
* @param value Value to match against
|
|
73
|
-
* @returns Filtered array of items
|
|
79
|
+
* @returns Filtered array of items
|
|
74
80
|
*/
|
|
75
|
-
function
|
|
81
|
+
export function filter<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
76
82
|
array: Item[],
|
|
77
83
|
key: ItemKey,
|
|
78
84
|
value: Item[ItemKey],
|
|
79
|
-
):
|
|
85
|
+
): Item[];
|
|
80
86
|
|
|
81
87
|
/**
|
|
82
|
-
* Get a filtered array of items
|
|
88
|
+
* Get a filtered array of items matching the filter
|
|
83
89
|
* @param array Array to search in
|
|
84
90
|
* @param filter Filter callback to match items
|
|
85
|
-
* @returns Filtered array of items
|
|
91
|
+
* @returns Filtered array of items
|
|
86
92
|
*/
|
|
87
|
-
function
|
|
93
|
+
export function filter<Item>(
|
|
88
94
|
array: Item[],
|
|
89
95
|
filter: (item: Item, index: number, array: Item[]) => boolean,
|
|
90
|
-
):
|
|
96
|
+
): Item[];
|
|
91
97
|
|
|
92
98
|
/**
|
|
93
|
-
* Get a filtered array of items
|
|
99
|
+
* Get a filtered array of items matching the given item
|
|
94
100
|
* @param array Array to search in
|
|
95
101
|
* @param item Item to match against
|
|
96
|
-
* @returns Filtered array of items
|
|
102
|
+
* @returns Filtered array of items
|
|
97
103
|
*/
|
|
98
|
-
function
|
|
104
|
+
export function filter<Item>(array: Item[], item: Item): Item[];
|
|
99
105
|
|
|
100
|
-
function
|
|
101
|
-
return findValues(FIND_VALUES_ALL, array, parameters).
|
|
106
|
+
export function filter(array: unknown[], ...parameters: unknown[]): unknown[] {
|
|
107
|
+
return findValues(FIND_VALUES_ALL, array, parameters).matched;
|
|
102
108
|
}
|
|
103
109
|
|
|
110
|
+
filter.remove = exclude;
|
|
111
|
+
|
|
104
112
|
// #endregion
|
package/src/array/first.ts
CHANGED
|
@@ -54,27 +54,32 @@ export function first(array: unknown[], ...parameters: unknown[]): unknown {
|
|
|
54
54
|
first.default = firstOrDefault;
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
|
-
* Get the first item matching the given value
|
|
57
|
+
* Get the first item matching the given value, or a default value if no match is found
|
|
58
|
+
*
|
|
59
|
+
* Available as `firstOrDefault` and `first.default`
|
|
58
60
|
* @param array Array to search in
|
|
59
61
|
* @param defaultValue Default value to return if no match is found
|
|
60
62
|
* @param callback Callback to get an item's value for matching
|
|
61
63
|
* @param value Value to match against
|
|
62
64
|
* @returns First item that matches the value, or the default value if no match is found
|
|
63
65
|
*/
|
|
64
|
-
function firstOrDefault<
|
|
66
|
+
export function firstOrDefault<
|
|
65
67
|
Item,
|
|
66
68
|
Callback extends (item: Item, index: number, array: Item[]) => unknown,
|
|
67
69
|
>(array: Item[], defaultValue: Item, callback: Callback, value: ReturnType<Callback>): Item;
|
|
68
70
|
|
|
69
71
|
/**
|
|
70
|
-
* Get the first item matching the given value by key
|
|
72
|
+
* Get the first item matching the given value by key, or a default value if no match is found
|
|
73
|
+
*
|
|
74
|
+
* Available as `firstOrDefault` and `first.default`
|
|
71
75
|
* @param array Array to search in
|
|
72
76
|
* @param defaultValue Default value to return if no match is found
|
|
73
77
|
* @param key Key to get an item's value for matching
|
|
74
78
|
* @param value Value to match against
|
|
75
79
|
* @returns First item that matches the value, or the default value if no match is found
|
|
76
80
|
*/
|
|
77
|
-
|
|
81
|
+
|
|
82
|
+
export function firstOrDefault<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
78
83
|
array: Item[],
|
|
79
84
|
defaultValue: Item,
|
|
80
85
|
key: ItemKey,
|
|
@@ -82,27 +87,31 @@ function firstOrDefault<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
|
82
87
|
): Item;
|
|
83
88
|
|
|
84
89
|
/**
|
|
85
|
-
* Get the first item matching the filter
|
|
90
|
+
* Get the first item matching the filter, or a default value if no match is found
|
|
91
|
+
*
|
|
92
|
+
* Available as `firstOrDefault` and `first.default`
|
|
86
93
|
* @param array Array to search in
|
|
87
94
|
* @param defaultValue Default value to return if no match is found
|
|
88
95
|
* @param filter Filter callback to match items
|
|
89
96
|
* @returns First item that matches the filter, or the default value if no match is found
|
|
90
97
|
*/
|
|
91
|
-
function firstOrDefault<Item>(
|
|
98
|
+
export function firstOrDefault<Item>(
|
|
92
99
|
array: Item[],
|
|
93
100
|
defaultValue: Item,
|
|
94
101
|
filter: (item: Item, index: number, array: Item[]) => boolean,
|
|
95
102
|
): Item;
|
|
96
103
|
|
|
97
104
|
/**
|
|
98
|
-
* Get the first item from an array
|
|
105
|
+
* Get the first item from an array, or a default value if the array is empty
|
|
106
|
+
*
|
|
107
|
+
* Available as `firstOrDefault` and `first.default`
|
|
99
108
|
* @param array Array to get from
|
|
100
109
|
* @param defaultValue Default value to return if the array is empty
|
|
101
110
|
* @return First item from the array, or the default value if the array is empty
|
|
102
111
|
*/
|
|
103
|
-
function firstOrDefault<Item>(array: Item[], defaultValue: Item): Item;
|
|
112
|
+
export function firstOrDefault<Item>(array: Item[], defaultValue: Item): Item;
|
|
104
113
|
|
|
105
|
-
function firstOrDefault(
|
|
114
|
+
export function firstOrDefault(
|
|
106
115
|
array: unknown[],
|
|
107
116
|
defaultValue: unknown,
|
|
108
117
|
...parameters: unknown[]
|
package/src/array/group-by.ts
CHANGED
|
@@ -120,12 +120,14 @@ groupBy.arrays = groupArraysBy;
|
|
|
120
120
|
|
|
121
121
|
/**
|
|
122
122
|
* Create a record from an array of items using a specific key and value, grouping values into arrays
|
|
123
|
+
*
|
|
124
|
+
* Available as `groupArraysBy` and `groupBy.arrays`
|
|
123
125
|
* @param array Array to group
|
|
124
126
|
* @param key Callback to get an item's grouping key
|
|
125
127
|
* @param value Callback to get an item's value
|
|
126
128
|
* @returns Record of keyed values
|
|
127
129
|
*/
|
|
128
|
-
function groupArraysBy<
|
|
130
|
+
export function groupArraysBy<
|
|
129
131
|
Item,
|
|
130
132
|
KeyCallback extends (item: Item, index: number, array: Item[]) => Key,
|
|
131
133
|
ValueCallback extends (item: Item, index: number, array: Item[]) => unknown,
|
|
@@ -137,12 +139,14 @@ function groupArraysBy<
|
|
|
137
139
|
|
|
138
140
|
/**
|
|
139
141
|
* Create a record from an array of items using a specific key and value, grouping values into arrays
|
|
142
|
+
*
|
|
143
|
+
* Available as `groupArraysBy` and `groupBy.arrays`
|
|
140
144
|
* @param array Array to group
|
|
141
145
|
* @param key Callback to get an item's grouping key
|
|
142
146
|
* @param value Key to use for value
|
|
143
147
|
* @returns Record of keyed values
|
|
144
148
|
*/
|
|
145
|
-
function groupArraysBy<
|
|
149
|
+
export function groupArraysBy<
|
|
146
150
|
Item extends PlainObject,
|
|
147
151
|
KeyCallback extends (item: Item, index: number, array: Item[]) => Key,
|
|
148
152
|
ItemValue extends keyof Item,
|
|
@@ -154,12 +158,14 @@ function groupArraysBy<
|
|
|
154
158
|
|
|
155
159
|
/**
|
|
156
160
|
* Create a record from an array of items using a specific key and value, grouping values into arrays
|
|
161
|
+
*
|
|
162
|
+
* Available as `groupArraysBy` and `groupBy.arrays`
|
|
157
163
|
* @param array Array to group
|
|
158
164
|
* @param key Key to use for grouping
|
|
159
165
|
* @param value Callback to get an item's value
|
|
160
166
|
* @returns Record of keyed values
|
|
161
167
|
*/
|
|
162
|
-
function groupArraysBy<
|
|
168
|
+
export function groupArraysBy<
|
|
163
169
|
Item extends PlainObject,
|
|
164
170
|
ItemKey extends keyof Item,
|
|
165
171
|
ValueCallback extends (item: Item, index: number, array: Item[]) => unknown,
|
|
@@ -171,12 +177,14 @@ function groupArraysBy<
|
|
|
171
177
|
|
|
172
178
|
/**
|
|
173
179
|
* Create a record from an array of items using a specific key and value, grouping values into arrays
|
|
180
|
+
*
|
|
181
|
+
* Available as `groupArraysBy` and `groupBy.arrays`
|
|
174
182
|
* @param array Array to group
|
|
175
183
|
* @param key Key to use for grouping
|
|
176
184
|
* @param value Key to use for value
|
|
177
185
|
* @returns Record of keyed values
|
|
178
186
|
*/
|
|
179
|
-
function groupArraysBy<
|
|
187
|
+
export function groupArraysBy<
|
|
180
188
|
Item extends PlainObject,
|
|
181
189
|
ItemKey extends keyof Item,
|
|
182
190
|
ItemValue extends keyof Item,
|
|
@@ -188,27 +196,31 @@ function groupArraysBy<
|
|
|
188
196
|
|
|
189
197
|
/**
|
|
190
198
|
* Create a record from an array of items using a specific key, grouping items into arrays
|
|
199
|
+
*
|
|
200
|
+
* Available as `groupArraysBy` and `groupBy.arrays`
|
|
191
201
|
* @param array Array to group
|
|
192
202
|
* @param callback Callback to get an item's grouping key
|
|
193
203
|
* @returns Record of keyed items
|
|
194
204
|
*/
|
|
195
|
-
function groupArraysBy<
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
): Record<ReturnType<Callback>, Item[]>;
|
|
205
|
+
export function groupArraysBy<
|
|
206
|
+
Item,
|
|
207
|
+
Callback extends (item: Item, index: number, array: Item[]) => Key,
|
|
208
|
+
>(array: Item[], callback: Callback): Record<ReturnType<Callback>, Item[]>;
|
|
199
209
|
|
|
200
210
|
/**
|
|
201
211
|
* Create a record from an array of items using a specific key, grouping items into arrays
|
|
212
|
+
*
|
|
213
|
+
* Available as `groupArraysBy` and `groupBy.arrays`
|
|
202
214
|
* @param array Array to group
|
|
203
215
|
* @param key Key to use for grouping
|
|
204
216
|
* @returns Record of keyed items
|
|
205
217
|
*/
|
|
206
|
-
function groupArraysBy<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
218
|
+
export function groupArraysBy<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
207
219
|
array: Item[],
|
|
208
220
|
key: ItemKey,
|
|
209
221
|
): Simplify<Record<KeyedValue<Item, ItemKey>, Item[]>>;
|
|
210
222
|
|
|
211
|
-
function groupArraysBy(array: unknown[], first?: unknown, second?: unknown): unknown {
|
|
223
|
+
export function groupArraysBy(array: unknown[], first?: unknown, second?: unknown): unknown {
|
|
212
224
|
return groupValues(array, first, second, true);
|
|
213
225
|
}
|
|
214
226
|
|