typescript-domain
Version:
Decorator-based transformation of JSON or plain Javascript objects to classes
19 lines (18 loc) • 654 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.object = exports.array = void 0;
function array(Type, debugFunction, debugSkipUndef) {
return (data) => Array.isArray(data)
? data
.map((element) => new Type(element, debugFunction, debugSkipUndef))
.filter((element) => element.isValid())
: [];
}
exports.array = array;
function object(Type, debugFunction, debugSkipUndef) {
return (data) => {
const parsedResponse = new Type(data, debugFunction, debugSkipUndef);
return parsedResponse.isValid() ? parsedResponse : null;
};
}
exports.object = object;