Skip to content

Commit

Permalink
Require Node.js 14
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 18, 2022
1 parent 49db63a commit 22b9bd4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/main.yml
Expand Up @@ -12,10 +12,9 @@ jobs:
node-version:
- 16
- 14
- 12
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
8 changes: 4 additions & 4 deletions index.js
Expand Up @@ -48,7 +48,7 @@ const toJSON = from => {
return json;
};

const getErrorConstructor = name => errorConstructors.get(name) || Error;
const getErrorConstructor = name => errorConstructors.get(name) ?? Error;

// eslint-disable-next-line complexity
const destroyCircular = ({
Expand All @@ -60,7 +60,7 @@ const destroyCircular = ({
depth,
useToJSON,
}) => {
const to = to_ || (Array.isArray(from) ? [] : {});
const to = to_ ?? (Array.isArray(from) ? [] : {});

seen.push(from);

Expand Down Expand Up @@ -152,7 +152,7 @@ export function serializeError(value, options = {}) {
// People sometimes throw things besides Error objects…
if (typeof value === 'function') {
// `JSON.stringify()` discards functions. We do too, unless a function is thrown directly.
return `[Function: ${value.name || 'anonymous'}]`;
return `[Function: ${value.name ?? 'anonymous'}]`;
}

return value;
Expand Down Expand Up @@ -187,4 +187,4 @@ export function isErrorLike(value) {
&& 'stack' in value;
}

export {errorConstructors};
export {default as errorConstructors} from './error-constructors.js';
10 changes: 5 additions & 5 deletions package.json
Expand Up @@ -13,7 +13,7 @@
"type": "module",
"exports": "./index.js",
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
"node": ">=14.16"
},
"scripts": {
"test": "xo && ava && tsd"
Expand All @@ -36,11 +36,11 @@
"deserialize"
],
"dependencies": {
"type-fest": "^2.5.3"
"type-fest": "^2.12.2"
},
"devDependencies": {
"ava": "^3.15.0",
"tsd": "^0.18.0",
"xo": "^0.46.4"
"ava": "^4.2.0",
"tsd": "^0.20.0",
"xo": "^0.48.0"
}
}
6 changes: 3 additions & 3 deletions readme.md
Expand Up @@ -33,7 +33,7 @@ console.log(deserialized);

### Error constructors

When a serialized error with a known `name` is encountered, it will be deserialized using the corresponding error constructor, while enknown error names will be deserialized as regular errors:
When a serialized error with a known `name` is encountered, it will be deserialized using the corresponding error constructor, while unknown error names will be deserialized as regular errors:

```js
import {deserializeError} from 'serialize-error';
Expand All @@ -44,15 +44,15 @@ const known = deserializeError({
});

console.log(known);
//=> [TypeError: 🦄] <-- still a TypeError
//=> [TypeError: 🦄] <-- Still a TypeError

const unknown = deserializeError({
name: 'TooManyCooksError',
message: '🦄'
});

console.log(unknown);
//=> [Error: 🦄] <-- just a regular Error
//=> [Error: 🦄] <-- Just a regular Error
```

The [list of known errors](./error-constructors.js) can be extended globally. This also works if `serialize-error` is a sub-dependency that's not used directly.
Expand Down

0 comments on commit 22b9bd4

Please sign in to comment.