Skip to content

Commit d7476d4

Browse files
committed
Require Node.js 12 and move to ESM
1 parent 54f3404 commit d7476d4

File tree

10 files changed

+74
-101
lines changed

10 files changed

+74
-101
lines changed

.editorconfig

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ charset = utf-8
77
trim_trailing_whitespace = true
88
insert_final_newline = true
99

10-
[{package.json,*.yml}]
10+
[*.yml]
1111
indent_style = space
1212
indent_size = 2
13-
14-
[*.md]
15-
trim_trailing_whitespace = false

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* text=auto
1+
* text=auto eol=lf

.github/workflows/main.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,9 @@ jobs:
1212
node-version:
1313
- 14
1414
- 12
15-
- 10
16-
- 8
17-
- 6
18-
- 4
19-
- 0.12
20-
- 0.1
2115
steps:
2216
- uses: actions/checkout@v2
23-
- uses: actions/setup-node@v1
17+
- uses: actions/setup-node@v2
2418
with:
2519
node-version: ${{ matrix.node-version }}
2620
- run: npm install

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
yarn.lock

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

index.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
'use strict';
2-
module.exports = function (item, n) {
3-
var ret = new Array(n);
4-
var isFn = typeof item === 'function';
1+
export default function filledArray(fillValue, count) {
2+
const returnValue = Array.from({length: count});
3+
const isFunction = typeof fillValue === 'function';
54

6-
if (!isFn && typeof ret.fill === 'function') {
7-
return ret.fill(item);
5+
if (!isFunction) {
6+
return returnValue.fill(fillValue);
87
}
98

10-
for (var i = 0; i < n; i++) {
11-
ret[i] = isFn ? item(i, n, ret) : item;
9+
for (let index = 0; index < count; index++) {
10+
returnValue[index] = isFunction ? fillValue(index, count, returnValue) : fillValue;
1211
}
1312

14-
return ret;
15-
};
13+
return returnValue;
14+
}

license

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
1-
The MIT License (MIT)
1+
MIT License
22

3-
Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)
3+
Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com)
44

5-
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
7-
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
copies of the Software, and to permit persons to whom the Software is
10-
furnished to do so, subject to the following conditions:
5+
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:
116

12-
The above copyright notice and this permission notice shall be included in
13-
all copies or substantial portions of the Software.
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
148

15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21-
THE SOFTWARE.
9+
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.

package.json

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,38 @@
11
{
2-
"name": "filled-array",
3-
"version": "1.1.0",
4-
"description": "Returns an array filled with the specified input",
5-
"license": "MIT",
6-
"repository": "sindresorhus/filled-array",
7-
"author": {
8-
"name": "Sindre Sorhus",
9-
"email": "[email protected]",
10-
"url": "sindresorhus.com"
11-
},
12-
"engines": {
13-
"node": ">=0.10.0"
14-
},
15-
"scripts": {
16-
"test": "xo && ava"
17-
},
18-
"files": [
19-
"index.js"
20-
],
21-
"keywords": [
22-
"array",
23-
"elements",
24-
"el",
25-
"filled",
26-
"repeat",
27-
"repeating",
28-
"string",
29-
"str",
30-
"text",
31-
"fill"
32-
],
33-
"devDependencies": {
34-
"ava": "*",
35-
"xo": "*"
36-
}
2+
"name": "filled-array",
3+
"version": "1.1.0",
4+
"description": "Returns an array filled with the specified input",
5+
"license": "MIT",
6+
"repository": "sindresorhus/filled-array",
7+
"funding": "https://github.com/sponsors/sindresorhus",
8+
"author": {
9+
"name": "Sindre Sorhus",
10+
"email": "[email protected]",
11+
"url": "https://sindresorhus.com"
12+
},
13+
"type": "module",
14+
"exports": "./index.js",
15+
"engines": {
16+
"node": ">=12"
17+
},
18+
"scripts": {
19+
"test": "xo && ava"
20+
},
21+
"files": [
22+
"index.js"
23+
],
24+
"keywords": [
25+
"array",
26+
"elements",
27+
"filled",
28+
"repeat",
29+
"repeating",
30+
"string",
31+
"text",
32+
"fill"
33+
],
34+
"devDependencies": {
35+
"ava": "^3.15.0",
36+
"xo": "^0.38.2"
37+
}
3738
}

readme.md

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,36 @@
22

33
> Returns an array filled with the specified input
44
5-
65
## Install
76

87
```
9-
$ npm install --save filled-array
8+
$ npm install filled-array
109
```
1110

12-
1311
## Usage
1412

1513
```js
16-
const filledArray = require('filled-array');
14+
import filledArray from 'filled-array';
1715

1816
filledArray('x', 3);
1917
//=> ['x', 'x', 'x']
2018

2119
filledArray(0, 3);
2220
//=> [0, 0, 0]
2321

24-
filledArray(i => {
25-
return (++i % 3 ? '' : 'Fizz') + (i % 5 ? '' : 'Buzz') || i;
22+
filledArray(index => {
23+
return (++index % 3 ? '' : 'Fizz') + (index % 5 ? '' : 'Buzz') || index;
2624
}, 15);
2725
//=> [1, 2, 'Fizz', 4, 'Buzz', 'Fizz', 7, 8, 'Fizz', 'Buzz', 11, 'Fizz', 13, 14, 'FizzBuzz']
2826
```
2927

30-
3128
## API
3229

33-
### filledArray(filler, count)
30+
### filledArray(fillValue, count)
3431

35-
#### filler
32+
#### fillValue
3633

37-
Type: Any
34+
Type: `unknown`
3835

3936
Value to fill the array with.
4037

@@ -45,8 +42,3 @@ You can pass a function to generate the array items dynamically. The function is
4542
Type: `number`
4643

4744
Number of items to fill the array with.
48-
49-
50-
## License
51-
52-
MIT © [Sindre Sorhus](http://sindresorhus.com)

test.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import test from 'ava';
2-
import fn from './';
2+
import filledArray from './index.js';
33

44
function indexPlus(index) {
55
return index + 1;
@@ -10,20 +10,20 @@ function fizzBuzz(index) {
1010
}
1111

1212
function comprehensive(index, length, partial) {
13-
return partial.indexOf(index) === -1 ? index + 1 : length;
13+
return partial.includes(index) ? length : index + 1;
1414
}
1515

16-
test(t => {
17-
t.deepEqual(fn('a', 0), []);
18-
t.deepEqual(fn('a', 1), ['a']);
19-
t.deepEqual(fn('a', 2), ['a', 'a']);
20-
t.deepEqual(fn('a', 5), ['a', 'a', 'a', 'a', 'a']);
21-
t.deepEqual(fn('foo', 2), ['foo', 'foo']);
22-
t.deepEqual(fn(0, 2), [0, 0]);
23-
t.deepEqual(fn(indexPlus, 5), [1, 2, 3, 4, 5]);
16+
test('main', t => {
17+
t.deepEqual(filledArray('a', 0), []);
18+
t.deepEqual(filledArray('a', 1), ['a']);
19+
t.deepEqual(filledArray('a', 2), ['a', 'a']);
20+
t.deepEqual(filledArray('a', 5), ['a', 'a', 'a', 'a', 'a']);
21+
t.deepEqual(filledArray('foo', 2), ['foo', 'foo']);
22+
t.deepEqual(filledArray(0, 2), [0, 0]);
23+
t.deepEqual(filledArray(indexPlus, 5), [1, 2, 3, 4, 5]);
2424
t.deepEqual(
25-
fn(fizzBuzz, 15),
25+
filledArray(fizzBuzz, 15),
2626
[1, 2, 'Fizz', 4, 'Buzz', 'Fizz', 7, 8, 'Fizz', 'Buzz', 11, 'Fizz', 13, 14, 'FizzBuzz']
2727
);
28-
t.deepEqual(fn(comprehensive, 5), [1, 5, 3, 5, 5]);
28+
t.deepEqual(filledArray(comprehensive, 5), [1, 5, 3, 5, 5]);
2929
});

0 commit comments

Comments
 (0)