UNPKG

@fewer/validations

Version:

A collection of pipes that handle common model validation use-cases for Fewer

28 lines 999 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function withConfirmation(fieldName, confirmationFieldName, config = {}) { return { validate(obj) { if (obj[confirmationFieldName]) { const { caseSensitive = true } = config; let matches = false; if (caseSensitive) { matches = obj[fieldName] === obj[confirmationFieldName]; } else { matches = String(obj[fieldName]).toLowerCase() === String(obj[confirmationFieldName]).toLowerCase(); } if (!matches) { return { on: fieldName, message: 'does not match confirmation', }; } } }, }; } exports.withConfirmation = withConfirmation; //# sourceMappingURL=confirmation.js.map