UNPKG

@decaf-ts/decorator-validation

Version:
31 lines 1.12 kB
import { DefaultSerializationMethod } from "./constants.js"; export class Serialization { static { this.current = DefaultSerializationMethod; } constructor() { } static get(key) { if (key in this.cache) return this.cache[key]; throw new Error(`No serialization method registered under ${key}`); } static register(key, func, setDefault = false) { if (key in this.cache) throw new Error(`Serialization method ${key} already registered`); this.cache[key] = new func(); if (setDefault) this.current = key; } static serialize(obj, method, ...args) { if (!method) return this.get(this.current).serialize(obj, ...args); return this.get(method).serialize(obj, ...args); } static deserialize(obj, method, ...args) { if (!method) return this.get(this.current).deserialize(obj, ...args); return this.get(method).deserialize(obj, ...args); } static setDefault(method) { this.current = this.get(method); } } //# sourceMappingURL=serialization.js.map