es-toolkit 1.18.0-dev.574 → 1.18.0-dev.575

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.
@@ -72,7 +72,6 @@ export { sumBy } from '../math/sumBy.mjs';
72
72
  export { range } from '../math/range.mjs';
73
73
  export { omit } from '../object/omit.mjs';
74
74
  export { omitBy } from '../object/omitBy.mjs';
75
- export { pick } from '../object/pick.mjs';
76
75
  export { pickBy } from '../object/pickBy.mjs';
77
76
  export { invert } from '../object/invert.mjs';
78
77
  export { clone } from '../object/clone.mjs';
@@ -130,6 +129,7 @@ export { attempt } from './function/attempt.mjs';
130
129
  export { rearg } from './function/rearg.mjs';
131
130
  export { get } from './object/get.mjs';
132
131
  export { set } from './object/set.mjs';
132
+ export { pick } from './object/pick.mjs';
133
133
  export { has } from './object/has.mjs';
134
134
  export { property } from './object/property.mjs';
135
135
  export { mapKeys } from './object/mapKeys.mjs';
@@ -72,7 +72,6 @@ export { sumBy } from '../math/sumBy.js';
72
72
  export { range } from '../math/range.js';
73
73
  export { omit } from '../object/omit.js';
74
74
  export { omitBy } from '../object/omitBy.js';
75
- export { pick } from '../object/pick.js';
76
75
  export { pickBy } from '../object/pickBy.js';
77
76
  export { invert } from '../object/invert.js';
78
77
  export { clone } from '../object/clone.js';
@@ -130,6 +129,7 @@ export { attempt } from './function/attempt.js';
130
129
  export { rearg } from './function/rearg.js';
131
130
  export { get } from './object/get.js';
132
131
  export { set } from './object/set.js';
132
+ export { pick } from './object/pick.js';
133
133
  export { has } from './object/has.js';
134
134
  export { property } from './object/property.js';
135
135
  export { mapKeys } from './object/mapKeys.js';
@@ -7,7 +7,7 @@ const promise_index = require('../_chunk/index-BGZDR9.js');
7
7
  const rest$1 = require('../_chunk/rest-CXt9w3.js');
8
8
  const math_index = require('../math/index.js');
9
9
  const randomInt = require('../_chunk/randomInt-CF7bZK.js');
10
- const toMerged = require('../_chunk/toMerged-DN1PPP.js');
10
+ const toMerged = require('../_chunk/toMerged-Bmrr2j.js');
11
11
  const isWeakSet$1 = require('../_chunk/isWeakSet-BerD1A.js');
12
12
  const isTypedArray$1 = require('../_chunk/isTypedArray-Dsrnb1.js');
13
13
  const string_index = require('../string/index.js');
@@ -782,6 +782,23 @@ function rearg(func, ...indices) {
782
782
  };
783
783
  }
784
784
 
