bun add @aklinker1/zero-serialize-error
Features
- 🔄 Convert errors to and from JS objects
- 🌳 Serializes entire
causetree - ✨ Supports custom properties added to errors
- 🔧 Accepts custom serialization functions for converting other data types to and from objects
- 📦 Tiny package with zero dependencies
Usage
const error = Error("🐛");
const serialized = serializeError(error);
console.log(serialized); // { name: "Error", message: "🐛", stack: "..." }
const deserialized = deserializeError(serialized);
console.log(deserialized); // Error: 🐛
Other Data Types
No other classes other than Errors are supported by default when serializing/deserializing:
const error = new Error("With a date");
error.time = new Date();
const serialized = serializeError(error);
console.log(serialized); // { ..., time: "[object Date]" }
const deserialized = deserializeError(serialized);
console.log(deserialized.time); // "[object Date]"
Inspired by serialize-error. Goal was to trim it down, drop any dependencies, and make it as small as possible.
| Package | Size | node_modules Size |
|---|---|---|
serialize-error | 20 kB | 586.8 kB |
@aklinker1/zero-serialize-error | 6.1 kB | 6.1 kB |