dynamodb-toolbox
Version:
Lightweight and type-safe query builder for DynamoDB and TypeScript.
34 lines (33 loc) • 1.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.jsonStringify = exports.JSONStringifier = void 0;
const pipe_js_1 = require("./pipe.js");
class JSONStringifier {
constructor({ space, replacer, reviver } = {}) {
this.transformerId = 'jsonStringify';
this.space = space;
this.replacer = replacer;
this.reviver = reviver;
}
encode(formatted) {
return JSON.stringify(formatted, this.replacer, this.space);
}
decode(transformed) {
return JSON.parse(transformed, this.reviver);
}
toJSON() {
if (this.replacer !== undefined || this.reviver !== undefined) {
console.warn('Schema DTO is probably incomplete when using `replacer` or `reviver` options in JSON Stringifier.');
}
return {
transformerId: this.transformerId,
...(this.space !== undefined ? { space: this.space } : {})
};
}
pipe(transformer) {
return (0, pipe_js_1.pipe)(this, transformer);
}
}
exports.JSONStringifier = JSONStringifier;
const jsonStringify = (options = {}) => new JSONStringifier(options);
exports.jsonStringify = jsonStringify;