@decaf-ts/decorator-validation
Version:
simple decorator based validation engine
31 lines • 1.12 kB
JavaScript
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