@oscarpalmer/atoms 0.76.0 → 0.77.1

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 (70) hide show
  1. package/dist/js/array/count.cjs +1 -8
  2. package/dist/js/array/count.js +1 -8
  3. package/dist/js/array/exists.cjs +1 -8
  4. package/dist/js/array/exists.js +1 -8
  5. package/dist/js/array/filter.cjs +1 -8
  6. package/dist/js/array/filter.js +1 -8
  7. package/dist/js/array/find.cjs +1 -8
  8. package/dist/js/array/find.js +1 -8
  9. package/dist/js/array/index-of.cjs +1 -8
  10. package/dist/js/array/index-of.js +1 -8
  11. package/dist/js/array/unique.cjs +1 -1
  12. package/dist/js/array/unique.js +1 -1
  13. package/dist/js/internal/array/find.cjs +12 -2
  14. package/dist/js/internal/array/find.js +12 -2
  15. package/dist/js/value/equal.cjs +4 -1
  16. package/dist/js/value/equal.js +4 -1
  17. package/package.json +11 -4
  18. package/src/js/array/count.ts +10 -23
  19. package/src/js/array/exists.ts +10 -25
  20. package/src/js/array/filter.ts +10 -23
  21. package/src/js/array/find.ts +10 -23
  22. package/src/js/array/group-by.ts +66 -56
  23. package/src/js/array/index-of.ts +10 -23
  24. package/src/js/array/models.ts +2 -16
  25. package/src/js/array/sort.ts +23 -7
  26. package/src/js/array/to-map.ts +59 -53
  27. package/src/js/array/to-record.ts +63 -61
  28. package/src/js/array/unique.ts +10 -10
  29. package/src/js/internal/array/callbacks.ts +4 -4
  30. package/src/js/internal/array/find.ts +29 -6
  31. package/src/js/internal/value/handle.ts +5 -5
  32. package/src/js/value/clone.ts +3 -1
  33. package/src/js/value/equal.ts +4 -1
  34. package/src/js/value/get.ts +9 -9
  35. package/src/js/value/set.ts +10 -11
  36. package/types/array/count.d.cts +35 -6
  37. package/types/array/count.d.ts +4 -4
  38. package/types/array/exists.d.cts +35 -6
  39. package/types/array/exists.d.ts +4 -4
  40. package/types/array/filter.d.cts +35 -6
  41. package/types/array/filter.d.ts +4 -4
  42. package/types/array/find.d.cts +35 -6
  43. package/types/array/find.d.ts +4 -4
  44. package/types/array/group-by.d.cts +44 -15
  45. package/types/array/group-by.d.ts +13 -14
  46. package/types/array/index-of.d.cts +35 -6
  47. package/types/array/index-of.d.ts +4 -4
  48. package/types/array/index.d.cts +103 -66
  49. package/types/array/models.d.cts +2 -7
  50. package/types/array/models.d.ts +2 -7
  51. package/types/array/sort.d.cts +45 -4
  52. package/types/array/sort.d.ts +14 -4
  53. package/types/array/to-map.d.cts +44 -15
  54. package/types/array/to-map.d.ts +13 -14
  55. package/types/array/to-record.d.cts +44 -15
  56. package/types/array/to-record.d.ts +13 -14
  57. package/types/array/unique.d.cts +36 -6
  58. package/types/array/unique.d.ts +5 -5
  59. package/types/index.d.cts +280 -261
  60. package/types/internal/array/find.d.cts +2 -2
  61. package/types/internal/array/find.d.ts +2 -2
  62. package/types/internal/value/handle.d.cts +27 -2
  63. package/types/internal/value/handle.d.ts +2 -2
  64. package/types/value/clone.d.cts +1 -1
  65. package/types/value/clone.d.ts +1 -1
  66. package/types/value/get.d.cts +3 -3
  67. package/types/value/get.d.ts +3 -3
  68. package/types/value/index.d.cts +5 -5
  69. package/types/value/set.d.cts +3 -3
  70. package/types/value/set.d.ts +3 -3
@@ -2,13 +2,6 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const internal_array_find = require("../internal/array/find.cjs");
4
4
  function count(array, ...parameters) {
5
- const { length } = parameters;
6
- return internal_array_find.findValues(
7
- "all",
8
- array,
9
- length === 1 && typeof parameters[0] === "function" ? parameters[0] : void 0,
10
- length === 2 ? parameters[0] : void 0,
11
- length === 1 && typeof parameters[0] !== "function" ? parameters[0] : parameters[1]
12
- ).length;
5
+ return internal_array_find.findValues("all", array, parameters).length;
13
6
  }
14
7
  exports.count = count;
@@ -1,13 +1,6 @@
1
1
  import { findValues } from "../internal/array/find.js";
2
2
  function count(array, ...parameters) {
3
- const { length } = parameters;
4
- return findValues(
5
- "all",
6
- array,
7
- length === 1 && typeof parameters[0] === "function" ? parameters[0] : void 0,
8
- length === 2 ? parameters[0] : void 0,
9
- length === 1 && typeof parameters[0] !== "function" ? parameters[0] : parameters[1]
10
- ).length;
3
+ return findValues("all", array, parameters).length;
11
4
  }
12
5
  export {
13
6
  count
@@ -2,13 +2,6 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const internal_array_find = require("../internal/array/find.cjs");
4
4
  function exists(array, ...parameters) {
5
- const { length } = parameters;
6
- return internal_array_find.findValue(
7
- "index",
8
- array,
9
- length === 1 && typeof parameters[0] === "function" ? parameters[0] : void 0,
10
- length === 2 ? parameters[0] : void 0,
11
- length === 1 && typeof parameters[0] !== "function" ? parameters[0] : parameters[1]
12
- ) > -1;
5
+ return internal_array_find.findValue("index", array, parameters) > -1;
13
6
  }
14
7
  exports.exists = exists;
@@ -1,13 +1,6 @@
1
1
  import { findValue } from "../internal/array/find.js";
2
2
  function exists(array, ...parameters) {
3
- const { length } = parameters;
4
- return findValue(
5
- "index",
6
- array,
7
- length === 1 && typeof parameters[0] === "function" ? parameters[0] : void 0,
8
- length === 2 ? parameters[0] : void 0,
9
- length === 1 && typeof parameters[0] !== "function" ? parameters[0] : parameters[1]
10
- ) > -1;
3
+ return findValue("index", array, parameters) > -1;
11
4
  }
12
5
  export {
13
6
  exists
@@ -2,13 +2,6 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const internal_array_find = require("../internal/array/find.cjs");
4
4
  function filter(array, ...parameters) {
5
- const { length } = parameters;
6
- return internal_array_find.findValues(
7
- "all",
8
- array,
9
- length === 1 && typeof parameters[0] === "function" ? parameters[0] : void 0,
10
- length === 2 ? parameters[0] : void 0,
11
- length === 1 && typeof parameters[0] !== "function" ? parameters[0] : parameters[1]
12
- );
5
+ return internal_array_find.findValues("all", array, parameters);
13
6
  }
14
7
  exports.filter = filter;
@@ -1,13 +1,6 @@
1
1
  import { findValues } from "../internal/array/find.js";
2
2
  function filter(array, ...parameters) {
3
- const { length } = parameters;
4
- return findValues(
5
- "all",
6
- array,
7
- length === 1 && typeof parameters[0] === "function" ? parameters[0] : void 0,
8
- length === 2 ? parameters[0] : void 0,
9
- length === 1 && typeof parameters[0] !== "function" ? parameters[0] : parameters[1]
10
- );
3
+ return findValues("all", array, parameters);
11
4
  }
12
5
  export {
13
6
  filter
@@ -2,13 +2,6 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const internal_array_find = require("../internal/array/find.cjs");
4
4
  function find(array, ...parameters) {
5
- const { length } = parameters;
6
- return internal_array_find.findValue(
7
- "value",
8
- array,
9
- length === 1 && typeof parameters[0] === "function" ? parameters[0] : void 0,
10
- length === 2 ? parameters[0] : void 0,
11
- length === 1 && typeof parameters[0] !== "function" ? parameters[0] : parameters[1]
12
- );
5
+ return internal_array_find.findValue("value", array, parameters);
13
6
  }
14
7
  exports.find = find;
@@ -1,13 +1,6 @@
1
1
  import { findValue } from "../internal/array/find.js";
2
2
  function find(array, ...parameters) {
3
- const { length } = parameters;
4
- return findValue(
5
- "value",
6
- array,
7
- length === 1 && typeof parameters[0] === "function" ? parameters[0] : void 0,
8
- length === 2 ? parameters[0] : void 0,
9
- length === 1 && typeof parameters[0] !== "function" ? parameters[0] : parameters[1]
10
- );
3
+ return findValue("value", array, parameters);
11
4
  }
12
5
  export {
13
6
  find
@@ -2,13 +2,6 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const internal_array_find = require("../internal/array/find.cjs");
4
4
  function indexOf(array, ...parameters) {
5
- const { length } = parameters;
6
- return internal_array_find.findValue(
7
- "index",
8
- array,
9
- length === 1 && typeof parameters[0] === "function" ? parameters[0] : void 0,
10
- length === 2 ? parameters[0] : void 0,
11
- length === 1 && typeof parameters[0] !== "function" ? parameters[0] : parameters[1]
12
- );
5
+ return internal_array_find.findValue("index", array, parameters);
13
6
  }
14
7
  exports.indexOf = indexOf;
@@ -1,13 +1,6 @@
1
1
  import { findValue } from "../internal/array/find.js";
2
2
  function indexOf(array, ...parameters) {
3
- const { length } = parameters;
4
- return findValue(
5
- "index",
6
- array,
7
- length === 1 && typeof parameters[0] === "function" ? parameters[0] : void 0,
8
- length === 2 ? parameters[0] : void 0,
9
- length === 1 && typeof parameters[0] !== "function" ? parameters[0] : parameters[1]
10
- );
3
+ return findValue("index", array, parameters);
11
4
  }
12
5
  export {
13
6
  indexOf
@@ -2,6 +2,6 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const internal_array_find = require("../internal/array/find.cjs");
4
4
  function unique(array, key) {
5
- return internal_array_find.findValues("unique", array, void 0, key, void 0);
5
+ return internal_array_find.findValues("unique", array, [key, void 0]);
6
6
  }
7
7
  exports.unique = unique;
@@ -1,6 +1,6 @@
1
1
  import { findValues } from "../internal/array/find.js";
2
2
  function unique(array, key) {
3
- return findValues("unique", array, void 0, key, void 0);
3
+ return findValues("unique", array, [key, void 0]);
4
4
  }
5
5
  export {
6
6
  unique
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const internal_array_callbacks = require("./callbacks.cjs");
4
- function findValue(type, array, bool, key, value) {
4
+ function findValue(type, array, parameters) {
5
5
  var _a;
6
+ const { bool, key, value } = getParameters(parameters);
6
7
  const callbacks = internal_array_callbacks.getCallbacks(bool, key);
7
8
  if ((callbacks == null ? void 0 : callbacks.bool) == null && (callbacks == null ? void 0 : callbacks.key) == null) {
8
9
  return type === "index" ? array.findIndex((item) => item === value) : array.find((item) => item === value);
@@ -20,8 +21,9 @@ function findValue(type, array, bool, key, value) {
20
21
  }
21
22
  return type === "index" ? -1 : void 0;
22
23
  }
23
- function findValues(type, array, bool, key, value) {
24
+ function findValues(type, array, parameters) {
24
25
  var _a;
26
+ const { bool, key, value } = getParameters(parameters);
25
27
  const callbacks = internal_array_callbacks.getCallbacks(bool, key);
26
28
  const { length } = array;
27
29
  if (type === "unique" && (callbacks == null ? void 0 : callbacks.key) == null && length >= 100) {
@@ -47,5 +49,13 @@ function findValues(type, array, bool, key, value) {
47
49
  }
48
50
  return result;
49
51
  }
52
+ function getParameters(original) {
53
+ const { length } = original;
54
+ return {
55
+ bool: length === 1 && typeof original[0] === "function" ? original[0] : void 0,
56
+ key: length === 2 ? original[0] : void 0,
57
+ value: length === 1 && typeof original[0] !== "function" ? original[0] : original[1]
58
+ };
59
+ }
50
60
  exports.findValue = findValue;
51
61
  exports.findValues = findValues;
@@ -1,6 +1,7 @@
1
1
  import { getCallbacks } from "./callbacks.js";
2
- function findValue(type, array, bool, key, value) {
2
+ function findValue(type, array, parameters) {
3
3
  var _a;
4
+ const { bool, key, value } = getParameters(parameters);
4
5
  const callbacks = getCallbacks(bool, key);
5
6
  if ((callbacks == null ? void 0 : callbacks.bool) == null && (callbacks == null ? void 0 : callbacks.key) == null) {
6
7
  return type === "index" ? array.findIndex((item) => item === value) : array.find((item) => item === value);
@@ -18,8 +19,9 @@ function findValue(type, array, bool, key, value) {
18
19
  }
19
20
  return type === "index" ? -1 : void 0;
20
21
  }
21
- function findValues(type, array, bool, key, value) {
22
+ function findValues(type, array, parameters) {
22
23
  var _a;
24
+ const { bool, key, value } = getParameters(parameters);
23
25
  const callbacks = getCallbacks(bool, key);
24
26
  const { length } = array;
25
27
  if (type === "unique" && (callbacks == null ? void 0 : callbacks.key) == null && length >= 100) {
@@ -45,6 +47,14 @@ function findValues(type, array, bool, key, value) {
45
47
  }
46
48
  return result;
47
49
  }
50
+ function getParameters(original) {
51
+ const { length } = original;
52
+ return {
53
+ bool: length === 1 && typeof original[0] === "function" ? original[0] : void 0,
54
+ key: length === 2 ? original[0] : void 0,
55
+ value: length === 1 && typeof original[0] !== "function" ? original[0] : original[1]
56
+ };
57
+ }
48
58
  export {
49
59
  findValue,
50
60
  findValues
@@ -40,7 +40,10 @@ function equalArrayBuffer(first, second) {
40
40
  ) : false;
41
41
  }
42
42
  function equalDataView(first, second) {
43
- return first.byteOffset === second.byteOffset ? equalArrayBuffer(first.buffer, second.buffer) : false;
43
+ return first.byteOffset === second.byteOffset ? equalArrayBuffer(
44
+ first.buffer,
45
+ second.buffer
46
+ ) : false;
44
47
  }
45
48
  function equalMap(first, second) {
46
49
  const { size } = first;
@@ -38,7 +38,10 @@ function equalArrayBuffer(first, second) {
38
38
  ) : false;
39
39
  }
40
40
  function equalDataView(first, second) {
41
- return first.byteOffset === second.byteOffset ? equalArrayBuffer(first.buffer, second.buffer) : false;
41
+ return first.byteOffset === second.byteOffset ? equalArrayBuffer(
42
+ first.buffer,
43
+ second.buffer
44
+ ) : false;
42
45
  }
43
46
  function equalMap(first, second) {
44
47
  const { size } = first;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "url": "https://oscarpalmer.se"
5
5
  },
6
6
  "dependencies": {
7
- "type-fest": "^4.26.1"
7
+ "type-fest": "^4.26"
8
8
  },
9
9
  "description": "Sweet little atomic goodies…",
10
10
  "devDependencies": {
@@ -208,8 +208,15 @@
208
208
  }
209
209
  }
210
210
  },
211
- "files": ["dist", "src", "types"],
212
- "keywords": ["helper", "utility"],
211
+ "files": [
212
+ "dist",
213
+ "src",
214
+ "types"
215
+ ],
216
+ "keywords": [
217
+ "helper",
218
+ "utility"
219
+ ],
213
220
  "license": "MIT",
214
221
  "main": "./dist/js/index.cjs",
215
222
  "module": "./dist/js/index.js",
@@ -230,5 +237,5 @@
230
237
  },
231
238
  "type": "module",
232
239
  "types": "./types/index.d.cts",
233
- "version": "0.76.0"
240
+ "version": "0.77.1"
234
241
  }
@@ -1,5 +1,5 @@
1
1
  import {findValues} from '~/internal/array/find';
2
- import type {BooleanCallback, KeyCallback} from '~/array/models';
2
+ import type {Key, PlainObject} from '~/models';
3
3
 
4
4
  /**
5
5
  * Get the number of items _(count)_ that match the given value
@@ -11,39 +11,26 @@ export function count<Item>(array: Item[], value: Item): number;
11
11
  */
12
12
  export function count<Item>(
13
13
  array: Item[],
14
- matches: BooleanCallback<Item>,
14
+ matches: (item: Item, index: number, array: Item[]) => boolean,
15
15
  ): number;
16
16
 
17
17
  /**
18
18
  * Get the number of items _(count)_ that match the given value
19
19
  */
20
- export function count<Item, Key extends keyof Item>(
20
+ export function count<Item extends PlainObject, ItemKey extends keyof Item>(
21
21
  array: Item[],
22
- key: Key,
23
- value: Item[Key],
22
+ key: ItemKey,
23
+ value: Item[ItemKey],
24
24
  ): number;
25
25
 
26
26
  /**
27
27
  * Get the number of items _(count)_ that match the given value
28
28
  */
29
- export function count<Item, Key extends KeyCallback<Item>>(
30
- array: Item[],
31
- key: Key,
32
- value: ReturnType<Key>,
33
- ): number;
29
+ export function count<
30
+ Item,
31
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
32
+ >(array: Item[], key: ItemKey, value: ReturnType<ItemKey>): number;
34
33
 
35
34
  export function count(array: unknown[], ...parameters: unknown[]): number {
36
- const {length} = parameters;
37
-
38
- return findValues(
39
- 'all',
40
- array,
41
- length === 1 && typeof parameters[0] === 'function'
42
- ? parameters[0]
43
- : undefined,
44
- length === 2 ? parameters[0] : undefined,
45
- length === 1 && typeof parameters[0] !== 'function'
46
- ? parameters[0]
47
- : parameters[1],
48
- ).length;
35
+ return findValues('all', array, parameters).length;
49
36
  }
@@ -1,5 +1,5 @@
1
1
  import {findValue} from '~/internal/array/find';
2
- import type {BooleanCallback, KeyCallback} from './models';
2
+ import type {Key, PlainObject} from '~/models';
3
3
 
4
4
  /**
5
5
  * Does the value exist in array?
@@ -11,43 +11,28 @@ export function exists<Item>(array: Item[], value: Item): boolean;
11
11
  */
12
12
  export function exists<Item>(
13
13
  array: Item[],
14
- matches: BooleanCallback<Item>,
14
+ matches: (item: Item, index: number, array: Item[]) => boolean,
15
15
  ): boolean;
16
16
 
17
17
  /**
18
18
  * - Does the value exist in array?
19
19
  * - Use `key` to find a comparison value to match with `value`
20
20
  */
21
- export function exists<Item, Key extends keyof Item>(
21
+ export function exists<Item extends PlainObject, ItemKey extends keyof Item>(
22
22
  array: Item[],
23
- key: Key,
24
- value: Item[Key],
23
+ key: ItemKey,
24
+ value: Item[ItemKey],
25
25
  ): boolean;
26
26
 
27
27
  /**
28
28
  * - Does the value exist in array?
29
29
  * - Use `key` to find a comparison value to match with `value`
30
30
  */
31
- export function exists<Item, Key extends KeyCallback<Item>>(
32
- array: Item[],
33
- key: Key,
34
- value: ReturnType<Key>,
35
- ): boolean;
31
+ export function exists<
32
+ Item,
33
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
34
+ >(array: Item[], key: ItemKey, value: ReturnType<ItemKey>): boolean;
36
35
 
37
36
  export function exists(array: unknown[], ...parameters: unknown[]): boolean {
38
- const {length} = parameters;
39
-
40
- return (
41
- (findValue(
42
- 'index',
43
- array,
44
- length === 1 && typeof parameters[0] === 'function'
45
- ? parameters[0]
46
- : undefined,
47
- length === 2 ? parameters[0] : undefined,
48
- length === 1 && typeof parameters[0] !== 'function'
49
- ? parameters[0]
50
- : parameters[1],
51
- ) as number) > -1
52
- );
37
+ return (findValue('index', array, parameters) as number) > -1;
53
38
  }
@@ -1,5 +1,5 @@
1
- import type {BooleanCallback, KeyCallback} from '~/array/models';
2
1
  import {findValues} from '~/internal/array/find';
2
+ import type {Key, PlainObject} from '~/models';
3
3
 
4
4
  /**
5
5
  * Get a filtered array of items matching `value`
@@ -11,41 +11,28 @@ export function filter<Item>(array: Item[], value: Item): Item[];
11
11
  */
12
12
  export function filter<Item>(
13
13
  array: Item[],
14
- matches: BooleanCallback<Item>,
14
+ matches: (item: Item, index: number, array: Item[]) => boolean,
15
15
  ): Item[];
16
16
 
17
17
  /**
18
18
  * - Get a filtered array of items
19
19
  * - Use `key` to find a comparison value to match with `value`
20
20
  */
21
- export function filter<Item, Key extends keyof Item>(
21
+ export function filter<Item extends PlainObject, ItemKey extends keyof Item>(
22
22
  array: Item[],
23
- key: Key,
24
- value: Item[Key],
23
+ key: ItemKey,
24
+ value: Item[ItemKey],
25
25
  ): Item[];
26
26
 
27
27
  /**
28
28
  * - Get a filtered array of items
29
29
  * - Use `key` to find a comparison value to match with `value`
30
30
  */
31
- export function filter<Item, Key extends KeyCallback<Item>>(
32
- array: Item[],
33
- key: Key,
34
- value: ReturnType<Key>,
35
- ): Item[];
31
+ export function filter<
32
+ Item,
33
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
34
+ >(array: Item[], key: ItemKey, value: ReturnType<ItemKey>): Item[];
36
35
 
37
36
  export function filter(array: unknown[], ...parameters: unknown[]): unknown[] {
38
- const {length} = parameters;
39
-
40
- return findValues(
41
- 'all',
42
- array,
43
- length === 1 && typeof parameters[0] === 'function'
44
- ? parameters[0]
45
- : undefined,
46
- length === 2 ? parameters[0] : undefined,
47
- length === 1 && typeof parameters[0] !== 'function'
48
- ? parameters[0]
49
- : parameters[1],
50
- );
37
+ return findValues('all', array, parameters);
51
38
  }
@@ -1,5 +1,5 @@
1
- import type {BooleanCallback, KeyCallback} from '~/array/models';
2
1
  import {findValue} from '~/internal/array/find';
2
+ import type {Key, PlainObject} from '~/models';
3
3
 
4
4
  /**
5
5
  * Get the first item matching `value` _(or `undefined` if no match is found)_
@@ -11,44 +11,31 @@ export function find<Item>(array: Item[], value: Item): Item | undefined;
11
11
  */
12
12
  export function find<Item>(
13
13
  array: Item[],
14
- matches: BooleanCallback<Item>,
14
+ matches: (item: Item, index: number, array: Item[]) => boolean,
15
15
  ): Item | undefined;
16
16
 
17
17
  /**
18
18
  * - Get the first matching item _(or `undefined` if no match is found)_
19
19
  * - Use `key` to find a comparison value to match with `value`
20
20
  */
21
- export function find<Item, Key extends keyof Item>(
21
+ export function find<Item extends PlainObject, ItemKey extends keyof Item>(
22
22
  array: Item[],
23
- key: Key,
24
- value: Item[Key],
23
+ key: ItemKey,
24
+ value: Item[ItemKey],
25
25
  ): Item | undefined;
26
26
 
27
27
  /**
28
28
  * - Get the first matching item _(or `undefined` if no match is found)_
29
29
  * - Use `key` to find a comparison value to match with `value`
30
30
  */
31
- export function find<Item, Key extends KeyCallback<Item>>(
32
- array: Item[],
33
- key: Key,
34
- value: ReturnType<Key>,
35
- ): Item | undefined;
31
+ export function find<
32
+ Item,
33
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
34
+ >(array: Item[], key: ItemKey, value: ReturnType<ItemKey>): Item | undefined;
36
35
 
37
36
  export function find<Item>(
38
37
  array: unknown[],
39
38
  ...parameters: unknown[]
40
39
  ): Item | undefined {
41
- const {length} = parameters;
42
-
43
- return findValue(
44
- 'value',
45
- array,
46
- length === 1 && typeof parameters[0] === 'function'
47
- ? parameters[0]
48
- : undefined,
49
- length === 2 ? parameters[0] : undefined,
50
- length === 1 && typeof parameters[0] !== 'function'
51
- ? parameters[0]
52
- : parameters[1],
53
- ) as Item | undefined;
40
+ return findValue('value', array, parameters) as Item | undefined;
54
41
  }