Skip to content

Commit af6a6a1

Browse files
outslept43081j
andauthored
docs: transported docs from e18e; slight stylistic cleanup (#258)
* a * extra * core-util-us + update index * make shell stuff a bit more distinguishable * fix diffs for chalk page * extra space * bash * remote html comment noway i did this with a regex find and replace * :/ * add description frontmatter for lodash-underscore doc * remove all the info from lodash doc to match the style * ts -> diff codeblock * Update js-yaml.md * thank you james * js -> ts * tson -> json * remove process-exec (old file) * change docPaths & sort manifests * Update docs/modules/globby.md Co-authored-by: James Garbutt <43081j@users.noreply.github.com> * Update find-up.md * Update find-up.md * Update docs/modules/tempy.md Co-authored-by: James Garbutt <43081j@users.noreply.github.com> * Update docs/modules/tempy.md Co-authored-by: James Garbutt <43081j@users.noreply.github.com> --------- Co-authored-by: James Garbutt <43081j@users.noreply.github.com>
1 parent 6510e22 commit af6a6a1

69 files changed

Lines changed: 2132 additions & 899 deletions

Some content is hidden

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

docs/modules/README.md

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ ESLint plugin.
1212

1313
## List of modules
1414

15-
- [`@jsdevtools/ez-spawn`](./process-exec.md)
15+
- [`@jsdevtools/ezspawn`](./ez-spawn.md)
1616
- [`axios`](./axios.md)
17-
- [`bluebird` / `q`](./bluebird-q.md)
17+
- [`bluebird`](./bluebird-q.md)
1818
- [`body-parser`](./body-parser.md)
1919
- [`buf-compare`](./buf-compare.md)
20-
- [`buffer-equal` / `buffer-equals`](./buffer-equal.md)
20+
- [`buffer-equal`](./buffer-equal.md)
21+
- [`buffer-equals`](./buffer-equals.md)
22+
- [`builtin-modules`](./builtin-modules.md)
2123
- [`chalk`](./chalk.md)
22-
- [`core-util-is`](./core-util-is.md)
24+
| [`core-util-is`](./core-util-is.md)
2325
- [`cpx`](./cpx.md)
2426
- [`deep-equal`](./deep-equal.md)
2527
- [`depcheck`](./depcheck.md)
@@ -32,32 +34,39 @@ ESLint plugin.
3234
- [`eslint-plugin-node`](./eslint-plugin-node.md)
3335
- [`eslint-plugin-react`](./eslint-plugin-react.md)
3436
- [`eslint-plugin-vitest`](./eslint-plugin-vitest.md)
35-
- [`execa`](./process-exec.md)
36-
- [`ezspawn`](./process-exec.md)
37+
- [`execa`](./execa.md)
38+
- [`ezspawn`](./ez-spawn.md)
3739
- [`faker`](./faker.md)
38-
- [`fast-glob`](./glob.md)
39-
- [`find-up` and related](./find-up.md)
40+
- [`fast-glob`](./fast-glob.md)
41+
- [`find-cache-dir`](./find-cache-dir.md)
42+
- [`find-cache-directory`](./find-cache-directory.md)
43+
- [`find-file-up`](./find-file-up.md)
44+
- [`find-pkg`](./find-pkg.md)
45+
- [`find-up`](./find-up.md)
4046
- [`fs-extra`](./fs-extra.md)
4147
- [`glob`](./glob.md)
42-
- [`globby`](./glob.md)
43-
- [`grapheme`](./grapheme.md)
48+
- [`globby`](./globby.md)
49+
- [`graphemer`](./graphemer.md)
4450
- [`invariant`](./invariant.md)
4551
- [`is-builtin-module`](./is-builtin-module.md)
4652
- [`jQuery`](./jquery.md)
4753
- [`js-yaml`](./js-yaml.md)
4854
- [`jsx-ast-utils`](./jsx-ast-utils.md)
4955
- [`lint-staged`](./lint-staged.md)
5056
- [`lodash`, `underscore` and related](./lodash-underscore.md)
51-
- [`make-dir`](./mkdirp.md)
52-
- [`MaterializeCSS`](./materialize-css.md)
57+
- [`materialize-css`](./materialize-css.md)
5358
- [`md5`](./md5.md)
5459
- [`mkdirp`](./mkdirp.md)
55-
- [`moment.js`](./momentjs.md)
60+
- [`moment.js`](./moment.md)
5661
- [`npm-run-all`](./npm-run-all.md)
5762
- [`object-hash`](./object-hash.md)
5863
- [`ora`](./ora.md)
5964
- [`path-exists`](./path-exists.md)
65+
- [`pkg-dir`](./pkg-dir.md)
6066
- [`qs`](./qs.md)
67+
- [`read-pkg`](./read-pkg.md)
68+
- [`read-pkg-up`](./read-pkg-up.md)
69+
- [`read-package-up`](./read-package-up.md)
6170
- [`readable-stream`](./readable-stream.md)
6271
- [`rimraf`](./rimraf.md)
6372
- [`shortid`](./shortid.md)
@@ -67,4 +76,4 @@ ESLint plugin.
6776
- [`tempy`](./tempy.md)
6877
- [`traverse`](./traverse.md)
6978
- [`uri-js`](./uri-js.md)
70-
- [`xmldom`](./xmldom.md)
79+
- [`xmldom`](./xmldom.md)

docs/modules/axios.md

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,58 @@
1-
# axios
1+
---
2+
description: Modern alternatives to the axios package for making HTTP requests in browsers and Node.js
3+
---
24

3-
`axios` is a popular HTTP client library, but modern JavaScript and Node.js provide native alternatives that can often replace it for many use cases.
4-
5-
# Alternatives
5+
# Replacements for `axios`
66

77
## Native `fetch` API
88

9-
The native `fetch` API is now available in Node.js (since v18.x) and all modern browsers. For most HTTP requests, it can replace axios without additional dependencies.
9+
The native [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) API is available in Node.js (since v18.x) and all modern browsers. For most HTTP requests, it can replace `axios` without extra dependencies.
10+
11+
Example:
1012

11-
```js
12-
// GET request
13-
const response = await fetch('https://api.example.com/data');
14-
const data = await response.json();
13+
```ts
14+
// GET
15+
const res = await fetch('https://api.example.com/data')
16+
const data = await res.json()
1517

16-
// POST request with JSON
17-
const response = await fetch('https://api.example.com/data', {
18+
// POST
19+
await fetch('https://api.example.com/data', {
1820
method: 'POST',
19-
headers: {
20-
'Content-Type': 'application/json',
21-
},
21+
headers: { 'Content-Type': 'application/json' },
2222
body: JSON.stringify({ key: 'value' })
23-
});
23+
})
2424
```
2525

26-
[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
26+
## `ky`
27+
28+
[`ky`](https://github.com/sindresorhus/ky) is a lightweight HTTP client based on the Fetch API with timeout support, hooks (interceptors) and other helpers.
2729

28-
## ky
30+
Example:
2931

30-
`ky` is a tiny and elegant HTTP client based on the Fetch API. It provides a more convenient API than raw fetch while being much smaller than axios. Also, includes `hooks` (interceptors) for request/response modification.
32+
```ts
33+
import ky from 'ky'
3134

32-
[Project Page](https://github.com/sindresorhus/ky)
33-
[npm](https://www.npmjs.com/package/ky)
35+
const api = ky.create({
36+
prefixUrl: 'https://api.example.com',
37+
timeout: 5000, // ms
38+
})
39+
40+
const data = await api.get('users').json()
41+
```
3442

35-
## ofetch
43+
## `ofetch`
3644

37-
`ofetch` is a better fetch API with automatic response parsing, request/response interceptors, and retry functionality.
45+
[`ofetch`](https://github.com/unjs/ofetch) s a fetch wrapper with automatic JSON parsing, request/response interceptors, and retries.
3846

39-
[Project Page](https://github.com/unjs/ofetch)
40-
[npm](https://www.npmjs.com/package/ofetch)
47+
Example:
48+
49+
```ts
50+
import { ofetch } from 'ofetch'
51+
52+
const api = ofetch.create({
53+
baseURL: 'https://api.example.com',
54+
})
55+
56+
const data = await api('/user', { query: { id: 123 } })
57+
const created = await api('/items', { method: 'POST', body: { name: 'A' } })
58+
```

docs/modules/bluebird-q.md

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
# `bluebird` / `q`
1+
---
2+
description: Modern alternatives to the Bluebird and Q Promise libraries for async control flow in JavaScript
3+
---
24

3-
[`bluebird`](https://github.com/petkaantonov/bluebird?tab=readme-ov-file#%EF%B8%8Fnote%EF%B8%8F) and [`q`](https://github.com/kriskowal/q#note) recommends that you switch away from them to native promises.
5+
# Replacements for `bluebird` / `q`
46

5-
# Alternatives
7+
## `Promise` (native)
68

7-
## Native JavaScript `Promise`
8-
9-
For most cases, native JavaScript `Promise` is enough.
10-
11-
[MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
9+
[`bluebird`](https://github.com/petkaantonov/bluebird?tab=readme-ov-file#%EF%B8%8Fnote%EF%B8%8F) and [`q`](https://github.com/kriskowal/q#note) recommend switching away from them to native promises.
1210

1311
## NativeBird
1412

15-
Ultralight native `Promise` extension compatible with `bluebird` if you need some helpers missed in native JavaScript `Promise`.
16-
17-
[Project Page](https://github.com/doodlewind/nativebird)
18-
[npm](https://www.npmjs.com/package/nativebird)
13+
[`NativeBird`](https://github.com/doodlewind/nativebird) is an ultralight native `Promise` extension that provides Bluebird-like helpers if you miss a few conveniences from Bluebird.

docs/modules/body-parser.md

Lines changed: 17 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,27 @@
1-
# Body-parser
1+
---
2+
description: Modern alternatives to the body-parser package for parsing HTTP request bodies in Node.js servers
3+
---
24

3-
`body-parser` can be replaced with more modern alternatives which are both lighter and faster.
5+
# Replacements for `body-parser`
46

5-
# Alternatives
7+
## `milliparsec`
68

7-
## Native Implementation
9+
[`milliparsec`](https://github.com/tinyhttp/milliparsec) is a lightweight alternative to [`body-parser`](https://github.com/expressjs/body-parser) with a smaller footprint.
810

9-
For simple use cases, you can implement a minimal body parser in vanilla JavaScript:
11+
Example:
1012

11-
```js
12-
const sizeLimit = 10 * 1024; // limit body size to 10kB
13-
req.body = {};
13+
```ts
14+
import bodyParser from 'body-parser' // [!code --]
15+
import { json, urlencoded } from 'milliparsec' // [!code ++]
16+
import express from 'express'
1417

15-
await new Promise(function(res, rej) {
16-
let buffers = [];
17-
let size = 0;
18+
const app = express()
1819

19-
// parse each chunk and append them into Buffer array
20-
req.on('data', chunk => {
21-
size += chunk.length;
22-
if (size > sizeLimit) {
23-
return rej(new Error('Size limit'));
24-
}
20+
app.use(bodyParser.json()) // [!code --]
21+
app.use(bodyParser.urlencoded({ extended: true })) // [!code --]
2522

26-
buffers.push(chunk);
27-
});
28-
29-
req.on('end', () => res(buffers));
30-
})
31-
.then(function(buffers) {
32-
if (!buffers.length) return;
33-
34-
try {
35-
req.body = JSON.parse(Buffer.concat(buffers).toString());
36-
} catch (err) {
37-
return Promise.reject(new Error('Invalid JSON: ' + err.message));
38-
}
39-
});
23+
app.use(json()) // [!code ++]
24+
app.use(urlencoded()) // [!code ++]
4025
```
4126

42-
Do note that the above implementation lacks sophisticated features such as better error handling, timeouts, flexible size limits, etc.
43-
44-
45-
## milliparsec
46-
47-
`milliparsec` a modern `body-parser` alternative that supports `async / await`, lighter (8 kB vs 62.6 kB for `body-parser`), and [30% faster](https://github.com/tinyhttp/milliparsec/blob/master/bench/index.md)
48-
49-
[Project Page](https://github.com/tinyhttp/milliparsec)
50-
[npm](https://www.npmjs.com/package/milliparsec)
51-
27+
For API differences and feature comparison, see the [migration.md](https://github.com/tinyhttp/milliparsec/blob/master/migration.md).

docs/modules/buf-compare.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
# buf-compare
1+
---
2+
description: Native Node.js alternatives to the buf-compare package for buffer comparison
3+
---
24

3-
[`buf-compare`](https://github.com/sindresorhus/buf-compare) recommends that you switch to native `Buffer.compare()` which has been available since Node.js v0.12.0
5+
# Replacements for `buf-compare`
46

5-
# Alternatives
7+
## `Buffer.compare` (native)
68

7-
## Node.js
9+
`Buffer.compare` is a native method which achieves the same result as `buf-compare`, available since Node v0.11.13.
810

9-
```js
10-
import {Buffer} from 'node:buffer';
11+
Example:
1112

12-
const buf1 = Buffer.from('1234');
13-
const buf2 = Buffer.from('0123');
14-
const arr = [buf1, buf2];
13+
```ts
14+
import { Buffer } from 'node:buffer'
15+
import bufCompare from 'buf-compare' // [!code --]
1516
16-
console.log(arr.sort(Buffer.compare));
17-
// Prints: [ <Buffer 30 31 32 33>, <Buffer 31 32 33 34> ]
18-
// (This result is equal to: [buf2, buf1].)
19-
```
17+
const buf1 = Buffer.from('303')
18+
const buf2 = Buffer.from('808')
2019

21-
[Node.js Docs](https://nodejs.org/api/buffer.html#static-method-buffercomparebuf1-buf2)
20+
bufCompare(buf1, buf2) // [!code --]
21+
Buffer.compare(buf1, buf2) // [!code ++]
22+
```

docs/modules/buffer-equal.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1-
# `buffer-equal`/`buffer-equals`
1+
---
2+
description: Native Node.js alternatives to the buffer-equal package for buffer equality checks
3+
---
24

3-
[`buffer-equal`](https://www.npmjs.com/package/buffer-equal) and [`buffer-equals`](https://www.npmjs.com/package/buffer-equals) recommends that you switch away from them to native `Buffer.prototype.equals` which has been available since Node.js v0.11.13
5+
# Replacements for `buffer-equal`
46

5-
# Alternative(s)
7+
## `Buffer#equals` (native)
68

7-
## Native `Buffer.prototype.equals`
9+
Buffers have an `equals` method since Node 0.12.
810

9-
For most cases, native Node.js `Buffer.prototype.equals` is enough.
11+
Example:
1012

11-
[Node.js Docs](https://nodejs.org/api/buffer.html#bufequalsotherbuffer)
13+
```ts
14+
import { Buffer } from 'node:buffer'
15+
import bufferEqual from 'buffer-equal' // [!code --]
16+
17+
const buf1 = Buffer.from('303')
18+
const buf2 = Buffer.from('303')
19+
20+
bufferEqual(buf1, buf2) // [!code --]
21+
buf1.equals(buf2) // [!code ++]
22+
```

docs/modules/buffer-equals.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
description: Native Node.js alternatives to the buffer-equals package for buffer equality checks
3+
---
4+
5+
# Replacements for `buffer-equals`
6+
7+
## `Buffer#equals` (native)
8+
9+
Buffers have an `equals` method since Node 0.12.
10+
11+
Example:
12+
13+
```ts
14+
import { Buffer } from 'node:buffer'
15+
import bufferEquals from 'buffer-equals' // [!code --]
16+
17+
const buf1 = Buffer.from('303')
18+
const buf2 = Buffer.from('303')
19+
20+
bufferEquals(buf1, buf2) // [!code --]
21+
buf1.equals(buf2) // [!code ++]
22+
```

docs/modules/builtin-modules.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
description: Native Node.js alternatives to the builtin-modules package for listing built-in modules
3+
---
4+
5+
# Replacements for `builtin-modules`
6+
7+
## Node.js (since 6.x)
8+
9+
For getting the list of built-in modules, you can use [builtinModules](https://nodejs.org/api/module.html#modulebuiltinmodules):
10+
11+
```ts
12+
import builtinModulesList from 'builtin-modules' // [!code --]
13+
import { builtinModules } from 'node:module' // [!code ++]
14+
15+
builtinModulesList.includes('fs') // true [!code --]
16+
builtinModules.includes('fs') // true [!code ++]
17+
```

0 commit comments

Comments
 (0)