8000 Refactor package in TypeScript, simplify interface · blakeembrey/array-flatten@8de93a1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8de93a1

Browse files
committed
Refactor package in TypeScript, simplify interface
1 parent 7e0e513 commit 8de93a1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+9587
-3171
lines changed

.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
.DS_Store
2-
node_modules
3-
coverage
2+
.vscode/
3+
dist/
4+
dist.es2015/
5+
node_modules/
6+
coverage/
47
npm-debug.log

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ notifications:
66
on_failure: change
77

88
node_js:
9-
- "6"
9+
- "8"
1010
- "stable"
1111

1212
after_script: "npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"

README.md

Lines changed: 9 additions & 16 deletions
3262
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[![NPM downloads][downloads-image]][downloads-url]
55
[![Build status][travis-image]][travis-url]
66
[![Test coverage][coveralls-image]][coveralls-url]
7+
[![Bundle size][bundlephobia-image]][bundlephobia-url]
78

89
> Flatten nested arrays.
910
@@ -15,27 +16,17 @@ npm install array-flatten --save
1516

1617
## Usage
1718

18-
```javascript
19-
var flatten = require('array-flatten')
19+
```js
20+
import { flatten } from "array-flatten";
2021

21-
flatten([1, [2, [3, [4, [5], 6], 7], 8], 9])
22+
flatten([1, [2, [3, [4, [5], 6], 7], 8], 9]);
2223
//=> [1, 2, 3, 4, 5, 6, 7, 8, 9]
2324

24-
flatten.depth([1, [2, [3, [4, [5], 6], 7], 8], 9], 2)
25-
//=> [1, 2, 3, [4, [5], 6], 7, 8, 9]
26-
27-
(function () {
28-
flatten.from(arguments) //=> [1, 2, 3]
29-
})(1, [2, 3])
25+
(function() {
26+
flatten(arguments); //=> [1, 2, 3]
27+
})(1, [2, 3]);
3028
```
3129

32-
### Methods
33-
34-
* **flatten(array)** Flatten a nested array structure
35-
* **flatten.from(arrayish)** Flatten an array-like structure (E.g. arguments)
36-
* **flatten.depth(array, depth)** Flatten a nested array structure with a specific depth
37-
* **flatten.fromDepth(arrayish, depth)** Flatten an array-like structure with a specific depth
38-
3930
## License
4031

4132
MIT
@@ -48,3 +39,5 @@ MIT
4839
[travis-url]: https://travis-ci.org/blakeembrey/array-flatten
4940
[coveralls-image]: https://img.shields.io/coveralls/blakeembrey/array-flatten.svg?style=flat
5041
[coveralls-url]: https://coveralls.io/r/blakeembrey/array-flatten?branch=master
42+
[bundlephobia-image]: https://img.shields.io/bundlephobia/minzip/array-flatten.svg
43+
[bundlephobia-url]: https://bundlephobia.com/result?p=array-flatten

array-flatten.d.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

array-flatten.js

Lines changed: 0 additions & 108 deletions
This file was deleted.

benchmark/code/arguments/pass-as-arguments.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

benchmark/code/arguments/pass-as-for.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

benchmark/code/arguments/pass-as-slice.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

benchmark/code/concat.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = flatten;
2+
3+
function flatten(array) {
4+
var result = Array.prototype.concat.apply([], array);
5+
6+
if (result.length === array.length) {
7+
return result;
8+
}
9+
10+
return flatten(result);
11+
}

benchmark/code/current.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const { flatten } = require("../../dist");
2+
3+
module.exports = flatten;

0 commit comments

Comments
 (0)
0