ramda-adjunct
Version:
Ramda Adjunct is the most popular and most comprehensive set of utilities for use with Ramda, providing a variety of useful, well tested functions with excellent documentation.
27 lines (26 loc) • 822 B
JavaScript
import { ifElse, values, curryN } from 'ramda';
import isIterable from './isIterable';
import isFunction from './isFunction';
import polyfill from './internal/polyfills/Array.from';
export var fromPolyfill = curryN(1, polyfill);
var 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); //=> []
*/
var toArray = ifElse(isIterable, fromArray, values);
export default toArray;