firest commit
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015-19 Lloyd Brookes <75pound@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
[](https://www.npmjs.org/package/array-back)
|
||||
[](https://www.npmjs.org/package/array-back)
|
||||
[](https://travis-ci.org/75lb/array-back)
|
||||
[](https://coveralls.io/github/75lb/array-back?branch=master)
|
||||
[](https://david-dm.org/75lb/array-back)
|
||||
[](https://github.com/feross/standard)
|
||||
|
||||
{{>main}}
|
||||
|
||||
### Load anywhere
|
||||
|
||||
This library is compatible with Node.js, the Web and any style of module loader. It can be loaded anywhere, natively without transpilation.
|
||||
|
||||
Node.js:
|
||||
|
||||
```js
|
||||
const arrayify = require('array-back')
|
||||
```
|
||||
|
||||
Within Node.js with ECMAScript Module support enabled:
|
||||
|
||||
```js
|
||||
import arrayify from 'array-back'
|
||||
```
|
||||
|
||||
Within an modern browser ECMAScript Module:
|
||||
|
||||
```js
|
||||
import arrayify from './node_modules/array-back/index.mjs'
|
||||
```
|
||||
|
||||
Old browser (adds `window.arrayBack`):
|
||||
|
||||
```html
|
||||
<script nomodule src="./node_modules/array-back/dist/index.js"></script>
|
||||
```
|
||||
|
||||
* * *
|
||||
|
||||
© 2015-19 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/75lb/jsdoc-to-markdown).
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
[](https://www.npmjs.org/package/array-back)
|
||||
[](https://www.npmjs.org/package/array-back)
|
||||
[](https://travis-ci.org/75lb/array-back)
|
||||
[](https://coveralls.io/github/75lb/array-back?branch=master)
|
||||
[](https://david-dm.org/75lb/array-back)
|
||||
[](https://github.com/feross/standard)
|
||||
|
||||
<a name="module_array-back"></a>
|
||||
|
||||
## array-back
|
||||
Takes any input and guarantees an array back.
|
||||
|
||||
- Converts array-like objects (e.g. `arguments`, `Set`) to a real array.
|
||||
- Converts `undefined` to an empty array.
|
||||
- Converts any another other, singular value (including `null`, objects and iterables other than `Set`) into an array containing that value.
|
||||
- Ignores input which is already an array.
|
||||
|
||||
**Example**
|
||||
```js
|
||||
> const arrayify = require('array-back')
|
||||
|
||||
> arrayify(undefined)
|
||||
[]
|
||||
|
||||
> arrayify(null)
|
||||
[ null ]
|
||||
|
||||
> arrayify(0)
|
||||
[ 0 ]
|
||||
|
||||
> arrayify([ 1, 2 ])
|
||||
[ 1, 2 ]
|
||||
|
||||
> arrayify(new Set([ 1, 2 ]))
|
||||
[ 1, 2 ]
|
||||
|
||||
> function f(){ return arrayify(arguments); }
|
||||
> f(1,2,3)
|
||||
[ 1, 2, 3 ]
|
||||
```
|
||||
<a name="exp_module_array-back--arrayify"></a>
|
||||
|
||||
### arrayify(input) ⇒ <code>Array</code> ⏏
|
||||
**Kind**: Exported function
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| input | <code>\*</code> | The input value to convert to an array |
|
||||
|
||||
|
||||
### Load anywhere
|
||||
|
||||
This library is compatible with Node.js, the Web and any style of module loader. It can be loaded anywhere, natively without transpilation.
|
||||
|
||||
Node.js:
|
||||
|
||||
```js
|
||||
const arrayify = require('array-back')
|
||||
```
|
||||
|
||||
Within Node.js with ECMAScript Module support enabled:
|
||||
|
||||
```js
|
||||
import arrayify from 'array-back'
|
||||
```
|
||||
|
||||
Within an modern browser ECMAScript Module:
|
||||
|
||||
```js
|
||||
import arrayify from './node_modules/array-back/index.mjs'
|
||||
```
|
||||
|
||||
Old browser (adds `window.arrayBack`):
|
||||
|
||||
```html
|
||||
<script nomodule src="./node_modules/array-back/dist/index.js"></script>
|
||||
```
|
||||
|
||||
* * *
|
||||
|
||||
© 2015-19 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/75lb/jsdoc-to-markdown).
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
||||
typeof define === 'function' && define.amd ? define(factory) :
|
||||
(global = global || self, global.arrayBack = factory());
|
||||
}(this, (function () { 'use strict';
|
||||
|
||||
/**
|
||||
* Takes any input and guarantees an array back.
|
||||
*
|
||||
* - Converts array-like objects (e.g. `arguments`, `Set`) to a real array.
|
||||
* - Converts `undefined` to an empty array.
|
||||
* - Converts any another other, singular value (including `null`, objects and iterables other than `Set`) into an array containing that value.
|
||||
* - Ignores input which is already an array.
|
||||
*
|
||||
* @module array-back
|
||||
* @example
|
||||
* > const arrayify = require('array-back')
|
||||
*
|
||||
* > arrayify(undefined)
|
||||
* []
|
||||
*
|
||||
* > arrayify(null)
|
||||
* [ null ]
|
||||
*
|
||||
* > arrayify(0)
|
||||
* [ 0 ]
|
||||
*
|
||||
* > arrayify([ 1, 2 ])
|
||||
* [ 1, 2 ]
|
||||
*
|
||||
* > arrayify(new Set([ 1, 2 ]))
|
||||
* [ 1, 2 ]
|
||||
*
|
||||
* > function f(){ return arrayify(arguments); }
|
||||
* > f(1,2,3)
|
||||
* [ 1, 2, 3 ]
|
||||
*/
|
||||
|
||||
function isObject (input) {
|
||||
return typeof input === 'object' && input !== null
|
||||
}
|
||||
|
||||
function isArrayLike (input) {
|
||||
return isObject(input) && typeof input.length === 'number'
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {*} - The input value to convert to an array
|
||||
* @returns {Array}
|
||||
* @alias module:array-back
|
||||
*/
|
||||
function arrayify (input) {
|
||||
if (Array.isArray(input)) {
|
||||
return input
|
||||
}
|
||||
|
||||
if (input === undefined) {
|
||||
return []
|
||||
}
|
||||
|
||||
if (isArrayLike(input) || input instanceof Set) {
|
||||
return Array.from(input)
|
||||
}
|
||||
|
||||
return [input]
|
||||
}
|
||||
|
||||
return arrayify;
|
||||
|
||||
})));
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Takes any input and guarantees an array back.
|
||||
*
|
||||
* - Converts array-like objects (e.g. `arguments`, `Set`) to a real array.
|
||||
* - Converts `undefined` to an empty array.
|
||||
* - Converts any another other, singular value (including `null`, objects and iterables other than `Set`) into an array containing that value.
|
||||
* - Ignores input which is already an array.
|
||||
*
|
||||
* @module array-back
|
||||
* @example
|
||||
* > const arrayify = require('array-back')
|
||||
*
|
||||
* > arrayify(undefined)
|
||||
* []
|
||||
*
|
||||
* > arrayify(null)
|
||||
* [ null ]
|
||||
*
|
||||
* > arrayify(0)
|
||||
* [ 0 ]
|
||||
*
|
||||
* > arrayify([ 1, 2 ])
|
||||
* [ 1, 2 ]
|
||||
*
|
||||
* > arrayify(new Set([ 1, 2 ]))
|
||||
* [ 1, 2 ]
|
||||
*
|
||||
* > function f(){ return arrayify(arguments); }
|
||||
* > f(1,2,3)
|
||||
* [ 1, 2, 3 ]
|
||||
*/
|
||||
|
||||
function isObject (input) {
|
||||
return typeof input === 'object' && input !== null
|
||||
}
|
||||
|
||||
function isArrayLike (input) {
|
||||
return isObject(input) && typeof input.length === 'number'
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {*} - The input value to convert to an array
|
||||
* @returns {Array}
|
||||
* @alias module:array-back
|
||||
*/
|
||||
function arrayify (input) {
|
||||
if (Array.isArray(input)) {
|
||||
return input
|
||||
}
|
||||
|
||||
if (input === undefined) {
|
||||
return []
|
||||
}
|
||||
|
||||
if (isArrayLike(input) || input instanceof Set) {
|
||||
return Array.from(input)
|
||||
}
|
||||
|
||||
return [input]
|
||||
}
|
||||
|
||||
export default arrayify
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"name": "array-back",
|
||||
"author": "Lloyd Brookes <75pound@gmail.com>",
|
||||
"version": "4.0.2",
|
||||
"description": "Guarantees an array back",
|
||||
"repository": "https://github.com/75lb/array-back.git",
|
||||
"license": "MIT",
|
||||
"main": "dist/index.js",
|
||||
"keywords": [
|
||||
"to",
|
||||
"convert",
|
||||
"return",
|
||||
"array",
|
||||
"arrayify"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
},
|
||||
"files": [
|
||||
"index.mjs",
|
||||
"dist/index.js"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "npm run dist && npm run test:esm && npm run test:web",
|
||||
"test:esm": "esm-runner test.mjs",
|
||||
"test:web": "web-runner test.mjs",
|
||||
"docs": "jsdoc2md -t README.hbs index.mjs -c jsdoc.conf > README.md",
|
||||
"dist": "rollup -f umd -n arrayBack -o dist/index.js index.mjs",
|
||||
"cover": "c8 npm run test:esm && c8 report --reporter=text-lcov | coveralls"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"@test-runner/web": "^0.2.1",
|
||||
"c8": "^6.0.1",
|
||||
"coveralls": "^3.0.7",
|
||||
"esm-runner": "^0.2.0",
|
||||
"isomorphic-assert": "^0.1.1",
|
||||
"jsdoc-to-markdown": "^5.0.2",
|
||||
"rollup": "^1.26.5"
|
||||
},
|
||||
"standard": {
|
||||
"ignore": [
|
||||
"dist"
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user