Ramda Adjunct 2.26.0

toArray.js

import { ifElse, values, curryN } from 'ramda';

import isIterable from './isIterable';
import isFunction from './isFunction';
import polyfill from './internal/polyfills/Array.from';

export const fromPolyfill = curryN(1, polyfill);

const fromArray = isFunction(Array.from) ? curryN(1, Array.from) : fromPolyfill;

/**
 * Converts value to an array.
 *
 * @func toArray
 * @memberOf RA
 * @since {@link https://char0n.github.io/ramda-adjunct/2.22.0|v2.22.0}
 * @category List
 * @sig * -> [a]
 * @param {*} val The value to convert
 * @return {Array}
 * @example
 *
 * RA.toArray([1, 2]); //=> [1, 2]
 * RA.toArray({'foo': 1, 'bar': 2}); //=> [1, 2]
 * RA.toArray('abc'); //=> ['a', 'b', 'c']
 * RA.toArray(1); //=> []
 * RA.toArray(null); //=> []
 */

const toArray = ifElse(isIterable, fromArray, values);

export default toArray;