1 | function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
---|
2 | function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
---|
3 | function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
---|
4 | function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
---|
5 | function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
---|
6 | function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
---|
7 | import { bind } from 'ramda';
|
---|
8 | import isIterable from '../../isIterable';
|
---|
9 | import isNotUndefined from '../../isNotUndefined';
|
---|
10 | import isNotNil from '../../isNotNil';
|
---|
11 | import isNotFunction from '../../isNotFunction';
|
---|
12 | var copyArray = function copyArray(items, mapFn, thisArg) {
|
---|
13 | var boundMapFn = isNotUndefined(thisArg) ? bind(mapFn, thisArg) : mapFn;
|
---|
14 | return isNotUndefined(mapFn) ? _toConsumableArray(items).map(boundMapFn) : _toConsumableArray(items);
|
---|
15 | };
|
---|
16 | var fromArray = function fromArray(items, mapFn, thisArg) {
|
---|
17 | if (items == null) {
|
---|
18 | throw new TypeError('Array.from requires an array-like object - not null or undefined');
|
---|
19 | }
|
---|
20 | if (isNotNil(mapFn) && isNotFunction(mapFn)) {
|
---|
21 | throw new TypeError('Array.from: when provided, the second argument must be a function');
|
---|
22 | }
|
---|
23 | if (isIterable(items)) {
|
---|
24 | return copyArray(items, mapFn, thisArg);
|
---|
25 | }
|
---|
26 | return [];
|
---|
27 | };
|
---|
28 | export default fromArray; |
---|