diff options
author | Dimitri Staessens <[email protected]> | 2019-10-06 21:37:45 +0200 |
---|---|---|
committer | Dimitri Staessens <[email protected]> | 2019-10-06 21:37:45 +0200 |
commit | 3c51c3be85bb0d1bdb87ea0d6632f1c256912f27 (patch) | |
tree | c7ccc8279b12c4f7bdbbb4270d617e48f51722e4 /node_modules/lodash/toArray.js | |
parent | 412c104bebc507bea9c94fd53b5bdc4b64cbfe31 (diff) | |
download | website-3c51c3be85bb0d1bdb87ea0d6632f1c256912f27.tar.gz website-3c51c3be85bb0d1bdb87ea0d6632f1c256912f27.zip |
build: Add some required modules for node
Diffstat (limited to 'node_modules/lodash/toArray.js')
-rw-r--r-- | node_modules/lodash/toArray.js | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/node_modules/lodash/toArray.js b/node_modules/lodash/toArray.js new file mode 100644 index 0000000..9809584 --- /dev/null +++ b/node_modules/lodash/toArray.js @@ -0,0 +1,58 @@ +var Symbol = require('./_Symbol'), + copyArray = require('./_copyArray'), + getTag = require('./_getTag'), + isArrayLike = require('./isArrayLike'), + isString = require('./isString'), + iteratorToArray = require('./_iteratorToArray'), + mapToArray = require('./_mapToArray'), + setToArray = require('./_setToArray'), + stringToArray = require('./_stringToArray'), + values = require('./values'); + +/** `Object#toString` result references. */ +var mapTag = '[object Map]', + setTag = '[object Set]'; + +/** Built-in value references. */ +var symIterator = Symbol ? Symbol.iterator : undefined; + +/** + * Converts `value` to an array. + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category Lang + * @param {*} value The value to convert. + * @returns {Array} Returns the converted array. + * @example + * + * _.toArray({ 'a': 1, 'b': 2 }); + * // => [1, 2] + * + * _.toArray('abc'); + * // => ['a', 'b', 'c'] + * + * _.toArray(1); + * // => [] + * + * _.toArray(null); + * // => [] + */ +function toArray(value) { + if (!value) { + return []; + } + if (isArrayLike(value)) { + return isString(value) ? stringToArray(value) : copyArray(value); + } + if (symIterator && value[symIterator]) { + return iteratorToArray(value[symIterator]()); + } + var tag = getTag(value), + func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values); + + return func(value); +} + +module.exports = toArray; |