source: node_modules/ramda-adjunct/src/internal/ponyfills/Array.from.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 877 bytes
Line 
1import { bind } from 'ramda';
2
3import isIterable from '../../isIterable';
4import isNotUndefined from '../../isNotUndefined';
5import isNotNil from '../../isNotNil';
6import isNotFunction from '../../isNotFunction';
7
8const copyArray = (items, mapFn, thisArg) => {
9 const boundMapFn = isNotUndefined(thisArg) ? bind(mapFn, thisArg) : mapFn;
10
11 return isNotUndefined(mapFn) ? [...items].map(boundMapFn) : [...items];
12};
13
14const fromArray = (items, mapFn, thisArg) => {
15 if (items == null) {
16 throw new TypeError(
17 'Array.from requires an array-like object - not null or undefined'
18 );
19 }
20
21 if (isNotNil(mapFn) && isNotFunction(mapFn)) {
22 throw new TypeError(
23 'Array.from: when provided, the second argument must be a function'
24 );
25 }
26
27 if (isIterable(items)) {
28 return copyArray(items, mapFn, thisArg);
29 }
30
31 return [];
32};
33
34export default fromArray;
Note: See TracBrowser for help on using the repository browser.