Skip to content

Require Node.js 18+ #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ jobs:
fail-fast: false
matrix:
node-version:
- 16
- 14
- 18
- 20
- 22
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Expand Down
6 changes: 3 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Primitive, JsonObject} from 'type-fest';
import {type Primitive, type JsonObject} from 'type-fest';

export {default as errorConstructors} from './error-constructors.js';

Expand All @@ -19,7 +19,7 @@ export type ErrorLike = {
code?: string;
};

export interface Options {
export type Options = {
/**
The maximum depth of properties to preserve when serializing/deserializing.

Expand Down Expand Up @@ -47,7 +47,7 @@ export interface Options {
@default true
*/
readonly useToJSON?: boolean;
}
};

/**
Serialize an `Error` object into a plain object.
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const destroyCircular = ({
}

for (const {property, enumerable} of commonProperties) {
if (typeof from[property] !== 'undefined' && from[property] !== null) {
if (from[property] !== undefined && from[property] !== null) {
Object.defineProperty(to, property, {
value: isErrorLike(from[property]) ? continueDestroyCircular(from[property]) : from[property],
enumerable: forceEnumerable ? true : enumerable,
Expand Down
4 changes: 3 additions & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {expectType, expectAssignable} from 'tsd';
import {serializeError, deserializeError, ErrorObject, Options} from './index.js';
import {
serializeError, deserializeError, type ErrorObject, type Options,
} from './index.js';

const error = new Error('unicorn');

Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"exports": "./index.js",
"sideEffects": false,
"engines": {
"node": ">=14.16"
"node": ">=18"
},
"scripts": {
"//test": "xo && ava && tsd",
Expand All @@ -38,11 +38,11 @@
"deserialize"
],
"dependencies": {
"type-fest": "^2.12.2"
"type-fest": "^4.31.0"
},
"devDependencies": {
"ava": "^4.2.0",
"tsd": "^0.20.0",
"xo": "^0.48.0"
"ava": "^6.2.0",
"tsd": "^0.31.2",
"xo": "^0.60.0"
}
}
14 changes: 10 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ test('should drop functions', t => {

const serialized = serializeError(object);
t.deepEqual(serialized, {});
t.false(Object.prototype.hasOwnProperty.call(serialized, 'a'));
t.false(Object.hasOwn(serialized, 'a'));
});

test('should not access deep non-enumerable properties', t => {
Expand Down Expand Up @@ -467,13 +467,19 @@ test('should serialize properties up to `Options.maxDepth` levels deep', t => {
t.deepEqual(levelZero, {});

const levelOne = serializeError(error, {maxDepth: 1});
t.deepEqual(levelOne, {message, name, stack, one: {}});
t.deepEqual(levelOne, {
message, name, stack, one: {},
});

const levelTwo = serializeError(error, {maxDepth: 2});
t.deepEqual(levelTwo, {message, name, stack, one: {two: {}}});
t.deepEqual(levelTwo, {
message, name, stack, one: {two: {}},
});

const levelThree = serializeError(error, {maxDepth: 3});
t.deepEqual(levelThree, {message, name, stack, one: {two: {three: {}}}});
t.deepEqual(levelThree, {
message, name, stack, one: {two: {three: {}}},
});
});

test('should identify serialized errors', t => {
Expand Down
Loading