Added npm dependency
This commit is contained in:
1 parent
888dd9af1e
commit
8dfc6caa7e
21061 files changed
+3885381
No files matched your search
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Blake Embrey (hello@blakeembrey.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.
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
# Array Flatten
|
||||
|
||||
[![NPM version][npm-image]][npm-url]
|
||||
[![NPM downloads][downloads-image]][downloads-url]
|
||||
[![Build status][travis-image]][travis-url]
|
||||
[![Test coverage][coveralls-image]][coveralls-url]
|
||||
|
||||
> Flatten nested arrays.
|
||||
|
||||
## Installation
|
||||
|
||||
```
|
||||
npm install array-flatten --save
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```javascript
|
||||
var flatten = require('array-flatten')
|
||||
|
||||
flatten([1, [2, [3, [4, [5], 6], 7], 8], 9])
|
||||
//=> [1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
|
||||
flatten.depth([1, [2, [3, [4, [5], 6], 7], 8], 9], 2)
|
||||
//=> [1, 2, 3, [4, [5], 6], 7, 8, 9]
|
||||
|
||||
(function () {
|
||||
flatten.from(arguments) //=> [1, 2, 3]
|
||||
})(1, [2, 3])
|
||||
```
|
||||
|
||||
### Methods
|
||||
|
||||
* **flatten(array)** Flatten a nested array structure
|
||||
* **flatten.from(arrayish)** Flatten an array-like structure (E.g. arguments)
|
||||
* **flatten.depth(array, depth)** Flatten a nested array structure with a specific depth
|
||||
* **flatten.fromDepth(arrayish, depth)** Flatten an array-like structure with a specific depth
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
[npm-image]: https://img.shields.io/npm/v/array-flatten.svg?style=flat
|
||||
[npm-url]: https://npmjs.org/package/array-flatten
|
||||
[downloads-image]: https://img.shields.io/npm/dm/array-flatten.svg?style=flat
|
||||
[downloads-url]: https://npmjs.org/package/array-flatten
|
||||
[travis-image]: https://img.shields.io/travis/blakeembrey/array-flatten.svg?style=flat
|
||||
[travis-url]: https://travis-ci.org/blakeembrey/array-flatten
|
||||
[coveralls-image]: https://img.shields.io/coveralls/blakeembrey/array-flatten.svg?style=flat
|
||||
[coveralls-url]: https://coveralls.io/r/blakeembrey/array-flatten?branch=master
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
declare function flatten <T> (array: flatten.NestedArray<T>): T[];
|
||||
|
||||
declare namespace flatten {
|
||||
export interface NestedArray <T> extends ReadonlyArray<T | NestedArray<T>> {}
|
||||
|
||||
export interface NestedList <T> {
|
||||
[index: number]: T | NestedList<T>;
|
||||
length: number;
|
||||
}
|
||||
|
||||
export function from <T> (array: NestedList<T>): T[];
|
||||
export function depth <T> (array: NestedArray<T>, depth: number): NestedArray<T>;
|
||||
export function depthFrom <T> (array: NestedList<T>, depth: number): NestedArray<T>;
|
||||
}
|
||||
|
||||
export = flatten;
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
'use strict'
|
||||
|
||||
/**
|
||||
* Expose `arrayFlatten`.
|
||||
*/
|
||||
module.exports = flatten
|
||||
module.exports.from = flattenFrom
|
||||
module.exports.depth = flattenDepth
|
||||
module.exports.fromDepth = flattenFromDepth
|
||||
|
||||
/**
|
||||
* Flatten an array.
|
||||
*
|
||||
* @param {Array} array
|
||||
* @return {Array}
|
||||
*/
|
||||
function flatten (array) {
|
||||
if (!Array.isArray(array)) {
|
||||
throw new TypeError('Expected value to be an array')
|
||||
}
|
||||
|
||||
return flattenFrom(array)
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten an array-like structure.
|
||||
*
|
||||
* @param {Array} array
|
||||
* @return {Array}
|
||||
*/
|
||||
function flattenFrom (array) {
|
||||
return flattenDown(array, [])
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten an array-like structure with depth.
|
||||
*
|
||||
* @param {Array} array
|
||||
* @param {number} depth
|
||||
* @return {Array}
|
||||
*/
|
||||
function flattenDepth (array, depth) {
|
||||
if (!Array.isArray(array)) {
|
||||
throw new TypeError('Expected value to be an array')
|
||||
}
|
||||
|
||||
return flattenFromDepth(array, depth)
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten an array-like structure with depth.
|
||||
*
|
||||
* @param {Array} array
|
||||
* @param {number} depth
|
||||
* @return {Array}
|
||||
*/
|
||||
function flattenFromDepth (array, depth) {
|
||||
if (typeof depth !== 'number') {
|
||||
throw new TypeError('Expected the depth to be a number')
|
||||
}
|
||||
|
||||
return flattenDownDepth(array, [], depth)
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten an array indefinitely.
|
||||
*
|
||||
* @param {Array} array
|
||||
* @param {Array} result
|
||||
* @return {Array}
|
||||
*/
|
||||
function flattenDown (array, result) {
|
||||
for (var i = 0; i < array.length; i++) {
|
||||
var value = array[i]
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
flattenDown(value, result)
|
||||
} else {
|
||||
result.push(value)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten an array with depth.
|
||||
*
|
||||
* @param {Array} array
|
||||
* @param {Array} result
|
||||
* @param {number} depth
|
||||
* @return {Array}
|
||||
*/
|
||||
function flattenDownDepth (array, result, depth) {
|
||||
depth--
|
||||
|
||||
for (var i = 0; i < array.length; i++) {
|
||||
var value = array[i]
|
||||
|
||||
if (depth > -1 && Array.isArray(value)) {
|
||||
flattenDownDepth(value, result, depth)
|
||||
} else {
|
||||
result.push(value)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"array-flatten@^2.1.0",
|
||||
"/home/ppinto/temp/spark/src/web/ui/node_modules/bonjour"
|
||||
]
|
||||
],
|
||||
"_from": "array-flatten@>=2.1.0 <3.0.0",
|
||||
"_hasShrinkwrap": false,
|
||||
"_id": "array-flatten@2.1.2",
|
||||
"_inCache": true,
|
||||
"_installable": true,
|
||||
"_location": "/array-flatten",
|
||||
"_nodeVersion": "11.3.0",
|
||||
"_npmOperationalInternal": {
|
||||
"host": "s3://npm-registry-packages",
|
||||
"tmp": "tmp/array-flatten_2.1.2_1543796514917_0.6725103941555342"
|
||||
},
|
||||
"_npmUser": {
|
||||
"email": "hello@blakeembrey.com",
|
||||
"name": "blakeembrey"
|
||||
},
|
||||
"_npmVersion": "6.4.1",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"name": "array-flatten",
|
||||
"raw": "array-flatten@^2.1.0",
|
||||
"rawSpec": "^2.1.0",
|
||||
"scope": null,
|
||||
"spec": ">=2.1.0 <3.0.0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/bonjour"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-2.1.2.tgz",
|
||||
"_shasum": "24ef80a28c1a893617e2149b0c6d0d788293b099",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "array-flatten@^2.1.0",
|
||||
"_where": "/home/ppinto/temp/spark/src/web/ui/node_modules/bonjour",
|
||||
"author": {
|
||||
"email": "hello@blakeembrey.com",
|
||||
"name": "Blake Embrey",
|
||||
"url": "http://blakeembrey.me"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/blakeembrey/array-flatten/issues"
|
||||
},
|
||||
"dependencies": {},
|
||||
"description": "Flatten nested arrays",
|
||||
"devDependencies": {
|
||||
"benchmarked": "^2.0.0",
|
||||
"istanbul": "^0.4.0",
|
||||
"mocha": "^3.1.2",
|
||||
"standard": "^10.0.0"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"fileCount": 5,
|
||||
"integrity": "sha512-hNfzcOV8W4NdualtqBFPyVO+54DSJuZGY9qT4pRroB6S9e3iiido2ISIC5h9R2sPJ8H3FHCIiEnsv1lPXO3KtQ==",
|
||||
"npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcBHcjCRA9TVsSAnZWagAA6C4P/1ZV77yfnxvhR9WUixth\nVTQCT4TxIWY/qRmFV8IldijazpVvtKAEkJjdsetwDCoq0Qtt0fJciJQl8+Hi\nPgS19C5sI0bBLuxeCSwbIUKYQon7vCMB6xoR40J8LbM+L7CLczENo2CmilCD\nwMXe6m8dxRPcNaIRY0GhnDDyMx6D7ZANaEu/8D0CKB8zO64I+w6nIUmO287N\nPZQA5hRQz1W1mI+w+J+j2MRYTouqhkPa/FWcdC5o/PF5QoOXpcOXfHYLazCw\nuNEiRIDjrQo4bZ0xYk0YN6iL7PSczJeAXtUB0gHJvIBX4or/Sp4d+RZRAeQA\neCfgnVJ6ayxbgg3nAHDKAqqyOkgC+WZ9BPxbG7x+kL4O8A/bdLetBnP7K8HS\nxetv8WEn5T5t/a7q/crzp81HZPM0MxNeCiRF49Zi41swmoHghN1SH5jWoWKJ\nKfM7TqBgbgsHtY5zlig+y079AfOal73wlVHwDyyNVdMXgv3wv5x1slBSvvx/\nQ4mDOf/7Fi/4Tys/4slYslqpWyFdwKwa4wZrLtw6H6ZoBLj9NonwdrttYIjE\ndWLMi+AiQC0/xAP1FAOrKf9PPasVdnqNZFoRYIqF6OtWX/4DaepSpPY4SL+v\ns+L/hhLP7PLgeDlv0qr/lH4Fa9fglPitQcdIedgP8UZAx/zfCULbkwPvv+XG\n/wqD\r\n=I6rO\r\n-----END PGP SIGNATURE-----\r\n",
|
||||
"shasum": "24ef80a28c1a893617e2149b0c6d0d788293b099",
|
||||
"tarball": "https://registry.npmjs.org/array-flatten/-/array-flatten-2.1.2.tgz",
|
||||
"unpackedSize": 6242
|
||||
},
|
||||
"gitHead": "04b45e7a5a9fb7e7946a1321287a09e84f1d352d",
|
||||
"homepage": "https://github.com/blakeembrey/array-flatten",
|
||||
"keywords": [
|
||||
"arguments",
|
||||
"array",
|
||||
"depth",
|
||||
"fast",
|
||||
"flatten",
|
||||
"for"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "array-flatten.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "blakeembrey",
|
||||
"email": "hello@blakeembrey.com"
|
||||
}
|
||||
],
|
||||
"name": "array-flatten",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/blakeembrey/array-flatten.git"
|
||||
},
|
||||
"scripts": {
|
||||
"benchmark": "node benchmark",
|
||||
"lint": "standard",
|
||||
"test": "npm run lint && npm run test-cov",
|
||||
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- -R spec --bail",
|
||||
"test-spec": "mocha -R spec --bail"
|
||||
},
|
||||
"typings": "array-flatten.d.ts",
|
||||
"version": "2.1.2"
|
||||
}
|
||||
Reference in new issue
Block a user