785
+ function pick(obj, ...keys) {
786
+ if (isWeakSet$1.isNil(obj)) {
787
+ return {};
788
+ }
789
+ const typedObject = obj;
790
+ const result = {};
791
+ const flattenArgs = zipWith.flattenDeep(keys.map(arg => (typeof arg === 'object' ? Array.from(arg) : arg)));
792
+ for (const arg of flattenArgs) {
793
+ if (String(arg).includes('.') && arg in typedObject) {
794
+ result[arg] = get(typedObject, arg);
795
+ continue;
796
+ }
797
+ set(result, arg, get(typedObject, arg));
798
+ }
799
+ return result;
800
+ }
801
+
785
802
  function mapKeys(object, getNewKey) {
786
803
  getNewKey = getNewKey ?? identity;
787
804
  switch (typeof getNewKey) {
@@ -1137,7 +1154,6 @@ exports.invert = toMerged.invert;
1137
1154
  exports.isObjectLike = toMerged.isObjectLike;
1138
1155
  exports.omit = toMerged.omit;
1139
1156
  exports.omitBy = toMerged.omitBy;
1140
- exports.pick = toMerged.pick;
1141
1157
  exports.pickBy = toMerged.pickBy;
1142
1158
  exports.toMerged = toMerged.toMerged;
1143
1159
  exports.isEqual = isWeakSet$1.isEqual;
@@ -1210,6 +1226,7 @@ exports.orderBy = orderBy;
1210
1226
  exports.padEnd = padEnd;
1211
1227
  exports.padStart = padStart;
1212
1228
  exports.parseInt = parseInt;
1229
+ exports.pick = pick;
1213
1230
  exports.property = property;
1214
1231
  exports.rearg = rearg;
1215
1232
  exports.repeat = repeat;
@@ -72,7 +72,6 @@ export { sumBy } from '../math/sumBy.mjs';
72
72
  export { range } from '../math/range.mjs';
73
73
  export { omit } from '../object/omit.mjs';
74
74
  export { omitBy } from '../object/omitBy.mjs';
75
- export { pick } from '../object/pick.mjs';
76
75
  export { pickBy } from '../object/pickBy.mjs';
77
76
  export { invert } from '../object/invert.mjs';
78
77
  export { clone } from '../object/clone.mjs';
@@ -131,6 +130,7 @@ export { attempt } from './function/attempt.mjs';
131
130
  export { rearg } from './function/rearg.mjs';
132
131
  export { get } from './object/get.mjs';
133
132
  export { set } from './object/set.mjs';
133
+ export { pick } from './object/pick.mjs';
134
134
  export { has } from './object/has.mjs';
135
135
  export { property } from './object/property.mjs';
136
136
  export { mapKeys } from './object/mapKeys.mjs';
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Creates a new object composed of the picked object properties.
3
+ *
4
+ * This function takes an object and an array of keys, and returns a new object that
5
+ * includes only the properties corresponding to the specified keys.
6
+ *
7
+ * @template T - The type of object.
8
+ * @param {T} obj - The object to pick keys from.
9
+ * @param {keyof T | string | Array<keyof T | string> | Array<Array<keyof T | string>>} keys - An array of keys to be picked from the object. received keysgoes through a flattening process before being used.
10
+ * @returns {Partial<T, K>} A new object with the specified keys picked.
11
+ *
12
+ * @example
13
+ * const obj = { a: 1, b: 2, c: 3 };
14
+ * const result = pick(obj, ['a', 'c']);
15
+ * // result will be { a: 1, c: 3 }
16
+ *
17
+ * // each path can be passed individually as an argument
18
+ * const obj = { a: 1, b: 2, c: 3 };
19
+ * const result = pick(obj, 'a', 'c');
20
+ *
21
+ * // pick a key over a path
22
+ * const obj = { 'a.b': 1, a: { b: 2 } };
23
+ * const result = pick(obj, 'a.b');
24
+ * // result will be { 'a.b': 1 }
25
+ */
26
+ declare function pick<T>(obj: T, ...keys: Array<keyof T | (NonNullable<unknown> & string) | IArguments | Array<keyof T | (NonNullable<unknown> & string) | IArguments> | Array<Array<keyof T | (NonNullable<unknown> & string) | IArguments>>>): Partial<T>;
27
+
28
+ export { pick };
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Creates a new object composed of the picked object properties.
3
+ *
4
+ * This function takes an object and an array of keys, and returns a new object that
5
+ * includes only the properties corresponding to the specified keys.
6
+ *
7
+ * @template T - The type of object.
8
+ * @param {T} obj - The object to pick keys from.
9
+ * @param {keyof T | string | Array<keyof T | string> | Array<Array<keyof T | string>>} keys - An array of keys to be picked from the object. received keysgoes through a flattening process before being used.
10
+ * @returns {Partial<T, K>} A new object with the specified keys picked.
11
+ *
12
+ * @example
13
+ * const obj = { a: 1, b: 2, c: 3 };
14
+ * const result = pick(obj, ['a', 'c']);
15
+ * // result will be { a: 1, c: 3 }
16
+ *
17
+ * // each path can be passed individually as an argument
18
+ * const obj = { a: 1, b: 2, c: 3 };
19
+ * const result = pick(obj, 'a', 'c');
20
+ *
21
+ * // pick a key over a path
22
+ * const obj = { 'a.b': 1, a: { b: 2 } };
23
+ * const result = pick(obj, 'a.b');
24
+ * // result will be { 'a.b': 1 }
25
+ */
26
+ declare function pick<T>(obj: T, ...keys: Array<keyof T | (NonNullable<unknown> & string) | IArguments | Array<keyof T | (NonNullable<unknown> & string) | IArguments> | Array<Array<keyof T | (NonNullable<unknown> & string) | IArguments>>>): Partial<T>;
27
+
28
+ export { pick };
@@ -0,0 +1,28 @@
1
+ import { set } from './set.mjs';
2
+ import { flattenDeep } from '../../array/flattenDeep.mjs';
3
+ import { get } from './get.mjs';
4
+ import '../../function/partial.mjs';
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';
10
+
11
+ function pick(obj, ...keys) {
12
+ if (isNil(obj)) {
13
+ return {};
14
+ }
15
+ const typedObject = obj;
16
+ const result = {};
17
+ const flattenArgs = flattenDeep(keys.map(arg => (typeof arg === 'object' ? Array.from(arg) : arg)));
18
+ for (const arg of flattenArgs) {
19
+ if (String(arg).includes('.') && arg in typedObject) {
20
+ result[arg] = get(typedObject, arg);
21
+ continue;
22
+ }
23
+ set(result, arg, get(typedObject, arg));
24
+ }
25
+ return result;
26
+ }
27
+
28
+ export { pick };
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ const rest = require('./_chunk/rest-CXt9w3.js');
9
9
  const function_index = require('./function/index.js');
10
10
  const math_index = require('./math/index.js');
11
11
  const randomInt = require('./_chunk/randomInt-CF7bZK.js');
12
- const toMerged = require('./_chunk/toMerged-DN1PPP.js');
12
+ const toMerged = require('./_chunk/toMerged-Bmrr2j.js');
13
13
  const object_index = require('./object/index.js');
14
14
  const isWeakSet = require('./_chunk/isWeakSet-BerD1A.js');
15
15
  const isTypedArray = require('./_chunk/isTypedArray-Dsrnb1.js');
@@ -112,10 +112,10 @@ exports.mapValues = toMerged.mapValues;
112
112
  exports.merge = toMerged.merge;
113
113
  exports.omit = toMerged.omit;
114
114
  exports.omitBy = toMerged.omitBy;
115
- exports.pick = toMerged.pick;
116
115
  exports.pickBy = toMerged.pickBy;
117
116
  exports.toMerged = toMerged.toMerged;
118
117
  exports.mergeWith = object_index.mergeWith;
118
+ exports.pick = object_index.pick;
119
119
  exports.isEqual = isWeakSet.isEqual;
120
120
  exports.isFunction = isWeakSet.isFunction;
121
121
  exports.isLength = isWeakSet.isLength;
@@ -2,7 +2,15 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const toMerged = require('../_chunk/toMerged-DN1PPP.js');
5
+ const toMerged = require('../_chunk/toMerged-Bmrr2j.js');
6
+
7
+ function pick(obj, keys) {
8
+ const result = {};
9
+ for (const key of keys) {
10
+ result[key] = obj[key];
11
+ }
12
+ return result;
13
+ }
6
14
 
7
15
  function mergeWith(target, source, merge) {
8
16
  const sourceKeys = Object.keys(source);
@@ -36,7 +44,7 @@ exports.mapValues = toMerged.mapValues;
36
44
  exports.merge = toMerged.merge;
37
45
  exports.omit = toMerged.omit;
38
46
  exports.omitBy = toMerged.omitBy;
39
- exports.pick = toMerged.pick;
40
47
  exports.pickBy = toMerged.pickBy;
41
48
  exports.toMerged = toMerged.toMerged;
42
49
  exports.mergeWith = mergeWith;
50
+ exports.pick = pick;
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.574+b1bb77b6",
4
+ "version": "1.18.0-dev.575+936e0980",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {