|
@@ -1,16 +1,17 @@
|
|
|
+import checkArray from '../array/_checkArray';
|
|
|
+
|
|
|
/**
|
|
|
* Receives an array of objects and extracts an object with the given key as index. The key
|
|
|
* must be a property of the array items. If the property is not found on the item, the item
|
|
|
* is omitted.
|
|
|
*
|
|
|
+ * @memberOf object
|
|
|
* @param {Object[]} array
|
|
|
* @param {string} key
|
|
|
* @param {boolean} keep - should the extracted prop be kept in the result object
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
-import checkArray from '../array/_checkArray';
|
|
|
-
|
|
|
-export default (array, key, keep = true) => {
|
|
|
+const fromArray = (array, key, keep = true) => {
|
|
|
checkArray(array);
|
|
|
|
|
|
if (!(typeof key === 'string')) {
|
|
@@ -27,4 +28,6 @@ export default (array, key, keep = true) => {
|
|
|
object[prop] = keep ? item : rest;
|
|
|
return object;
|
|
|
}, {});
|
|
|
-};
|
|
|
+};
|
|
|
+
|
|
|
+export default fromArray;
|