Path: blob/master/node_modules/array-back/dist/index.js
1126 views
(function (global, factory) {1typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :2typeof define === 'function' && define.amd ? define(factory) :3(global = global || self, global.arrayBack = factory());4}(this, function () { 'use strict';56/**7* Takes any input and guarantees an array back.8*9* - Converts array-like objects (e.g. `arguments`, `Set`) to a real array.10* - Converts `undefined` to an empty array.11* - Converts any another other, singular value (including `null`, objects and iterables other than `Set`) into an array containing that value.12* - Ignores input which is already an array.13*14* @module array-back15* @example16* > const arrayify = require('array-back')17*18* > arrayify(undefined)19* []20*21* > arrayify(null)22* [ null ]23*24* > arrayify(0)25* [ 0 ]26*27* > arrayify([ 1, 2 ])28* [ 1, 2 ]29*30* > arrayify(new Set([ 1, 2 ]))31* [ 1, 2 ]32*33* > function f(){ return arrayify(arguments); }34* > f(1,2,3)35* [ 1, 2, 3 ]36*/3738function isObject (input) {39return typeof input === 'object' && input !== null40}4142function isArrayLike (input) {43return isObject(input) && typeof input.length === 'number'44}4546/**47* @param {*} - The input value to convert to an array48* @returns {Array}49* @alias module:array-back50*/51function arrayify (input) {52if (Array.isArray(input)) {53return input54}5556if (input === undefined) {57return []58}5960if (isArrayLike(input) || input instanceof Set) {61return Array.from(input)62}6364return [ input ]65}6667return arrayify;6869}));707172