You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
822 B
JavaScript

"use strict";
const combinator = require("@validatem/combinator");
const validationResult = require("@validatem/validation-result");
const withContext = require("@validatem/with-context");
// TODO: Document that this passes on context
module.exports = function ignoreResult(rules) {
// TODO: Document the convention of `parseIntoResult`, and that parsing validators can take this from the context to determine whether the result is going to be ignored (which means it may not have to parse in the first place)
let rulesWithParsingDisabled = withContext(rules, { parseIntoResult: false });
return combinator((value, applyValidators, context) => {
let result = applyValidators(value, rulesWithParsingDisabled, context);
return validationResult({
errors: result.errors,
newValue: undefined
});
});
};