@carlosv2/glue
Version:
Dependency injection library that stays out of the way
21 lines (20 loc) • 528 B
JavaScript
import { DeserialiseError, SerialiseError } from '../../error/format.js';
import { Compiler } from '../compiler.js';
export class JsonCompiler extends Compiler {
serialise(path, data) {
try {
return JSON.stringify(data);
}
catch (_a) {
throw new SerialiseError('JSON', path);
}
}
deserialise(path, data) {
try {
return JSON.parse(data);
}
catch (_a) {
throw new DeserialiseError('JSON', path);
}
}
}