UNPKG

easy-constructor

Version:

JavaScript class constructors without the boilerplate

19 lines 521 B
function easyConstructor(classType, options) { return function(input, ...constructorArguments) { const newInstance = new classType(...constructorArguments); for (const [key, value] of Object.entries(input)) { if (options?.omit?.includes(key)) { continue; } if (value === void 0 && options?.optional?.includes(key)) { continue; } newInstance[key] = value; } return newInstance; }; } export { easyConstructor }; //# sourceMappingURL=easyConstructor.js.map