UNPKG

@arifwidianto/rpc-agent

Version:

RPC Agent for both client and server, extends more methods easily

51 lines 1.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class DateExtension { name = "date"; status = "active"; config = { enabled: true }; metadata = { name: this.name, version: "1.0.0", description: "Date and time utilities", }; now = async () => { if (!this.config.enabled) { throw new Error("Extension is disabled"); } const now = new Date(); return { timestamp: now.toISOString(), unix: now.getTime(), utc: now.toUTCString(), local: now.toLocaleString(), timezone: Intl.DateTimeFormat().resolvedOptions().timeZone, }; }; parse = async (params) => { if (!this.config.enabled) { throw new Error("Extension is disabled"); } const reqDate = params?.date instanceof Date ? params.date : typeof params?.date === "string" || typeof params?.date === "number" ? new Date(params.date) : undefined; if (!reqDate || isNaN(reqDate.getTime())) { throw new Error(`Invalid date format: ${typeof params?.date}`); } return { timestamp: reqDate.toISOString(), unix: reqDate.getTime(), utc: reqDate.toUTCString(), local: reqDate.toLocaleString(), timezone: Intl.DateTimeFormat().resolvedOptions().timeZone, }; }; methods = { now: this.now, parse: this.parse, }; } exports.default = DateExtension; //# sourceMappingURL=index.js.map