miter
Version:
A typescript web framework based on ExpressJs based loosely on SailsJs
21 lines • 716 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
require("reflect-metadata");
const _ = require("lodash");
function Sanitize(fn) {
return function (model) {
let proto = model.prototype;
if (proto.hasOwnProperty('toJSON')) {
console.warn(`Failed to apply Sanitize directive to ${model.name || model}. This class already has a toJSON property.`);
return;
}
proto.toJSON = function () {
let clone = _.cloneDeep(this);
clone = Object.assign({}, clone);
fn.call(this, clone);
return clone;
};
};
}
exports.Sanitize = Sanitize;
//# sourceMappingURL=sanitize.decorator.js.map