es-toolkit 1.18.0-dev.575 → 1.18.0-dev.576
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/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/index.js +29 -9
- package/dist/compat/object/pick.d.mts +20 -2
- package/dist/compat/object/pick.d.ts +20 -2
- package/dist/compat/object/pick.mjs +26 -16
- package/dist/compat/predicate/isNil.mjs +5 -0
- package/package.json +1 -1
package/dist/compat/index.js
CHANGED
|
@@ -782,19 +782,39 @@ function rearg(func, ...indices) {
|
|
|
782
782
|
};
|
|
783
783
|
}
|
|
784
784
|
|
|
785
|
-
function
|
|
786
|
-
|
|
785
|
+
function isNil(x) {
|
|
786
|
+
return x == null;
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
function pick(obj, ...keysArr) {
|
|
790
|
+
if (isNil(obj)) {
|
|
787
791
|
return {};
|
|
788
792
|
}
|
|
789
|
-
const typedObject = obj;
|
|
790
793
|
const result = {};
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
794
|
+
for (let keys of keysArr) {
|
|
795
|
+
switch (typeof keys) {
|
|
796
|
+
case 'object': {
|
|
797
|
+
if (!Array.isArray(keys)) {
|
|
798
|
+
keys = Array.from(keys);
|
|
799
|
+
}
|
|
800
|
+
break;
|
|
801
|
+
}
|
|
802
|
+
case 'string':
|
|
803
|
+
case 'symbol':
|
|
804
|
+
case 'number': {
|
|
805
|
+
keys = [keys];
|
|
806
|
+
break;
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
for (const key of keys) {
|
|
810
|
+
const value = get(obj, key);
|
|
811
|
+
if (typeof key === 'string' && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
812
|
+
result[key] = value;
|
|
813
|
+
}
|
|
814
|
+
else {
|
|
815
|
+
set(result, key, value);
|
|
816
|
+
}
|
|
796
817
|
}
|
|
797
|
-
set(result, arg, get(typedObject, arg));
|
|
798
818
|
}
|
|
799
819
|
return result;
|
|
800
820
|
}
|
|
@@ -5,8 +5,26 @@
|
|
|
5
5
|
* includes only the properties corresponding to the specified keys.
|
|
6
6
|
*
|
|
7
7
|
* @template T - The type of object.
|
|
8
|
+
* @template K - The type of keys in object.
|
|
8
9
|
* @param {T} obj - The object to pick keys from.
|
|
9
|
-
* @param {
|
|
10
|
+
* @param {K[]} keys - An array of keys to be picked from the object.
|
|
11
|
+
* @returns {Pick<T, K>} A new object with the specified keys picked.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const obj = { a: 1, b: 2, c: 3 };
|
|
15
|
+
* const result = pick(obj, ['a', 'c']);
|
|
16
|
+
* // result will be { a: 1, c: 3 }
|
|
17
|
+
*/
|
|
18
|
+
declare function pick<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new object composed of the picked object properties.
|
|
21
|
+
*
|
|
22
|
+
* This function takes an object and an array of keys, and returns a new object that
|
|
23
|
+
* includes only the properties corresponding to the specified keys.
|
|
24
|
+
*
|
|
25
|
+
* @template T - The type of object.
|
|
26
|
+
* @param {T | null | undefined} obj - The object to pick keys from.
|
|
27
|
+
* @param {PropertyKey | PropertyKey[] | ProperyKey[][]}} keys - An array of keys to be picked from the object. received keysgoes through a flattening process before being used.
|
|
10
28
|
* @returns {Partial<T, K>} A new object with the specified keys picked.
|
|
11
29
|
*
|
|
12
30
|
* @example
|
|
@@ -23,6 +41,6 @@
|
|
|
23
41
|
* const result = pick(obj, 'a.b');
|
|
24
42
|
* // result will be { 'a.b': 1 }
|
|
25
43
|
*/
|
|
26
|
-
declare function pick<T>(obj: T
|
|
44
|
+
declare function pick<T extends {}>(obj: T | null | undefined, ...keys: Array<PropertyKey | PropertyKey[] | PropertyKey[][]>): Partial<T>;
|
|
27
45
|
|
|
28
46
|
export { pick };
|
|
@@ -5,8 +5,26 @@
|
|
|
5
5
|
* includes only the properties corresponding to the specified keys.
|
|
6
6
|
*
|
|
7
7
|
* @template T - The type of object.
|
|
8
|
+
* @template K - The type of keys in object.
|
|
8
9
|
* @param {T} obj - The object to pick keys from.
|
|
9
|
-
* @param {
|
|
10
|
+
* @param {K[]} keys - An array of keys to be picked from the object.
|
|
11
|
+
* @returns {Pick<T, K>} A new object with the specified keys picked.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const obj = { a: 1, b: 2, c: 3 };
|
|
15
|
+
* const result = pick(obj, ['a', 'c']);
|
|
16
|
+
* // result will be { a: 1, c: 3 }
|
|
17
|
+
*/
|
|
18
|
+
declare function pick<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new object composed of the picked object properties.
|
|
21
|
+
*
|
|
22
|
+
* This function takes an object and an array of keys, and returns a new object that
|
|
23
|
+
* includes only the properties corresponding to the specified keys.
|
|
24
|
+
*
|
|
25
|
+
* @template T - The type of object.
|
|
26
|
+
* @param {T | null | undefined} obj - The object to pick keys from.
|
|
27
|
+
* @param {PropertyKey | PropertyKey[] | ProperyKey[][]}} keys - An array of keys to be picked from the object. received keysgoes through a flattening process before being used.
|
|
10
28
|
* @returns {Partial<T, K>} A new object with the specified keys picked.
|
|
11
29
|
*
|
|
12
30
|
* @example
|
|
@@ -23,6 +41,6 @@
|
|
|
23
41
|
* const result = pick(obj, 'a.b');
|
|
24
42
|
* // result will be { 'a.b': 1 }
|
|
25
43
|
*/
|
|
26
|
-
declare function pick<T>(obj: T
|
|
44
|
+
declare function pick<T extends {}>(obj: T | null | undefined, ...keys: Array<PropertyKey | PropertyKey[] | PropertyKey[][]>): Partial<T>;
|
|
27
45
|
|
|
28
46
|
export { pick };
|
|
@@ -1,26 +1,36 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { flattenDeep } from '../../array/flattenDeep.mjs';
|
|
1
|
+
import { isNil } from '../predicate/isNil.mjs';
|
|
3
2
|
import { get } from './get.mjs';
|
|
4
|
-
import '
|
|
5
|
-
import '../../function/partialRight.mjs';
|
|
6
|
-
import { isNil } from '../../predicate/isNil.mjs';
|
|
7
|
-
import '../../string/deburr.mjs';
|
|
8
|
-
import '../function/bind.mjs';
|
|
9
|
-
import '../function/bindKey.mjs';
|
|
3
|
+
import { set } from './set.mjs';
|
|
10
4
|
|
|
11
|
-
function pick(obj, ...
|
|
5
|
+
function pick(obj, ...keysArr) {
|
|
12
6
|
if (isNil(obj)) {
|
|
13
7
|
return {};
|
|
14
8
|
}
|
|
15
|
-
const typedObject = obj;
|
|
16
9
|
const result = {};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
10
|
+
for (let keys of keysArr) {
|
|
11
|
+
switch (typeof keys) {
|
|
12
|
+
case 'object': {
|
|
13
|
+
if (!Array.isArray(keys)) {
|
|
14
|
+
keys = Array.from(keys);
|
|
15
|
+
}
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
case 'string':
|
|
19
|
+
case 'symbol':
|
|
20
|
+
case 'number': {
|
|
21
|
+
keys = [keys];
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
for (const key of keys) {
|
|
26
|
+
const value = get(obj, key);
|
|
27
|
+
if (typeof key === 'string' && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
28
|
+
result[key] = value;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
set(result, key, value);
|
|
32
|
+
}
|
|
22
33
|
}
|
|
23
|
-
set(result, arg, get(typedObject, arg));
|
|
24
34
|
}
|
|
25
35
|
return result;
|
|
26
36
|
}
|
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.18.0-dev.
|
|
4
|
+
"version": "1.18.0-dev.576+9a48d39a",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|