@valuer/main
Version:
Valuer is an advanced declarative value validator
48 lines (47 loc) • 1.86 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var configs_1 = require("./modules/configs");
var descriptors_1 = require("./modules/descriptors");
var hooks_1 = require("./modules/hooks");
var processors_1 = require("./modules/processors");
function core() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var usingDescriptor = descriptors_1.Descriptors.isDescriptorFlow(args);
var config = configs_1.Configs.create(usingDescriptor ? args[1] : {});
var hooks = hooks_1.Hooks.create(config);
var processors = processors_1.Processors.create(args, usingDescriptor, config);
return function (value, role) {
if (role === void 0) { role = "value"; }
configs_1.Configs.setupCurrent(config);
for (var _i = 0, processors_2 = processors; _i < processors_2.length; _i++) {
var processor = processors_2[_i];
var processing = processors_1.Processors.apply(processor, value);
if (processing.result)
hooks["validation.success"](processing);
else
hooks["validation.failure"](processing, role);
if (hooks["validation.break"]())
break;
}
configs_1.Configs.clearCurrent();
return hooks["validation.return"](value);
};
}
/** @private */
var delegator = function (value, role) { return ({
as: function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return core.apply(void 0, args)(value, role);
},
}); };
exports.valuer = Object.assign(delegator, {
as: core,
config: configs_1.Configs.changeDefault,
define: descriptors_1.Descriptors.define,
});