Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/ayonli_jsext/error/index.ts>toObject

A JavaScript extension package for building strong and modern applications.
Latest
function toObject
import { toObject } from "https://deno.land/x/ayonli_jsext@v0.9.72/error/index.ts";

Transforms the error to a plain object.

Examples

Example 1

import { toObject } from "@ayonli/jsext/error";

const err = new Error("Something went wrong.");

const obj = toObject(err);
console.log(obj);
// {
//     "@@type": "Error",
//     name: "Error",
//     message: "Something went wrong.",
//     stack: "Error: Something went wrong.\n    at <anonymous>:1:13"
// }

Type Parameters

T extends Error

Returns

{ [x: string | symbol]: any; }