@oscarpalmer/atoms 0.76.0 → 0.77.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) 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/package.json +11 -4
  16. package/src/js/array/count.ts +7 -20
  17. package/src/js/array/exists.ts +7 -22
  18. package/src/js/array/filter.ts +7 -20
  19. package/src/js/array/find.ts +7 -20
  20. package/src/js/array/group-by.ts +19 -21
  21. package/src/js/array/index-of.ts +7 -20
  22. package/src/js/array/models.ts +2 -16
  23. package/src/js/array/sort.ts +3 -7
  24. package/src/js/array/to-map.ts +19 -21
  25. package/src/js/array/to-record.ts +17 -19
  26. package/src/js/array/unique.ts +8 -8
  27. package/src/js/internal/array/callbacks.ts +4 -4
  28. package/src/js/internal/array/find.ts +29 -6
  29. package/types/array/count.d.cts +2 -5
  30. package/types/array/count.d.ts +3 -3
  31. package/types/array/exists.d.cts +2 -5
  32. package/types/array/exists.d.ts +3 -3
  33. package/types/array/filter.d.cts +2 -5
  34. package/types/array/filter.d.ts +3 -3
  35. package/types/array/find.d.cts +2 -5
  36. package/types/array/find.d.ts +3 -3
  37. package/types/array/group-by.d.cts +8 -11
  38. package/types/array/group-by.d.ts +10 -11
  39. package/types/array/index-of.d.cts +2 -5
  40. package/types/array/index-of.d.ts +3 -3
  41. package/types/array/index.d.cts +43 -48
  42. package/types/array/models.d.cts +2 -7
  43. package/types/array/models.d.ts +2 -7
  44. package/types/array/sort.d.cts +3 -4
  45. package/types/array/sort.d.ts +3 -3
  46. package/types/array/to-map.d.cts +8 -11
  47. package/types/array/to-map.d.ts +9 -10
  48. package/types/array/to-record.d.cts +8 -11
  49. package/types/array/to-record.d.ts +9 -10
  50. package/types/array/unique.d.cts +3 -5
  51. package/types/array/unique.d.ts +4 -4
  52. package/types/index.d.cts +321 -1019
  53. package/types/internal/array/find.d.cts +2 -2
  54. package/types/internal/array/find.d.ts +2 -2
  55. package/types/models.d.cts +210 -467
  56. package/types/value/get.d.cts +210 -469
  57. package/types/value/index.d.cts +223 -514
  58. package/types/value/set.d.cts +169 -356
  59. package/types/value/smush.d.cts +209 -463
@@ -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
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.0"
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 as SimpleKey} from '~/models';
3
3
 
4
4
  /**
5
5
  * Get the number of items _(count)_ that match the given value
@@ -11,7 +11,7 @@ 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
  /**
@@ -26,24 +26,11 @@ export function count<Item, Key extends keyof Item>(
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
+ Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
32
+ >(array: Item[], key: Key, value: ReturnType<Key>): 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 as SimpleKey} from '~/models';
3
3
 
4
4
  /**
5
5
  * Does the value exist in array?
@@ -11,7 +11,7 @@ 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
  /**
@@ -28,26 +28,11 @@ export function exists<Item, Key extends keyof Item>(
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
+ Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
34
+ >(array: Item[], key: Key, value: ReturnType<Key>): 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 as SimpleKey} from '~/models';
3
3
 
4
4
  /**
5
5
  * Get a filtered array of items matching `value`
@@ -11,7 +11,7 @@ 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
  /**
@@ -28,24 +28,11 @@ export function filter<Item, Key extends keyof Item>(
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
+ Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
34
+ >(array: Item[], key: Key, value: ReturnType<Key>): 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 as SimpleKey} from '~/models';
3
3
 
4
4
  /**
5
5
  * Get the first item matching `value` _(or `undefined` if no match is found)_
@@ -11,7 +11,7 @@ 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
  /**
@@ -28,27 +28,14 @@ export function find<Item, Key extends keyof Item>(
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
+ Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
34
+ >(array: Item[], key: Key, value: ReturnType<Key>): 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
  }
@@ -1,6 +1,5 @@
1
- import type {KeyCallback, ValueCallback} from '~/array/models';
2
1
  import {getCallbacks} from '~/internal/array/callbacks';
3
- import type {Key, KeyedValue, PlainObject} from '~/models';
2
+ import type {Key as SimpleKey, KeyedValue, PlainObject} from '~/models';
4
3
 
5
4
  /**
6
5
  * Create a record from an array of items using a specific key
@@ -22,19 +21,18 @@ export function groupBy<Item, Key extends keyof Item>(
22
21
  /**
23
22
  * Create a record from an array of items using a specific key
24
23
  */
25
- export function groupBy<Item, Key extends KeyCallback<Item>>(
26
- array: Item[],
27
- key: Key,
28
- ): Record<ReturnType<Key>, Item>;
24
+ export function groupBy<
25
+ Item,
26
+ Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
27
+ >(array: Item[], key: Key): Record<ReturnType<Key>, Item>;
29
28
 
30
29
  /**
31
30
  * Create a record from an array of items using a specific key, and grouping them into arrays
32
31
  */
33
- export function groupBy<Item, Key extends KeyCallback<Item>>(
34
- array: Item[],
35
- key: Key,
36
- arrays: true,
37
- ): Record<ReturnType<Key>, Item[]>;
32
+ export function groupBy<
33
+ Item,
34
+ Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
35
+ >(array: Item[], key: Key, arrays: true): Record<ReturnType<Key>, Item[]>;
38
36
 
39
37
  /**
40
38
  * Create a record from an array of items using a specific key and value
@@ -61,7 +59,7 @@ export function groupBy<Item, Key extends keyof Item, Value extends keyof Item>(
61
59
  export function groupBy<
62
60
  Item,
63
61
  Key extends keyof Item,
64
- Value extends ValueCallback<Item>,
62
+ Value extends (item: Item, index: number, array: Item[]) => unknown,
65
63
  >(
66
64
  array: Item[],
67
65
  key: Key,
@@ -74,7 +72,7 @@ export function groupBy<
74
72
  export function groupBy<
75
73
  Item,
76
74
  Key extends keyof Item,
77
- Value extends ValueCallback<Item>,
75
+ Value extends (item: Item, index: number, array: Item[]) => unknown,
78
76
  >(
79
77
  array: Item[],
80
78
  key: Key,
@@ -87,7 +85,7 @@ export function groupBy<
87
85
  */
88
86
  export function groupBy<
89
87
  Item,
90
- Key extends KeyCallback<Item>,
88
+ Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
91
89
  Value extends keyof Item,
92
90
  >(
93
91
  array: Item[],
@@ -100,7 +98,7 @@ export function groupBy<
100
98
  */
101
99
  export function groupBy<
102
100
  Item,
103
- Key extends KeyCallback<Item>,
101
+ Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
104
102
  Value extends keyof Item,
105
103
  >(
106
104
  array: Item[],
@@ -114,8 +112,8 @@ export function groupBy<
114
112
  */
115
113
  export function groupBy<
116
114
  Item,
117
- Key extends KeyCallback<Item>,
118
- Value extends ValueCallback<Item>,
115
+ Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
116
+ Value extends (item: Item, index: number, array: Item[]) => unknown,
119
117
  >(
120
118
  array: Item[],
121
119
  key: Key,
@@ -127,8 +125,8 @@ export function groupBy<
127
125
  */
128
126
  export function groupBy<
129
127
  Item,
130
- Key extends KeyCallback<Item>,
131
- Value extends ValueCallback<Item>,
128
+ Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
129
+ Value extends (item: Item, index: number, array: Item[]) => unknown,
132
130
  >(
133
131
  array: Item[],
134
132
  key: Key,
@@ -155,9 +153,9 @@ export function groupValues(
155
153
  key: unknown,
156
154
  value: unknown,
157
155
  arrays: boolean,
158
- ): Record<Key, unknown> {
156
+ ): Record<SimpleKey, unknown> {
159
157
  const callbacks = getCallbacks(undefined, key, value);
160
- const record: Record<Key, unknown> = {};
158
+ const record: Record<SimpleKey, unknown> = {};
161
159
  const {length} = array;
162
160
 
163
161
  for (let index = 0; index < length; index += 1) {
@@ -1,5 +1,5 @@
1
- import type {BooleanCallback, KeyCallback} from '~/array/models';
2
1
  import {findValue} from '~/internal/array/find';
2
+ import type {Key as SimpleKey} from '~/models';
3
3
 
4
4
  /**
5
5
  * Get the index for the first item matching `value` _(or `-1` if no match is found)_
@@ -11,7 +11,7 @@ export function indexOf<Item>(array: Item[], value: Item): number;
11
11
  */
12
12
  export function indexOf<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
  /**
@@ -28,24 +28,11 @@ export function indexOf<Item, Key extends keyof Item>(
28
28
  * - Get the index for the first matching item _(or `-1` if no match is found)_
29
29
  * - Use `key` to find a comparison value to match with `value`
30
30
  */
31
- export function indexOf<Item, Key extends KeyCallback<Item>>(
32
- array: Item[],
33
- key: Key,
34
- value: ReturnType<Key>,
35
- ): number;
31
+ export function indexOf<
32
+ Item,
33
+ Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
34
+ >(array: Item[], key: Key, value: ReturnType<Key>): number;
36
35
 
37
36
  export function indexOf(array: unknown[], ...parameters: unknown[]): number {
38
- const {length} = parameters;
39
-
40
- return findValue(
41
- 'index',
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
- ) as number;
37
+ return findValue('index', array, parameters) as number;
51
38
  }
@@ -1,13 +1,5 @@
1
1
  import type {GenericCallback, Key} from '~/models';
2
2
 
3
- export type ArrayCallback<Item, Value> = (
4
- item: Item,
5
- index: number,
6
- array: Item[],
7
- ) => Value;
8
-
9
- export type BooleanCallback<Item> = ArrayCallback<Item, boolean>;
10
-
11
3
  export type Callbacks = {
12
4
  bool?: GenericCallback;
13
5
  key?: GenericCallback;
@@ -18,18 +10,12 @@ export type FindType = 'index' | 'value';
18
10
 
19
11
  export type InsertType = 'push' | 'splice';
20
12
 
21
- export type KeyCallback<Item> = ArrayCallback<Item, Key>;
22
-
23
13
  export type SortKey<Item> = {
24
14
  direction: 'asc' | 'desc';
25
- value: Key | SortKeyCallback<Item>;
15
+ value: Key | ((item: Item) => Key);
26
16
  };
27
17
 
28
- export type SortKeyCallback<Item> = (item: Item) => unknown;
29
-
30
18
  export type SortKeyWithCallback<Item> = {
31
- callback: SortKeyCallback<Item>;
19
+ callback: (item: Item) => Key;
32
20
  direction: 'asc' | 'desc';
33
21
  };
34
-
35
- export type ValueCallback<Item> = ArrayCallback<Item, unknown>;