UNPKG

@maximai/maxim-js

Version:

Maxim AI JS SDK. Visit https://getmaxim.ai for more info.

69 lines 2.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.utcNow = utcNow; exports.uniqueId = uniqueId; exports.makeObjectSerializable = makeObjectSerializable; function utcNow() { return new Date(new Date().toUTCString()); } function uniqueId() { return crypto.randomUUID(); } function makeObjectSerializable(obj) { if (obj === null || obj === undefined) { return null; } if (typeof obj !== "object") { if (typeof obj === "bigint") { return obj.toString(); } if (typeof obj === "symbol") { return { type: "symbol", symbolDescription: obj.description, symbolString: obj.toString(), }; } if (typeof obj === "function") { if ("name" in obj || "toString" in obj) { return { type: "function", functionName: "name" in obj ? obj.name : undefined, functionString: "toString" in obj ? obj.toString() : undefined, }; } return undefined; } return obj; } if (obj instanceof Date) { return obj.toISOString(); } if (Array.isArray(obj)) { return obj.map((item) => makeObjectSerializable(item)); } if (obj instanceof RegExp) { return obj.toString(); } if (obj instanceof Map) { return Object.fromEntries(Array.from(obj.entries()).map(([key, value]) => [key, makeObjectSerializable(value)])); } if (obj instanceof Set) { return Array.from(obj).map((item) => makeObjectSerializable(item)); } if (obj instanceof Error) { return { type: "error", errorName: obj.name, errorMessage: obj.message, errorStack: obj.stack, errorCause: obj.cause ? makeObjectSerializable(obj.cause) : undefined, }; } const result = {}; for (const [key, value] of Object.entries(obj)) { result[key] = makeObjectSerializable(value); } return result; } //# sourceMappingURL=utils.js.map