es-toolkit 1.17.0-dev.531 → 1.17.0-dev.532

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.
@@ -131,6 +131,7 @@ export { mapKeys } from './object/mapKeys.mjs';
131
131
  export { mapValues } from './object/mapValues.mjs';
132
132
  export { merge } from './object/merge.mjs';
133
133
  export { mergeWith } from './object/mergeWith.mjs';
134
+ export { fromPairs } from './object/fromPairs.mjs';
134
135
  export { isPlainObject } from './predicate/isPlainObject.mjs';
135
136
  export { isArray } from './predicate/isArray.mjs';
136
137
  export { isArguments } from './predicate/isArguments.mjs';
@@ -131,6 +131,7 @@ export { mapKeys } from './object/mapKeys.js';
131
131
  export { mapValues } from './object/mapValues.js';
132
132
  export { merge } from './object/merge.js';
133
133
  export { mergeWith } from './object/mergeWith.js';
134
+ export { fromPairs } from './object/fromPairs.js';
134
135
  export { isPlainObject } from './predicate/isPlainObject.js';
135
136
  export { isArray } from './predicate/isArray.js';
136
137
  export { isArguments } from './predicate/isArguments.js';
@@ -797,6 +797,14 @@ function merge(object, ...sources) {
797
797
  return mergeWith(object, ...sources, rest$1.noop);
798
798
  }
799
799
 
800
+ function fromPairs(data) {
801
+ const obj = {};
802
+ for (const [key, value] of data) {
803
+ obj[key] = value;
804
+ }
805
+ return obj;
806
+ }
807
+
800
808
  function isArray(value) {
801
809
  return Array.isArray(value);
802
810
  }
@@ -1002,6 +1010,7 @@ exports.findIndex = findIndex;
1002
1010
  exports.flatten = flatten;
1003
1011
  exports.flattenDeep = flattenDeep;
1004
1012
  exports.flattenDepth = flattenDepth;
1013
+ exports.fromPairs = fromPairs;
1005
1014
  exports.get = get;
1006
1015
  exports.has = has;
1007
1016
  exports.indexOf = indexOf;
@@ -132,6 +132,7 @@ export { mapKeys } from './object/mapKeys.mjs';
132
132
  export { mapValues } from './object/mapValues.mjs';
133
133
  export { merge } from './object/merge.mjs';
134
134
  export { mergeWith } from './object/mergeWith.mjs';
135
+ export { fromPairs } from './object/fromPairs.mjs';
135
136
  export { isPlainObject } from './predicate/isPlainObject.mjs';
136
137
  export { isArray } from './predicate/isArray.mjs';
137
138
  export { isArguments } from './predicate/isArguments.mjs';
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Transforms an array of key-value pairs into an object.
3
+ *
4
+ * @param {Array} data - An array of key-value pairs.
5
+ * @returns {Record<T, U>} - An object with keys and values from the input array.
6
+ *
7
+ * @example
8
+ * const pairs = [['a', 1], ['b', 2]];
9
+ *
10
+ * const object = fromPairs(pairs);
11
+ * console.log(object);
12
+ * // Output:
13
+ * // {
14
+ * // a: 1,
15
+ * // b: 2
16
+ * // }
17
+ */
18
+ declare function fromPairs<T extends PropertyKey, U>(data: Array<[PropertyKey, U]> | Map<PropertyKey, U>): {
19
+ [key in T]: U;
20
+ };
21
+
22
+ export { fromPairs };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Transforms an array of key-value pairs into an object.
3
+ *
4
+ * @param {Array} data - An array of key-value pairs.
5
+ * @returns {Record<T, U>} - An object with keys and values from the input array.
6
+ *
7
+ * @example
8
+ * const pairs = [['a', 1], ['b', 2]];
9
+ *
10
+ * const object = fromPairs(pairs);
11
+ * console.log(object);
12
+ * // Output:
13
+ * // {
14
+ * // a: 1,
15
+ * // b: 2
16
+ * // }
17
+ */
18
+ declare function fromPairs<T extends PropertyKey, U>(data: Array<[PropertyKey, U]> | Map<PropertyKey, U>): {
19
+ [key in T]: U;
20
+ };
21
+
22
+ export { fromPairs };
@@ -0,0 +1,9 @@
1
+ function fromPairs(data) {
2
+ const obj = {};
3
+ for (const [key, value] of data) {
4
+ obj[key] = value;
5
+ }
6
+ return obj;
7
+ }
8
+
9
+ export { fromPairs };
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.17.0-dev.531+1d4e55d5",
4
+ "version": "1.17.0-dev.532+fd2658e2",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {