es-toolkit 1.29.0-dev.931 → 1.29.0-dev.932

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.
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Maps each element in a readonly array to a new array of values using an iteratee function.
3
+ *
4
+ * @param {readonly T[]} collection - The collection to iterate over.
5
+ * @param {(value: T, index: number, collection: readonly T[]) => U} iteratee - The function invoked per iteration.
6
+ * @returns {U[]} - Returns the new mapped array.
7
+ *
8
+ * @example
9
+ * const array = [1, 2, 3];
10
+ * map(array, value => value * 2); // => [2, 4, 6]
11
+ */
12
+ declare function map<T, U>(collection: readonly T[], iteratee: (value: T, index: number, collection: readonly T[]) => U): U[];
13
+ /**
14
+ * Maps each element in a readonly array to a boolean array based on a partial object match.
15
+ *
16
+ * @param {readonly T[]} collection - The collection to iterate over.
17
+ * @param {Partial<T>} iteratee - The partial object to match against each element.
18
+ * @returns {boolean[]} - Returns an array of booleans indicating matches.
19
+ *
20
+ * @example
21
+ * const objects = [{ a: 1 }, { a: 2 }, { a: 3 }];
22
+ * map(objects, { a: 1 }); // => [true, false, false]
23
+ */
24
+ declare function map<T>(collection: readonly T[], iteratee: Partial<T>): boolean[];
25
+ /**
26
+ * Maps each element in a readonly array to a boolean array based on a property-value pair match.
27
+ *
28
+ * @param {readonly T[]} collection - The collection to iterate over.
29
+ * @param {[keyof T, unknown]} iteratee - The property-value pair to match against each element.
30
+ * @returns {boolean[]} - Returns an array of booleans indicating matches.
31
+ *
32
+ * @example
33
+ * const objects = [{ a: 1 }, { a: 2 }, { a: 3 }];
34
+ * map(objects, ['a', 1]); // => [true, false, false]
35
+ */
36
+ declare function map<T>(collection: readonly T[], iteratee: [keyof T, unknown]): boolean[];
37
+ /**
38
+ * Maps each element in a readonly array to an array of property values.
39
+ *
40
+ * @param {readonly T[]} collection - The collection to iterate over.
41
+ * @param {K} iteratee - The key of the property to extract from each element.
42
+ * @returns {Array<T[K]>} - Returns an array of property values.
43
+ *
44
+ * @example
45
+ * const objects = [{ a: 1 }, { a: 2 }, { a: 3 }];
46
+ * map(objects, 'a'); // => [1, 2, 3]
47
+ */
48
+ declare function map<T, K extends keyof T>(collection: readonly T[], iteratee: K): Array<T[K]>;
49
+ /**
50
+ * Maps each element in a readonly array to itself if no iteratee is provided.
51
+ *
52
+ * @param {readonly T[]} collection - The collection to iterate over.
53
+ * @param {null | undefined} [iteratee] - Optional iteratee.
54
+ * @returns {T[]} - Returns the original array.
55
+ *
56
+ * @example
57
+ * const numbers = [1, 2, 3];
58
+ * map(numbers); // => [1, 2, 3]
59
+ */
60
+ declare function map<T>(collection: readonly T[], iteratee?: null | undefined): T[];
61
+ /**
62
+ * Maps each element in an ArrayLike object to a new array of values using an iteratee function.
63
+ *
64
+ * @param {ArrayLike<T>} collection - The collection to iterate over.
65
+ * @param {(value: T, index: number, collection: ArrayLike<T>) => U} iteratee - The function invoked per iteration.
66
+ * @returns {U[]} - Returns the new mapped array.
67
+ *
68
+ * @example
69
+ * const arrayLike = {0: 1, 1: 2, 2: 3, length: 3};
70
+ * map(arrayLike, value => value * 2); // => [2, 4, 6]
71
+ */
72
+ declare function map<T, U>(collection: ArrayLike<T>, iteratee: (value: T, index: number, collection: ArrayLike<T>) => U): U[];
73
+ /**
74
+ * Maps each element in an ArrayLike object to a boolean array based on a partial object match.
75
+ *
76
+ * @param {ArrayLike<T>} collection - The collection to iterate over.
77
+ * @param {Partial<T>} iteratee - The partial object to match against each element.
78
+ * @returns {boolean[]} - Returns an array of booleans indicating matches.
79
+ *
80
+ * @example
81
+ * const arrayLike = [{ a: 1 }, { a: 2 }, { a: 3 }];
82
+ * map(arrayLike, { a: 1 }); // => [true, false, false]
83
+ */
84
+ declare function map<T>(collection: ArrayLike<T>, iteratee: Partial<T>): boolean[];
85
+ /**
86
+ * Maps each element in an ArrayLike object to a boolean array based on a property-value pair match.
87
+ *
88
+ * @param {ArrayLike<T>} collection - The collection to iterate over.
89
+ * @param {[keyof T, unknown]} iteratee - The property-value pair to match against each element.
90
+ * @returns {boolean[]} - Returns an array of booleans indicating matches.
91
+ *
92
+ * @example
93
+ * const arrayLike = [{ a: 1 }, { a: 2 }, { a: 3 }];
94
+ * map(arrayLike, ['a', 1]); // => [true, false, false]
95
+ */
96
+ declare function map<T>(collection: ArrayLike<T>, iteratee: [keyof T, unknown]): boolean[];
97
+ /**
98
+ * Maps each element in an ArrayLike object to an array of property values.
99
+ *
100
+ * @param {ArrayLike<T>} collection - The collection to iterate over.
101
+ * @param {K} iteratee - The key of the property to extract from each element.
102
+ * @returns {Array<T[K]>} - Returns an array of property values.
103
+ *
104
+ * @example
105
+ * const arrayLike = [{ a: 1 }, { a: 2 }, { a: 3 }];
106
+ * map(arrayLike, 'a'); // => [1, 2, 3]
107
+ */
108
+ declare function map<T, K extends keyof T>(collection: ArrayLike<T>, iteratee: K): Array<T[K]>;
109
+ /**
110
+ * Maps each element in an ArrayLike object to itself if no iteratee is provided.
111
+ *
112
+ * @param {ArrayLike<T>} collection - The collection to iterate over.
113
+ * @param {null | undefined} [iteratee] - Optional iteratee.
114
+ * @returns {ArrayLike<T>} - Returns the original ArrayLike object.
115
+ *
116
+ * @example
117
+ * const arrayLike = {0: 1, 1: 2, 2: 3, length: 3};
118
+ * map(arrayLike); // => {0: 1, 1: 2, 2: 3, length: 3}
119
+ */
120
+ declare function map<T, U>(collection: ArrayLike<T>, iteratee?: null | undefined): ArrayLike<T>;
121
+ /**
122
+ * Maps each value in an object to a new array of values using an iteratee function.
123
+ *
124
+ * @param {T} collection - The object to iterate over.
125
+ * @param {(value: T[keyof T], key: string, collection: T) => U} iteratee - The function invoked per iteration.
126
+ * @returns {U[]} - Returns the new mapped array.
127
+ *
128
+ * @example
129
+ * const obj = { a: 1, b: 2, c: 3 };
130
+ * map(obj, (value, key) => `${key}: ${value}`); // => ['a: 1', 'b: 2', 'c: 3']
131
+ */
132
+ declare function map<T extends object, U>(collection: T, iteratee: (value: T[keyof T], key: string, collection: T) => U): U[];
133
+ /**
134
+ * Maps each value in an object to a boolean array based on a partial object match.
135
+ *
136
+ * @param {T} object - The object to iterate over.
137
+ * @param {Partial<T[keyof T]>} iteratee - The partial object to match against each value.
138
+ * @returns {boolean[]} - Returns an array of booleans indicating matches.
139
+ *
140
+ * @example
141
+ * const obj = { a: { x: 1 }, b: { x: 2 }, c: { x: 3 } };
142
+ * map(obj, { x: 1 }); // => [true, false, false]
143
+ */
144
+ declare function map<T>(object: T, iteratee: Partial<T[keyof T]>): boolean[];
145
+ /**
146
+ * Maps each value in an object to a boolean array based on a property-value pair match.
147
+ *
148
+ * @param {T} object - The object to iterate over.
149
+ * @param {[keyof T[keyof T], unknown]} iteratee - The property-value pair to match against each value.
150
+ * @returns {boolean[]} - Returns an array of booleans indicating matches.
151
+ *
152
+ * @example
153
+ * const obj = { a: { x: 1 }, b: { x: 2 }, c: { x: 3 } };
154
+ * map(obj, ['x', 1]); // => [true, false, false]
155
+ */
156
+ declare function map<T>(object: T, iteratee: [keyof T[keyof T], unknown]): boolean[];
157
+ /**
158
+ * Maps each value in an object to an array of property values.
159
+ *
160
+ * @param {T} object - The object to iterate over.
161
+ * @param {K} iteratee - The key of the property to extract from each value.
162
+ * @returns {Array<T[keyof T][K]>} - Returns an array of property values.
163
+ *
164
+ * @example
165
+ * const obj = { a: { x: 1 }, b: { x: 2 }, c: { x: 3 } };
166
+ * map(obj, 'x'); // => [1, 2, 3]
167
+ */
168
+ declare function map<T, K extends keyof T[keyof T]>(object: T, iteratee: K): Array<T[keyof T][K]>;
169
+ /**
170
+ * Maps each value in an object to itself if no iteratee is provided.
171
+ *
172
+ * @param {T} object - The object to iterate over.
173
+ * @param {null | undefined} [iteratee] - Optional iteratee.
174
+ * @returns {U[]} - Returns the original object values as an array.
175
+ *
176
+ * @example
177
+ * const obj = { a: 1, b: 2, c: 3 };
178
+ * map(obj); // => [1, 2, 3]
179
+ */
180
+ declare function map<T extends object, U>(object: T, iteratee?: null | undefined): U[];
181
+
182
+ export { map };
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Maps each element in a readonly array to a new array of values using an iteratee function.
3
+ *
4
+ * @param {readonly T[]} collection - The collection to iterate over.
5
+ * @param {(value: T, index: number, collection: readonly T[]) => U} iteratee - The function invoked per iteration.
6
+ * @returns {U[]} - Returns the new mapped array.
7
+ *
8
+ * @example
9
+ * const array = [1, 2, 3];
10
+ * map(array, value => value * 2); // => [2, 4, 6]
11
+ */
12
+ declare function map<T, U>(collection: readonly T[], iteratee: (value: T, index: number, collection: readonly T[]) => U): U[];
13
+ /**
14
+ * Maps each element in a readonly array to a boolean array based on a partial object match.
15
+ *
16
+ * @param {readonly T[]} collection - The collection to iterate over.
17
+ * @param {Partial<T>} iteratee - The partial object to match against each element.
18
+ * @returns {boolean[]} - Returns an array of booleans indicating matches.
19
+ *
20
+ * @example
21
+ * const objects = [{ a: 1 }, { a: 2 }, { a: 3 }];
22
+ * map(objects, { a: 1 }); // => [true, false, false]
23
+ */
24
+ declare function map<T>(collection: readonly T[], iteratee: Partial<T>): boolean[];
25
+ /**
26
+ * Maps each element in a readonly array to a boolean array based on a property-value pair match.
27
+ *
28
+ * @param {readonly T[]} collection - The collection to iterate over.
29
+ * @param {[keyof T, unknown]} iteratee - The property-value pair to match against each element.
30
+ * @returns {boolean[]} - Returns an array of booleans indicating matches.
31
+ *
32
+ * @example
33
+ * const objects = [{ a: 1 }, { a: 2 }, { a: 3 }];
34
+ * map(objects, ['a', 1]); // => [true, false, false]
35
+ */
36
+ declare function map<T>(collection: readonly T[], iteratee: [keyof T, unknown]): boolean[];
37
+ /**
38
+ * Maps each element in a readonly array to an array of property values.
39
+ *
40
+ * @param {readonly T[]} collection - The collection to iterate over.
41
+ * @param {K} iteratee - The key of the property to extract from each element.
42
+ * @returns {Array<T[K]>} - Returns an array of property values.
43
+ *
44
+ * @example
45
+ * const objects = [{ a: 1 }, { a: 2 }, { a: 3 }];
46
+ * map(objects, 'a'); // => [1, 2, 3]
47
+ */
48
+ declare function map<T, K extends keyof T>(collection: readonly T[], iteratee: K): Array<T[K]>;
49
+ /**
50
+ * Maps each element in a readonly array to itself if no iteratee is provided.
51
+ *
52
+ * @param {readonly T[]} collection - The collection to iterate over.
53
+ * @param {null | undefined} [iteratee] - Optional iteratee.
54
+ * @returns {T[]} - Returns the original array.
55
+ *
56
+ * @example
57
+ * const numbers = [1, 2, 3];
58
+ * map(numbers); // => [1, 2, 3]
59
+ */
60
+ declare function map<T>(collection: readonly T[], iteratee?: null | undefined): T[];
61
+ /**
62
+ * Maps each element in an ArrayLike object to a new array of values using an iteratee function.
63
+ *
64
+ * @param {ArrayLike<T>} collection - The collection to iterate over.
65
+ * @param {(value: T, index: number, collection: ArrayLike<T>) => U} iteratee - The function invoked per iteration.
66
+ * @returns {U[]} - Returns the new mapped array.
67
+ *
68
+ * @example
69
+ * const arrayLike = {0: 1, 1: 2, 2: 3, length: 3};
70
+ * map(arrayLike, value => value * 2); // => [2, 4, 6]
71
+ */
72
+ declare function map<T, U>(collection: ArrayLike<T>, iteratee: (value: T, index: number, collection: ArrayLike<T>) => U): U[];
73
+ /**
74
+ * Maps each element in an ArrayLike object to a boolean array based on a partial object match.
75
+ *
76
+ * @param {ArrayLike<T>} collection - The collection to iterate over.
77
+ * @param {Partial<T>} iteratee - The partial object to match against each element.
78
+ * @returns {boolean[]} - Returns an array of booleans indicating matches.
79
+ *
80
+ * @example
81
+ * const arrayLike = [{ a: 1 }, { a: 2 }, { a: 3 }];
82
+ * map(arrayLike, { a: 1 }); // => [true, false, false]
83
+ */
84
+ declare function map<T>(collection: ArrayLike<T>, iteratee: Partial<T>): boolean[];
85
+ /**
86
+ * Maps each element in an ArrayLike object to a boolean array based on a property-value pair match.
87
+ *
88
+ * @param {ArrayLike<T>} collection - The collection to iterate over.
89
+ * @param {[keyof T, unknown]} iteratee - The property-value pair to match against each element.
90
+ * @returns {boolean[]} - Returns an array of booleans indicating matches.
91
+ *
92
+ * @example
93
+ * const arrayLike = [{ a: 1 }, { a: 2 }, { a: 3 }];
94
+ * map(arrayLike, ['a', 1]); // => [true, false, false]
95
+ */
96
+ declare function map<T>(collection: ArrayLike<T>, iteratee: [keyof T, unknown]): boolean[];
97
+ /**
98
+ * Maps each element in an ArrayLike object to an array of property values.
99
+ *
100
+ * @param {ArrayLike<T>} collection - The collection to iterate over.
101
+ * @param {K} iteratee - The key of the property to extract from each element.
102
+ * @returns {Array<T[K]>} - Returns an array of property values.
103
+ *
104
+ * @example
105
+ * const arrayLike = [{ a: 1 }, { a: 2 }, { a: 3 }];
106
+ * map(arrayLike, 'a'); // => [1, 2, 3]
107
+ */
108
+ declare function map<T, K extends keyof T>(collection: ArrayLike<T>, iteratee: K): Array<T[K]>;
109
+ /**
110
+ * Maps each element in an ArrayLike object to itself if no iteratee is provided.
111
+ *
112
+ * @param {ArrayLike<T>} collection - The collection to iterate over.
113
+ * @param {null | undefined} [iteratee] - Optional iteratee.
114
+ * @returns {ArrayLike<T>} - Returns the original ArrayLike object.
115
+ *
116
+ * @example
117
+ * const arrayLike = {0: 1, 1: 2, 2: 3, length: 3};
118
+ * map(arrayLike); // => {0: 1, 1: 2, 2: 3, length: 3}
119
+ */
120
+ declare function map<T, U>(collection: ArrayLike<T>, iteratee?: null | undefined): ArrayLike<T>;
121
+ /**
122
+ * Maps each value in an object to a new array of values using an iteratee function.
123
+ *
124
+ * @param {T} collection - The object to iterate over.
125
+ * @param {(value: T[keyof T], key: string, collection: T) => U} iteratee - The function invoked per iteration.
126
+ * @returns {U[]} - Returns the new mapped array.
127
+ *
128
+ * @example
129
+ * const obj = { a: 1, b: 2, c: 3 };
130
+ * map(obj, (value, key) => `${key}: ${value}`); // => ['a: 1', 'b: 2', 'c: 3']
131
+ */
132
+ declare function map<T extends object, U>(collection: T, iteratee: (value: T[keyof T], key: string, collection: T) => U): U[];
133
+ /**
134
+ * Maps each value in an object to a boolean array based on a partial object match.
135
+ *
136
+ * @param {T} object - The object to iterate over.
137
+ * @param {Partial<T[keyof T]>} iteratee - The partial object to match against each value.
138
+ * @returns {boolean[]} - Returns an array of booleans indicating matches.
139
+ *
140
+ * @example
141
+ * const obj = { a: { x: 1 }, b: { x: 2 }, c: { x: 3 } };
142
+ * map(obj, { x: 1 }); // => [true, false, false]
143
+ */
144
+ declare function map<T>(object: T, iteratee: Partial<T[keyof T]>): boolean[];
145
+ /**
146
+ * Maps each value in an object to a boolean array based on a property-value pair match.
147
+ *
148
+ * @param {T} object - The object to iterate over.
149
+ * @param {[keyof T[keyof T], unknown]} iteratee - The property-value pair to match against each value.
150
+ * @returns {boolean[]} - Returns an array of booleans indicating matches.
151
+ *
152
+ * @example
153
+ * const obj = { a: { x: 1 }, b: { x: 2 }, c: { x: 3 } };
154
+ * map(obj, ['x', 1]); // => [true, false, false]
155
+ */
156
+ declare function map<T>(object: T, iteratee: [keyof T[keyof T], unknown]): boolean[];
157
+ /**
158
+ * Maps each value in an object to an array of property values.
159
+ *
160
+ * @param {T} object - The object to iterate over.
161
+ * @param {K} iteratee - The key of the property to extract from each value.
162
+ * @returns {Array<T[keyof T][K]>} - Returns an array of property values.
163
+ *
164
+ * @example
165
+ * const obj = { a: { x: 1 }, b: { x: 2 }, c: { x: 3 } };
166
+ * map(obj, 'x'); // => [1, 2, 3]
167
+ */
168
+ declare function map<T, K extends keyof T[keyof T]>(object: T, iteratee: K): Array<T[keyof T][K]>;
169
+ /**
170
+ * Maps each value in an object to itself if no iteratee is provided.
171
+ *
172
+ * @param {T} object - The object to iterate over.
173
+ * @param {null | undefined} [iteratee] - Optional iteratee.
174
+ * @returns {U[]} - Returns the original object values as an array.
175
+ *
176
+ * @example
177
+ * const obj = { a: 1, b: 2, c: 3 };
178
+ * map(obj); // => [1, 2, 3]
179
+ */
180
+ declare function map<T extends object, U>(object: T, iteratee?: null | undefined): U[];
181
+
182
+ export { map };
@@ -0,0 +1,21 @@
1
+ import { identity } from '../../function/identity.mjs';
2
+ import { range } from '../../math/range.mjs';
3
+ import { isArrayLike } from '../predicate/isArrayLike.mjs';
4
+ import { iteratee } from '../util/iteratee.mjs';
5
+
6
+ function map(collection, _iteratee) {
7
+ if (!collection) {
8
+ return [];
9
+ }
10
+ const keys = isArrayLike(collection) || Array.isArray(collection) ? range(0, collection.length) : Object.keys(collection);
11
+ const iteratee$1 = iteratee(_iteratee ?? identity);
12
+ const result = new Array(keys.length);
13
+ for (let i = 0; i < keys.length; i++) {
14
+ const key = keys[i];
15
+ const value = collection[key];
16
+ result[i] = iteratee$1(value, key, collection);
17
+ }
18
+ return result;
19
+ }
20
+
21
+ export { map };
@@ -104,6 +104,7 @@ export { intersectionBy } from './array/intersectionBy.mjs';
104
104
  export { join } from './array/join.mjs';
105
105
  export { last } from './array/last.mjs';
106
106
  export { lastIndexOf } from './array/lastIndexOf.mjs';
107
+ export { map } from './array/map.mjs';
107
108
  export { nth } from './array/nth.mjs';
108
109
  export { orderBy } from './array/orderBy.mjs';
109
110
  export { pull } from './array/pull.mjs';
@@ -104,6 +104,7 @@ export { intersectionBy } from './array/intersectionBy.js';
104
104
  export { join } from './array/join.js';
105
105
  export { last } from './array/last.js';
106
106
  export { lastIndexOf } from './array/lastIndexOf.js';
107
+ export { map } from './array/map.js';
107
108
  export { nth } from './array/nth.js';
108
109
  export { orderBy } from './array/orderBy.js';
109
110
  export { pull } from './array/pull.js';
@@ -1008,6 +1008,21 @@ function lastIndexOf(array, searchElement, fromIndex) {
1008
1008
  return Array.from(array).lastIndexOf(searchElement, index);
1009
1009
  }
1010
1010
 
1011
+ function map(collection, _iteratee) {
1012
+ if (!collection) {
1013
+ return [];
1014
+ }
1015
+ const keys = isArrayLike(collection) || Array.isArray(collection) ? rangeRight.range(0, collection.length) : Object.keys(collection);
1016
+ const iteratee$1 = iteratee(_iteratee ?? unary.identity);
1017
+ const result = new Array(keys.length);
1018
+ for (let i = 0; i < keys.length; i++) {
1019
+ const key = keys[i];
1020
+ const value = collection[key];
1021
+ result[i] = iteratee$1(value, key, collection);
1022
+ }
1023
+ return result;
1024
+ }
1025
+
1011
1026
  function nth(array, n = 0) {
1012
1027
  if (!isArrayLikeObject(array) || array.length === 0) {
1013
1028
  return undefined;
@@ -2970,6 +2985,7 @@ exports.keysIn = keysIn;
2970
2985
  exports.last = last;
2971
2986
  exports.lastIndexOf = lastIndexOf;
2972
2987
  exports.lowerCase = lowerCase;
2988
+ exports.map = map;
2973
2989
  exports.mapKeys = mapKeys;
2974
2990
  exports.mapValues = mapValues;
2975
2991
  exports.matches = matches;
@@ -105,6 +105,7 @@ export { intersectionBy } from './array/intersectionBy.mjs';
105
105
  export { join } from './array/join.mjs';
106
106
  export { last } from './array/last.mjs';
107
107
  export { lastIndexOf } from './array/lastIndexOf.mjs';
108
+ export { map } from './array/map.mjs';
108
109
  export { nth } from './array/nth.mjs';
109
110
  export { orderBy } from './array/orderBy.mjs';
110
111
  export { pull } from './array/pull.mjs';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "es-toolkit",
3
3
  "description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
4
- "version": "1.29.0-dev.931+f7abb57d",
4
+ "version": "1.29.0-dev.932+e387b4f5",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {