Skip to content

Commit 33c485a

Browse files
committed
Update ESLint, update ESLint config, configure Prettier, format all files using new config
1 parent fe27b90 commit 33c485a

29 files changed

+955
-877
lines changed

.babelrc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
"presets": ["@babel/env"],
33
"env": {
44
"production-esm": {
5-
"presets": [
6-
["@babel/env", { "modules": false }]
7-
]
5+
"presets": [["@babel/env", { "modules": false }]]
86
},
97
"test": {
108
"presets": [
11-
["@babel/env", {
12-
"targets": {
13-
"node": "current"
9+
[
10+
"@babel/env",
11+
{
12+
"targets": {
13+
"node": "current"
14+
}
1415
}
15-
}]
16+
]
1617
]
1718
}
1819
}

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
yarn pretty-quick --staged

.prettierignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.cache
2+
.yarn
3+
coverage
4+
dist
5+
*.yml

.prettierrc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"printWidth": 100,
3+
"singleQuote": true,
4+
"trailingComma": "all"
5+
}

.vscode/extensions.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
{
2-
"recommendations": [
3-
"dbaeumer.vscode-eslint",
4-
"eamodio.gitlens"
5-
],
6-
"unwantedRecommendations": [
7-
"dbaeumer.jshint"
8-
]
2+
"recommendations": ["dbaeumer.vscode-eslint", "eamodio.gitlens", "esbenp.prettier-vscode"],
3+
"unwantedRecommendations": ["dbaeumer.jshint"]
94
}

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
2+
"editor.defaultFormatter": "esbenp.prettier-vscode",
3+
"editor.formatOnSave": true,
24
"search.exclude": {
35
"**/.yarn": true
46
}

README.md

Lines changed: 46 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
11
[![npm](https://img.shields.io/npm/v/@wojtekmaj/async-array-utils.svg)](https://www.npmjs.com/package/@wojtekmaj/async-array-utils) ![downloads](https://img.shields.io/npm/dt/@wojtekmaj/async-array-utils.svg) [![CI](https://github.com/wojtekmaj/async-array-utils/workflows/CI/badge.svg)](https://github.com/wojtekmaj/async-array-utils/actions) [![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://github.com/facebook/jest)
22

33
# Async-Array-Utils
4+
45
A collection of array-related async utilities.
56

67
## tl;dr
7-
* Install by executing `npm install @wojtekmaj/async-array-utils` or `yarn add @wojtekmaj/async-array-utils`.
8-
* Import by adding `import * as asyncArrayUtils from '@wojtekmaj/async-array-utils'`.
9-
* Do stuff with it!
10-
```js
11-
const asyncMappedArr = await asyncMap([1, 2, 3], async (x) => x * 2);
12-
```
8+
9+
- Install by executing `npm install @wojtekmaj/async-array-utils` or `yarn add @wojtekmaj/async-array-utils`.
10+
- Import by adding `import * as asyncArrayUtils from '@wojtekmaj/async-array-utils'`.
11+
- Do stuff with it!
12+
```js
13+
const asyncMappedArr = await asyncMap([1, 2, 3], async (x) => x * 2);
14+
```
1315

1416
## User guide
1517

1618
### Table of contents
1719

18-
* [`asyncEvery()`](#asyncEvery)
19-
* [`asyncEveryStrict()`](#asyncEveryStrict)
20-
* [`asyncFilter()`](#asyncFilter)
21-
* [`asyncFilterStrict()`](#asyncFilterStrict)
22-
* [`asyncForEach()`](#asyncForEach)
23-
* [`asyncForEachStrict()`](#asyncForEachStrict)
24-
* [`asyncMap()`](#asyncMap)
25-
* [`asyncMapStrict()`](#asyncMapStrict)
26-
* [`asyncReduce()`](#asyncReduce)
27-
* [`asyncSome()`](#asyncSome)
28-
* [`asyncSomeStrict()`](#asyncSomeStrict)
20+
- [`asyncEvery()`](#asyncEvery)
21+
- [`asyncEveryStrict()`](#asyncEveryStrict)
22+
- [`asyncFilter()`](#asyncFilter)
23+
- [`asyncFilterStrict()`](#asyncFilterStrict)
24+
- [`asyncForEach()`](#asyncForEach)
25+
- [`asyncForEachStrict()`](#asyncForEachStrict)
26+
- [`asyncMap()`](#asyncMap)
27+
- [`asyncMapStrict()`](#asyncMapStrict)
28+
- [`asyncReduce()`](#asyncReduce)
29+
- [`asyncSome()`](#asyncSome)
30+
- [`asyncSomeStrict()`](#asyncSomeStrict)
2931

3032
### `asyncEvery()`
3133

@@ -51,13 +53,10 @@ Like `asyncEvery()`, but runs iterations non-concurrently.
5153
import { asyncEveryStrict } from '@wojtekmaj/async-array-utils';
5254

5355
const indexes = [];
54-
const largerThanZero = await asyncEveryStrict(
55-
[1, 2, 3],
56-
async (el, index) => {
57-
indexes.push(index);
58-
return el > 0;
59-
},
60-
); // true
56+
const largerThanZero = await asyncEveryStrict([1, 2, 3], async (el, index) => {
57+
indexes.push(index);
58+
return el > 0;
59+
}); // true
6160
console.log(indexes); // [0, 1, 2]
6261
```
6362

@@ -85,13 +84,10 @@ Like `asyncFilter()`, but runs iterations non-concurrently.
8584
import { asyncFilterStrict } from '@wojtekmaj/async-array-utils';
8685

8786
const indexes = [];
88-
const asyncFilteredArr = await asyncFilterStrict(
89-
[1, 2, 3],
90-
async (el, index) => {
91-
indexes.push(index);
92-
return el > 1;
93-
},
94-
); // [2, 3]
87+
const asyncFilteredArr = await asyncFilterStrict([1, 2, 3], async (el, index) => {
88+
indexes.push(index);
89+
return el > 1;
90+
}); // [2, 3]
9591
console.log(indexes); // [0, 1, 2]
9692
```
9793

@@ -106,10 +102,9 @@ Note: For optimization purposes, all iterations are ran concurrently. If you rel
106102
```js
107103
import { asyncForEach } from '@wojtekmaj/async-array-utils';
108104

109-
await asyncForEach(
110-
[1, 2, 3],
111-
async (el) => { console.log(el * 2); }
112-
); // undefined; 3 console.logs
105+
await asyncForEach([1, 2, 3], async (el) => {
106+
console.log(el * 2);
107+
}); // undefined; 3 console.logs
113108
```
114109

115110
### `asyncForEachStrict()`
@@ -122,13 +117,10 @@ Like `asyncForEach()`, but runs iterations non-concurrently.
122117
import { asyncForEachStrict } from '@wojtekmaj/async-array-utils';
123118

124119
const indexes = [];
125-
await asyncForEachStrict(
126-
[1, 2, 3],
127-
async (el, index) => {
128-
indexes.push(index);
129-
console.log(el * 2);
130-
},
131-
); // undefined; 3 console.logs
120+
await asyncForEachStrict([1, 2, 3], async (el, index) => {
121+
indexes.push(index);
122+
console.log(el * 2);
123+
}); // undefined; 3 console.logs
132124
console.log(indexes); // [0, 1, 2]
133125
```
134126

@@ -156,13 +148,10 @@ Like `asyncMap()`, but runs iterations non-concurrently.
156148
import { asyncMapStrict } from '@wojtekmaj/async-array-utils';
157149

158150
const indexes = [];
159-
const asyncMappedArr = await asyncMapStrict(
160-
[1, 2, 3],
161-
async (el, index) => {
162-
indexes.push(index);
163-
return el * 2;
164-
},
165-
); // [2, 4, 6]
151+
const asyncMappedArr = await asyncMapStrict([1, 2, 3], async (el, index) => {
152+
indexes.push(index);
153+
return el * 2;
154+
}); // [2, 4, 6]
166155
console.log(indexes); // [0, 1, 2]
167156
```
168157

@@ -177,8 +166,10 @@ import { asyncReduce } from '@wojtekmaj/async-array-utils';
177166

178167
const result = await asyncReduce(
179168
[1, 2, 3],
180-
async (tmp, cur, idx) => { return tmp + cur },
181-
0
169+
async (tmp, cur, idx) => {
170+
return tmp + cur;
171+
},
172+
0,
182173
); // 6
183174
```
184175

@@ -206,13 +197,10 @@ Like `asyncSome()`, but runs iterations non-concurrently.
206197
import { asyncSomeStrict } from '@wojtekmaj/async-array-utils';
207198

208199
const indexes = [];
209-
const largerThanZero = await asyncSomeStrict(
210-
[1, 2, 3],
211-
async (el, index) => {
212-
indexes.push(index);
213-
return el > 0;
214-
},
215-
); // true
200+
const largerThanZero = await asyncSomeStrict([1, 2, 3], async (el, index) => {
201+
indexes.push(index);
202+
return el > 0;
203+
}); // true
216204
console.log(indexes); // [0]
217205
```
218206

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"clean": "rimraf dist",
1414
"jest": "jest",
1515
"lint": "eslint src/ --ext .jsx,.js",
16+
"postinstall": "husky install",
1617
"prepack": "yarn clean && yarn build",
1718
"test": "yarn lint && yarn jest"
1819
},
@@ -31,9 +32,12 @@
3132
"@babel/cli": "^7.15.0",
3233
"@babel/core": "^7.15.0",
3334
"@babel/preset-env": "^7.15.0",
34-
"eslint": "~7.19.0",
35-
"eslint-config-wojtekmaj": "^0.5.0",
35+
"eslint": "^8.5.0",
36+
"eslint-config-wojtekmaj": "^0.6.5",
37+
"husky": "^7.0.0",
3638
"jest": "^27.0.0",
39+
"prettier": "^2.5.0",
40+
"pretty-quick": "^3.1.0",
3741
"rimraf": "^3.0.0"
3842
},
3943
"resolutions": {

src/every.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@ import asyncForEach from './forEach';
22

33
export default function asyncSome(arr, fn) {
44
return new Promise((resolve) => {
5-
asyncForEach(arr, (cur, idx, arr2) => new Promise((resolve2) => {
6-
fn(cur, idx, arr2).then((result) => {
7-
if (!result) {
8-
resolve(false);
9-
}
10-
resolve2();
11-
});
12-
}))
13-
.then(() => { resolve(true); });
5+
asyncForEach(
6+
arr,
7+
(cur, idx, arr2) =>
8+
new Promise((resolve2) => {
9+
fn(cur, idx, arr2).then((result) => {
10+
if (!result) {
11+
resolve(false);
12+
}
13+
resolve2();
14+
});
15+
}),
16+
).then(() => {
17+
resolve(true);
18+
});
1419
});
1520
}

src/every.spec.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ function largerOrEqualThanZero(x) {
1313
}
1414

1515
function largerOrEqualThanZeroInRandomTime(x) {
16-
return new Promise(
17-
(resolve) => setTimeout(() => {
16+
return new Promise((resolve) =>
17+
setTimeout(() => {
1818
resolve(x >= 0);
1919
}, Math.random() * 100),
2020
);
@@ -34,7 +34,10 @@ describe('asyncEvery()', () => {
3434

3535
timer.start();
3636

37-
await asyncEvery([1, 2, 3], makeDelayed((el) => el > 0, delay));
37+
await asyncEvery(
38+
[1, 2, 3],
39+
makeDelayed((el) => el > 0, delay),
40+
);
3841

3942
const timeElapsed = timer.stop();
4043

0 commit comments

Comments
 (0)