Skip to content

Commit 87f377e

Browse files
authored
Merge branch 'main' into safe-compare
2 parents e324d04 + aecab99 commit 87f377e

13 files changed

Lines changed: 376 additions & 415 deletions

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ We provide two things:
1111

1212
## List of replacements
1313

14-
You can find a list of replacements in the
15-
[modules readme](./docs/modules/README.md).
14+
You can find a list of replacements on the [e18e website](https://e18e.dev/docs/replacements/).
1615

1716
## Tools
1817

@@ -21,6 +20,8 @@ Some tools consume the lists of modules in this repository:
2120
| Name | Description |
2221
| -------------------------------------------------------------------------- | --------------------------------------------- |
2322
| [eslint-plugin-depend](https://github.com/es-tooling/eslint-plugin-depend) | ESLint plugin to detect possible replacements |
23+
| [@e18e/eslint-plugin](https://github.com/e18e/eslint-plugin) | Official e18e ESLint plugin |
24+
| [npmx](https://npmx.dev) | Alternative npm frontend |
2425

2526
## Manifests
2627

docs/modules/README.md

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

docs/modules/deep-merge.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
description: Modern alternatives to packages for deep merging objects
3+
---
4+
5+
# Replacements for deep merge packages
6+
7+
## `defu`
8+
9+
If you need to deep merge two objects, you can use [`defu`](https://github.com/unjs/defu):
10+
11+
```ts
12+
import { defu } from 'defu'
13+
14+
const options = defu(object, defaults)
15+
```
16+
17+
## `@fastify/deepmerge`
18+
19+
The [`@fastify/deepmerge`](https://github.com/fastify/deepmerge) package is another fast and small alternative.
20+
21+
It also offers more options for customizing the merge behavior than other libraries.
22+
23+
```ts
24+
import deepMerge from '@fastify/deepmerge'
25+
26+
const options = deepMerge(object, defaults)
27+
```

docs/modules/parseargs.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
description: Modern alternatives to CLI argument parsing packages using Node.js built-in util.parseArgs
3+
---
4+
5+
# Replacements for argument parsers
6+
7+
## `util.parseArgs` (native, since Node.js 16.x)
8+
9+
[`util.parseArgs`](https://nodejs.org/api/util.html#utilparseargsconfig) is built into Node.js (since 18.3.0 and 16.17.0) and can replace many common CLI options parsing libraries.
10+
11+
Example:
12+
13+
```ts
14+
import { parseArgs } from 'node:util'
15+
16+
const { values, positionals } = parseArgs({
17+
args: process.argv.slice(2),
18+
options: {
19+
force: { type: 'boolean', short: 'f' },
20+
output: { type: 'string', short: 'o' }
21+
},
22+
allowPositionals: true
23+
})
24+
```
25+
26+
> [!NOTE]
27+
> `parseArgs` only supports `string` and `boolean` types. If you'd like to support stronger types, one of the other options may be a better fit.
28+
29+
## `mri`
30+
31+
[`mri`](https://github.com/lukeed/mri) is a minimalistic argument parser that supports both short and long options, as well as positional arguments.
32+
33+
Example:
34+
35+
```ts
36+
import mri from 'mri'
37+
38+
const options = mri(process.argv.slice(2), {
39+
alias: {
40+
f: 'force',
41+
o: 'output'
42+
},
43+
boolean: ['force']
44+
})
45+
```

docs/modules/portfinder.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
description: Modern alternatives to the portfinder package for finding an available port
3+
---
4+
5+
# Replacements for `portfinder`
6+
7+
## `get-port`
8+
9+
[`get-port`](https://github.com/sindresorhus/get-port) is a lighter and more modern package for finding an available port.
10+
11+
Example:
12+
13+
```ts
14+
import portfinder from 'portfinder' // [!code --]
15+
import getPort from 'get-port' // [!code ++]
16+
17+
const port = await portfinder.getPortPromise() // [!code --]
18+
const port = await getPort() // [!code ++]
19+
```

manifest-schema.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@
124124
"required": [
125125
"id",
126126
"replacementModule",
127-
"type",
128-
"url"
127+
"type"
129128
],
130129
"additionalProperties": false
131130
},

manifests/micro-utilities.json

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,24 @@
1212
"description": "You can use a combination of `filter` and `includes` to calculate the difference between two arrays.",
1313
"example": "const difference = (a, b) => a.filter((item) => !b.includes(item))"
1414
},
15+
"snippet::array-flatten": {
16+
"id": "snippet::array-flatten",
17+
"type": "simple",
18+
"description": "You can use `Array.prototype.flat` with `Infinity` as an argument to fully flatten an array.",
19+
"example": "array.flat(Infinity)"
20+
},
1521
"snippet::array-from-count": {
1622
"id": "snippet::array-from-count",
1723
"type": "simple",
1824
"description": "You can use `Array.from` to create an array of sequential integers",
1925
"example": "Array.from({ length: n }, (_, i) => i);"
2026
},
27+
"snippet::array-from-count-with-start": {
28+
"id": "snippet::array-from-count-with-start",
29+
"type": "simple",
30+
"description": "You can use `Array.from` to create an array of sequential integers starting from a specific integer",
31+
"example": "Array.from({ length: end - start }, (_, i) => i + start);"
32+
},
2133
"snippet::array-last": {
2234
"id": "snippet::array-last",
2335
"type": "simple",
@@ -162,6 +174,12 @@
162174
"description": "If the current environment is npm the `npm_config_user_agent` environment variable will be set and start with `\"npm\"`.",
163175
"example": "const isNpm = process.env.npm_config_user_agent?.startsWith(\"npm\")"
164176
},
177+
"snippet::is-number": {
178+
"id": "snippet::is-number",
179+
"type": "simple",
180+
"description": "You can check if a value is a number by using `typeof` or coercing it to a number and using `Number.isFinite`.",
181+
"example": "const isNumber = (v) => typeof v === \"number\" || (typeof v === \"string\" && Number.isFinite(+v));"
182+
},
165183
"snippet::is-object": {
166184
"id": "snippet::is-object",
167185
"type": "simple",
@@ -306,11 +324,11 @@
306324
"description": "You can check the start of a path for the Windows extended-length path prefix and if it's not present, replace backslashes with forward slashes.",
307325
"example": "path.startsWith('\\\\\\\\?\\\\') ? path : path.replace(/\\\\/g, '/')"
308326
},
309-
"snippet:is-number": {
310-
"id": "snippet:is-number",
327+
"snippet::year": {
328+
"id": "snippet::year",
311329
"type": "simple",
312-
"description": "You can check if a value is a number by using `typeof` or coercing it to a number and using `Number.isFinite`.",
313-
"example": "const isNumber = (v) => typeof v === \"number\" || (typeof v === \"string\" && Number.isFinite(+v));"
330+
"description": "You can use `new Date().getUTCFullYear()` to get the current year.",
331+
"example": "new Date().getUTCFullYear()"
314332
}
315333
},
316334
"mappings": {
@@ -319,6 +337,11 @@
319337
"moduleName": "arr-diff",
320338
"replacements": ["snippet::array-difference"]
321339
},
340+
"arr-flatten": {
341+
"type": "module",
342+
"moduleName": "arr-flatten",
343+
"replacements": ["snippet::array-flatten"]
344+
},
322345
"array-back": {
323346
"type": "module",
324347
"moduleName": "array-back",
@@ -339,6 +362,11 @@
339362
"moduleName": "array-last",
340363
"replacements": ["snippet::array-last"]
341364
},
365+
"array-range": {
366+
"type": "module",
367+
"moduleName": "array-range",
368+
"replacements": ["snippet::array-from-count-with-start"]
369+
},
342370
"array-union": {
343371
"type": "module",
344372
"moduleName": "array-union",
@@ -482,12 +510,12 @@
482510
"is-number": {
483511
"type": "module",
484512
"moduleName": "is-number",
485-
"replacements": ["snippet:is-number"]
513+
"replacements": ["snippet::is-number"]
486514
},
487515
"is-number-object": {
488516
"type": "module",
489517
"moduleName": "is-number-object",
490-
"replacements": ["snippet:is-number"]
518+
"replacements": ["snippet::is-number"]
491519
},
492520
"is-obj": {
493521
"type": "module",
@@ -643,6 +671,11 @@
643671
"type": "module",
644672
"moduleName": "upper-case",
645673
"replacements": ["snippet::to-uppercase"]
674+
},
675+
"year": {
676+
"type": "module",
677+
"moduleName": "year",
678+
"replacements": ["snippet::year"]
646679
}
647680
}
648681
}

0 commit comments

Comments
 (0)