UNPKG

@belvo-finance/belvo-vue-components

Version:

## Project setup ``` npm install ```

1,478 lines (1,425 loc) 96.7 kB
/** * vee-validate v3.3.0 * (c) 2020 Abdelrahman Awad * @license MIT */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue')) : typeof define === 'function' && define.amd ? define(['exports', 'vue'], factory) : (global = global || self, factory(global.VeeValidate = {}, global.Vue)); }(this, (function (exports, Vue) { 'use strict'; Vue = Vue && Vue.hasOwnProperty('default') ? Vue['default'] : Vue; var code = "en"; var messages = { alpha: "The {_field_} field may only contain alphabetic characters", alpha_num: "The {_field_} field may only contain alpha-numeric characters", alpha_dash: "The {_field_} field may contain alpha-numeric characters as well as dashes and underscores", alpha_spaces: "The {_field_} field may only contain alphabetic characters as well as spaces", between: "The {_field_} field must be between {min} and {max}", confirmed: "The {_field_} field confirmation does not match", digits: "The {_field_} field must be numeric and exactly contain {length} digits", dimensions: "The {_field_} field must be {width} pixels by {height} pixels", email: "The {_field_} field must be a valid email", excluded: "The {_field_} field is not a valid value", ext: "The {_field_} field is not a valid file", image: "The {_field_} field must be an image", integer: "The {_field_} field must be an integer", length: "The {_field_} field must be {length} long", max_value: "The {_field_} field must be {max} or less", max: "The {_field_} field may not be greater than {length} characters", mimes: "The {_field_} field must have a valid file type", min_value: "The {_field_} field must be {min} or more", min: "The {_field_} field must be at least {length} characters", numeric: "The {_field_} field may only contain numeric characters", oneOf: "The {_field_} field is not a valid value", regex: "The {_field_} field format is invalid", required_if: "The {_field_} field is required", required: "The {_field_} field is required", size: "The {_field_} field size must be less than {size}KB" }; var en = { code: code, messages: messages }; /** * Some Alpha Regex helpers. * https://github.com/chriso/validator.js/blob/master/src/lib/alpha.js */ /* eslint-disable no-misleading-character-class */ var alpha = { en: /^[A-Z]*$/i, cs: /^[A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]*$/i, da: /^[A-ZÆØÅ]*$/i, de: /^[A-ZÄÖÜß]*$/i, es: /^[A-ZÁÉÍÑÓÚÜ]*$/i, fa: /^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰپژگچکی]*$/, fr: /^[A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]*$/i, it: /^[A-Z\xC0-\xFF]*$/i, lt: /^[A-ZĄČĘĖĮŠŲŪŽ]*$/i, nl: /^[A-ZÉËÏÓÖÜ]*$/i, hu: /^[A-ZÁÉÍÓÖŐÚÜŰ]*$/i, pl: /^[A-ZĄĆĘŚŁŃÓŻŹ]*$/i, pt: /^[A-ZÃÁÀÂÇÉÊÍÕÓÔÚÜ]*$/i, ru: /^[А-ЯЁ]*$/i, sk: /^[A-ZÁÄČĎÉÍĹĽŇÓŔŠŤÚÝŽ]*$/i, sr: /^[A-ZČĆŽŠĐ]*$/i, sv: /^[A-ZÅÄÖ]*$/i, tr: /^[A-ZÇĞİıÖŞÜ]*$/i, uk: /^[А-ЩЬЮЯЄІЇҐ]*$/i, ar: /^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]*$/, az: /^[A-ZÇƏĞİıÖŞÜ]*$/i }; var alphaSpaces = { en: /^[A-Z\s]*$/i, cs: /^[A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ\s]*$/i, da: /^[A-ZÆØÅ\s]*$/i, de: /^[A-ZÄÖÜß\s]*$/i, es: /^[A-ZÁÉÍÑÓÚÜ\s]*$/i, fa: /^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰپژگچکی]*$/, fr: /^[A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ\s]*$/i, it: /^[A-Z\xC0-\xFF\s]*$/i, lt: /^[A-ZĄČĘĖĮŠŲŪŽ\s]*$/i, nl: /^[A-ZÉËÏÓÖÜ\s]*$/i, hu: /^[A-ZÁÉÍÓÖŐÚÜŰ\s]*$/i, pl: /^[A-ZĄĆĘŚŁŃÓŻŹ\s]*$/i, pt: /^[A-ZÃÁÀÂÇÉÊÍÕÓÔÚÜ\s]*$/i, ru: /^[А-ЯЁ\s]*$/i, sk: /^[A-ZÁÄČĎÉÍĹĽŇÓŔŠŤÚÝŽ\s]*$/i, sr: /^[A-ZČĆŽŠĐ\s]*$/i, sv: /^[A-ZÅÄÖ\s]*$/i, tr: /^[A-ZÇĞİıÖŞÜ\s]*$/i, uk: /^[А-ЩЬЮЯЄІЇҐ\s]*$/i, ar: /^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ\s]*$/, az: /^[A-ZÇƏĞİıÖŞÜ\s]*$/i }; var alphanumeric = { en: /^[0-9A-Z]*$/i, cs: /^[0-9A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]*$/i, da: /^[0-9A-ZÆØÅ]$/i, de: /^[0-9A-ZÄÖÜß]*$/i, es: /^[0-9A-ZÁÉÍÑÓÚÜ]*$/i, fa: /^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰپژگچکی]*$/, fr: /^[0-9A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]*$/i, it: /^[0-9A-Z\xC0-\xFF]*$/i, lt: /^[0-9A-ZĄČĘĖĮŠŲŪŽ]*$/i, hu: /^[0-9A-ZÁÉÍÓÖŐÚÜŰ]*$/i, nl: /^[0-9A-ZÉËÏÓÖÜ]*$/i, pl: /^[0-9A-ZĄĆĘŚŁŃÓŻŹ]*$/i, pt: /^[0-9A-ZÃÁÀÂÇÉÊÍÕÓÔÚÜ]*$/i, ru: /^[0-9А-ЯЁ]*$/i, sk: /^[0-9A-ZÁÄČĎÉÍĹĽŇÓŔŠŤÚÝŽ]*$/i, sr: /^[0-9A-ZČĆŽŠĐ]*$/i, sv: /^[0-9A-ZÅÄÖ]*$/i, tr: /^[0-9A-ZÇĞİıÖŞÜ]*$/i, uk: /^[0-9А-ЩЬЮЯЄІЇҐ]*$/i, ar: /^[٠١٢٣٤٥٦٧٨٩0-9ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]*$/, az: /^[0-9A-ZÇƏĞİıÖŞÜ]*$/i }; var alphaDash = { en: /^[0-9A-Z_-]*$/i, cs: /^[0-9A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ_-]*$/i, da: /^[0-9A-ZÆØÅ_-]*$/i, de: /^[0-9A-ZÄÖÜß_-]*$/i, es: /^[0-9A-ZÁÉÍÑÓÚÜ_-]*$/i, fa: /^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰپژگچکی]*$/, fr: /^[0-9A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ_-]*$/i, it: /^[0-9A-Z\xC0-\xFF_-]*$/i, lt: /^[0-9A-ZĄČĘĖĮŠŲŪŽ_-]*$/i, nl: /^[0-9A-ZÉËÏÓÖÜ_-]*$/i, hu: /^[0-9A-ZÁÉÍÓÖŐÚÜŰ_-]*$/i, pl: /^[0-9A-ZĄĆĘŚŁŃÓŻŹ_-]*$/i, pt: /^[0-9A-ZÃÁÀÂÇÉÊÍÕÓÔÚÜ_-]*$/i, ru: /^[0-9А-ЯЁ_-]*$/i, sk: /^[0-9A-ZÁÄČĎÉÍĹĽŇÓŔŠŤÚÝŽ_-]*$/i, sr: /^[0-9A-ZČĆŽŠĐ_-]*$/i, sv: /^[0-9A-ZÅÄÖ_-]*$/i, tr: /^[0-9A-ZÇĞİıÖŞÜ_-]*$/i, uk: /^[0-9А-ЩЬЮЯЄІЇҐ_-]*$/i, ar: /^[٠١٢٣٤٥٦٧٨٩0-9ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ_-]*$/, az: /^[0-9A-ZÇƏĞİıÖŞÜ_-]*$/i }; var validate = function (value, _a) { var _b = (_a === void 0 ? {} : _a).locale, locale = _b === void 0 ? '' : _b; if (Array.isArray(value)) { return value.every(function (val) { return validate(val, { locale: locale }); }); } // Match at least one locale. if (!locale) { return Object.keys(alpha).some(function (loc) { return alpha[loc].test(value); }); } return (alpha[locale] || alpha.en).test(value); }; var params = [ { name: 'locale' } ]; var alpha$1 = { validate: validate, params: params }; var validate$1 = function (value, _a) { var _b = (_a === void 0 ? {} : _a).locale, locale = _b === void 0 ? '' : _b; if (Array.isArray(value)) { return value.every(function (val) { return validate$1(val, { locale: locale }); }); } // Match at least one locale. if (!locale) { return Object.keys(alphaDash).some(function (loc) { return alphaDash[loc].test(value); }); } return (alphaDash[locale] || alphaDash.en).test(value); }; var params$1 = [ { name: 'locale' } ]; var alpha_dash = { validate: validate$1, params: params$1 }; var validate$2 = function (value, _a) { var _b = (_a === void 0 ? {} : _a).locale, locale = _b === void 0 ? '' : _b; if (Array.isArray(value)) { return value.every(function (val) { return validate$2(val, { locale: locale }); }); } // Match at least one locale. if (!locale) { return Object.keys(alphanumeric).some(function (loc) { return alphanumeric[loc].test(value); }); } return (alphanumeric[locale] || alphanumeric.en).test(value); }; var params$2 = [ { name: 'locale' } ]; var alpha_num = { validate: validate$2, params: params$2 }; var validate$3 = function (value, _a) { var _b = (_a === void 0 ? {} : _a).locale, locale = _b === void 0 ? '' : _b; if (Array.isArray(value)) { return value.every(function (val) { return validate$3(val, { locale: locale }); }); } // Match at least one locale. if (!locale) { return Object.keys(alphaSpaces).some(function (loc) { return alphaSpaces[loc].test(value); }); } return (alphaSpaces[locale] || alphaSpaces.en).test(value); }; var params$3 = [ { name: 'locale' } ]; var alpha_spaces = { validate: validate$3, params: params$3 }; var validate$4 = function (value, _a) { var _b = _a === void 0 ? {} : _a, min = _b.min, max = _b.max; if (Array.isArray(value)) { return value.every(function (val) { return !!validate$4(val, { min: min, max: max }); }); } return Number(min) <= value && Number(max) >= value; }; var params$4 = [ { name: 'min' }, { name: 'max' } ]; var between = { validate: validate$4, params: params$4 }; var validate$5 = function (value, _a) { var target = _a.target; return String(value) === String(target); }; var params$5 = [ { name: 'target', isTarget: true } ]; var confirmed = { validate: validate$5, params: params$5 }; var validate$6 = function (value, _a) { var length = _a.length; if (Array.isArray(value)) { return value.every(function (val) { return validate$6(val, { length: length }); }); } var strVal = String(value); return /^[0-9]*$/.test(strVal) && strVal.length === length; }; var params$6 = [ { name: 'length', cast: function (value) { return Number(value); } } ]; var digits = { validate: validate$6, params: params$6 }; var validateImage = function (file, width, height) { var URL = window.URL || window.webkitURL; return new Promise(function (resolve) { var image = new Image(); image.onerror = function () { return resolve(false); }; image.onload = function () { return resolve(image.width === width && image.height === height); }; image.src = URL.createObjectURL(file); }); }; var validate$7 = function (files, _a) { var width = _a.width, height = _a.height; var list = []; files = Array.isArray(files) ? files : [files]; for (var i = 0; i < files.length; i++) { // if file is not an image, reject. if (!/\.(jpg|svg|jpeg|png|bmp|gif)$/i.test(files[i].name)) { return Promise.resolve(false); } list.push(files[i]); } return Promise.all(list.map(function (file) { return validateImage(file, width, height); })).then(function (values) { return values.every(function (v) { return v; }); }); }; var params$7 = [ { name: 'width', cast: function (value) { return Number(value); } }, { name: 'height', cast: function (value) { return Number(value); } } ]; var dimensions = { validate: validate$7, params: params$7 }; var validate$8 = function (value, _a) { var multiple = (_a === void 0 ? {} : _a).multiple; // eslint-disable-next-line var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; if (multiple && !Array.isArray(value)) { value = String(value) .split(',') .map(function (emailStr) { return emailStr.trim(); }); } if (Array.isArray(value)) { return value.every(function (val) { return re.test(String(val)); }); } return re.test(String(value)); }; var params$8 = [ { name: 'multiple', default: false } ]; var email = { validate: validate$8, params: params$8 }; function isNaN$1(value) { // NaN is the one value that does not equal itself. // eslint-disable-next-line return value !== value; } function isNullOrUndefined(value) { return value === null || value === undefined; } function isEmptyArray(arr) { return Array.isArray(arr) && arr.length === 0; } var isObject = function (obj) { return obj !== null && obj && typeof obj === 'object' && !Array.isArray(obj); }; /** * Shallow object comparison. */ function isEqual(lhs, rhs) { if (lhs instanceof RegExp && rhs instanceof RegExp) { return isEqual(lhs.source, rhs.source) && isEqual(lhs.flags, rhs.flags); } if (Array.isArray(lhs) && Array.isArray(rhs)) { if (lhs.length !== rhs.length) return false; for (var i = 0; i < lhs.length; i++) { if (!isEqual(lhs[i], rhs[i])) { return false; } } return true; } // if both are objects, compare each key recursively. if (isObject(lhs) && isObject(rhs)) { return (Object.keys(lhs).every(function (key) { return isEqual(lhs[key], rhs[key]); }) && Object.keys(rhs).every(function (key) { return isEqual(lhs[key], rhs[key]); })); } if (isNaN$1(lhs) && isNaN$1(rhs)) { return true; } return lhs === rhs; } // Checks if a given value is not an empty string or null or undefined. function isSpecified(val) { if (val === '') { return false; } return !isNullOrUndefined(val); } function isCallable(fn) { return typeof fn === 'function'; } function isLocator(value) { return isCallable(value) && !!value.__locatorRef; } function findIndex(arrayLike, predicate) { var array = Array.isArray(arrayLike) ? arrayLike : toArray(arrayLike); if (isCallable(array.findIndex)) { return array.findIndex(predicate); } /* istanbul ignore next */ for (var i = 0; i < array.length; i++) { if (predicate(array[i], i)) { return i; } } /* istanbul ignore next */ return -1; } /** * finds the first element that satisfies the predicate callback, polyfills array.find */ function find(arrayLike, predicate) { var array = Array.isArray(arrayLike) ? arrayLike : toArray(arrayLike); var idx = findIndex(array, predicate); return idx === -1 ? undefined : array[idx]; } function includes(collection, item) { return collection.indexOf(item) !== -1; } /** * Converts an array-like object to array, provides a simple polyfill for Array.from */ function toArray(arrayLike) { if (isCallable(Array.from)) { return Array.from(arrayLike); } /* istanbul ignore next */ return _copyArray(arrayLike); } /* istanbul ignore next */ function _copyArray(arrayLike) { var array = []; var length = arrayLike.length; for (var i = 0; i < length; i++) { array.push(arrayLike[i]); } return array; } function values(obj) { if (isCallable(Object.values)) { return Object.values(obj); } // fallback to keys() /* istanbul ignore next */ return Object.keys(obj).map(function (k) { return obj[k]; }); } function merge(target, source) { Object.keys(source).forEach(function (key) { if (isObject(source[key])) { if (!target[key]) { target[key] = {}; } merge(target[key], source[key]); return; } target[key] = source[key]; }); return target; } function createFlags() { return { untouched: true, touched: false, dirty: false, pristine: true, valid: false, invalid: false, validated: false, pending: false, required: false, changed: false, passed: false, failed: false }; } function identity(x) { return x; } function debounce(fn, wait, token) { if (wait === void 0) { wait = 0; } if (token === void 0) { token = { cancelled: false }; } if (wait === 0) { return fn; } var timeout; return function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var later = function () { timeout = undefined; // check if the fn call was cancelled. if (!token.cancelled) fn.apply(void 0, args); }; // because we might want to use Node.js setTimout for SSR. clearTimeout(timeout); timeout = setTimeout(later, wait); }; } /** * Emits a warning to the console */ function warn(message) { console.warn("[vee-validate] " + message); } /** * Replaces placeholder values in a string with their actual values */ function interpolate(template, values) { return template.replace(/{([^}]+)}/g, function (_, p) { return p in values ? values[p] : "{" + p + "}"; }); } var validate$9 = function (value, options) { if (Array.isArray(value)) { return value.every(function (val) { return validate$9(val, options); }); } return toArray(options).some(function (item) { // eslint-disable-next-line return item == value; }); }; var oneOf = { validate: validate$9 }; var validate$a = function (value, args) { return !validate$9(value, args); }; var excluded = { validate: validate$a }; var validate$b = function (files, extensions) { var regex = new RegExp(".(" + extensions.join('|') + ")$", 'i'); if (Array.isArray(files)) { return files.every(function (file) { return regex.test(file.name); }); } return regex.test(files.name); }; var ext = { validate: validate$b }; var validate$c = function (files) { var regex = /\.(jpg|svg|jpeg|png|bmp|gif)$/i; if (Array.isArray(files)) { return files.every(function (file) { return regex.test(file.name); }); } return regex.test(files.name); }; var image = { validate: validate$c }; var validate$d = function (value) { if (Array.isArray(value)) { return value.every(function (val) { return /^-?[0-9]+$/.test(String(val)); }); } return /^-?[0-9]+$/.test(String(value)); }; var integer = { validate: validate$d }; var validate$e = function (value, _a) { var other = _a.other; return value === other; }; var params$9 = [ { name: 'other' } ]; var is = { validate: validate$e, params: params$9 }; var validate$f = function (value, _a) { var other = _a.other; return value !== other; }; var params$a = [ { name: 'other' } ]; var is_not = { validate: validate$f, params: params$a }; var validate$g = function (value, _a) { var length = _a.length; if (isNullOrUndefined(value)) { return false; } if (typeof value === 'number') { value = String(value); } if (!value.length) { value = toArray(value); } return value.length === length; }; var params$b = [ { name: 'length', cast: function (value) { return Number(value); } } ]; var length = { validate: validate$g, params: params$b }; var validate$h = function (value, _a) { var length = _a.length; if (isNullOrUndefined(value)) { return length >= 0; } if (Array.isArray(value)) { return value.every(function (val) { return validate$h(val, { length: length }); }); } return String(value).length <= length; }; var params$c = [ { name: 'length', cast: function (value) { return Number(value); } } ]; var max = { validate: validate$h, params: params$c }; var validate$i = function (value, _a) { var max = _a.max; if (isNullOrUndefined(value) || value === '') { return false; } if (Array.isArray(value)) { return value.length > 0 && value.every(function (val) { return validate$i(val, { max: max }); }); } return Number(value) <= max; }; var params$d = [ { name: 'max', cast: function (value) { return Number(value); } } ]; var max_value = { validate: validate$i, params: params$d }; var validate$j = function (files, mimes) { var regex = new RegExp(mimes.join('|').replace('*', '.+') + "$", 'i'); if (Array.isArray(files)) { return files.every(function (file) { return regex.test(file.type); }); } return regex.test(files.type); }; var mimes = { validate: validate$j }; var validate$k = function (value, _a) { var length = _a.length; if (isNullOrUndefined(value)) { return false; } if (Array.isArray(value)) { return value.every(function (val) { return validate$k(val, { length: length }); }); } return String(value).length >= length; }; var params$e = [ { name: 'length', cast: function (value) { return Number(value); } } ]; var min = { validate: validate$k, params: params$e }; var validate$l = function (value, _a) { var min = _a.min; if (isNullOrUndefined(value) || value === '') { return false; } if (Array.isArray(value)) { return value.length > 0 && value.every(function (val) { return validate$l(val, { min: min }); }); } return Number(value) >= min; }; var params$f = [ { name: 'min', cast: function (value) { return Number(value); } } ]; var min_value = { validate: validate$l, params: params$f }; var ar = /^[٠١٢٣٤٥٦٧٨٩]+$/; var en$1 = /^[0-9]+$/; var validate$m = function (value) { var testValue = function (val) { var strValue = String(val); return en$1.test(strValue) || ar.test(strValue); }; if (Array.isArray(value)) { return value.every(testValue); } return testValue(value); }; var numeric = { validate: validate$m }; var validate$n = function (value, _a) { var regex = _a.regex; if (Array.isArray(value)) { return value.every(function (val) { return validate$n(val, { regex: regex }); }); } return regex.test(String(value)); }; var params$g = [ { name: 'regex', cast: function (value) { if (typeof value === 'string') { return new RegExp(value); } return value; } } ]; var regex = { validate: validate$n, params: params$g }; var validate$o = function (value, _a) { var allowFalse = (_a === void 0 ? { allowFalse: true } : _a).allowFalse; var result = { valid: false, required: true }; if (isNullOrUndefined(value) || isEmptyArray(value)) { return result; } // incase a field considers `false` as an empty value like checkboxes. if (value === false && !allowFalse) { return result; } result.valid = !!String(value).trim().length; return result; }; var computesRequired = true; var params$h = [ { name: 'allowFalse', default: true } ]; var required = { validate: validate$o, params: params$h, computesRequired: computesRequired }; var testEmpty = function (value) { return isEmptyArray(value) || includes([false, null, undefined], value) || !String(value).trim().length; }; var validate$p = function (value, _a) { var target = _a.target, values = _a.values; var required; if (values && values.length) { if (!Array.isArray(values) && typeof values === 'string') { values = [values]; } // eslint-disable-next-line required = values.some(function (val) { return val == String(target).trim(); }); } else { required = !testEmpty(target); } if (!required) { return { valid: true, required: required }; } return { valid: !testEmpty(value), required: required }; }; var params$i = [ { name: 'target', isTarget: true }, { name: 'values' } ]; var computesRequired$1 = true; var required_if = { validate: validate$p, params: params$i, computesRequired: computesRequired$1 }; var validate$q = function (files, _a) { var size = _a.size; if (isNaN(size)) { return false; } var nSize = size * 1024; if (!Array.isArray(files)) { return files.size <= nSize; } for (var i = 0; i < files.length; i++) { if (files[i].size > nSize) { return false; } } return true; }; var params$j = [ { name: 'size', cast: function (value) { return Number(value); } } ]; var size = { validate: validate$q, params: params$j }; var Rules = /*#__PURE__*/Object.freeze({ __proto__: null, alpha_dash: alpha_dash, alpha_num: alpha_num, alpha_spaces: alpha_spaces, alpha: alpha$1, between: between, confirmed: confirmed, digits: digits, dimensions: dimensions, email: email, ext: ext, image: image, oneOf: oneOf, integer: integer, length: length, is_not: is_not, is: is, max: max, max_value: max_value, mimes: mimes, min: min, min_value: min_value, excluded: excluded, numeric: numeric, regex: regex, required: required, required_if: required_if, size: size }); /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ var __assign = function() { __assign = Object.assign || function __assign(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; function __awaiter(thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); } function __generator(thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } } function __spreadArrays() { for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j]; return r; } var DEFAULT_CONFIG = { defaultMessage: "{_field_} is not valid.", skipOptional: true, classes: { touched: 'touched', untouched: 'untouched', valid: 'valid', invalid: 'invalid', pristine: 'pristine', dirty: 'dirty' // control has been interacted with }, bails: true, mode: 'aggressive', useConstraintAttrs: true }; var currentConfig = __assign({}, DEFAULT_CONFIG); var getConfig = function () { return currentConfig; }; var setConfig = function (newConf) { currentConfig = __assign(__assign({}, currentConfig), newConf); }; var configure = function (cfg) { setConfig(cfg); }; var EVENT_BUS = new Vue(); function localeChanged() { EVENT_BUS.$emit('change:locale'); } var Dictionary = /** @class */ (function () { function Dictionary(locale, dictionary) { this.container = {}; this.locale = locale; this.merge(dictionary); } Dictionary.prototype.resolve = function (field, rule, values) { return this.format(this.locale, field, rule, values); }; Dictionary.prototype.format = function (locale, field, rule, values) { var _a, _b, _c, _d, _e, _f, _g, _h; var message; // find if specific message for that field was specified. message = ((_c = (_b = (_a = this.container[locale]) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b[field]) === null || _c === void 0 ? void 0 : _c[rule]) || ((_e = (_d = this.container[locale]) === null || _d === void 0 ? void 0 : _d.messages) === null || _e === void 0 ? void 0 : _e[rule]); if (!message) { message = '{_field_} is not valid'; } field = (_h = (_g = (_f = this.container[locale]) === null || _f === void 0 ? void 0 : _f.names) === null || _g === void 0 ? void 0 : _g[field]) !== null && _h !== void 0 ? _h : field; return isCallable(message) ? message(field, values) : interpolate(message, __assign(__assign({}, values), { _field_: field })); }; Dictionary.prototype.merge = function (dictionary) { merge(this.container, dictionary); }; Dictionary.prototype.hasRule = function (name) { var _a, _b; return !!((_b = (_a = this.container[this.locale]) === null || _a === void 0 ? void 0 : _a.messages) === null || _b === void 0 ? void 0 : _b[name]); }; return Dictionary; }()); var DICTIONARY; function localize(locale, dictionary) { var _a; if (!DICTIONARY) { DICTIONARY = new Dictionary('en', {}); setConfig({ defaultMessage: function (field, values) { return DICTIONARY.resolve(field, values === null || values === void 0 ? void 0 : values._rule_, values || {}); } }); } if (typeof locale === 'string') { DICTIONARY.locale = locale; if (dictionary) { DICTIONARY.merge((_a = {}, _a[locale] = dictionary, _a)); } localeChanged(); return; } DICTIONARY.merge(locale); } var RULES = {}; function normalizeSchema(schema) { var _a; if ((_a = schema.params) === null || _a === void 0 ? void 0 : _a.length) { schema.params = schema.params.map(function (param) { if (typeof param === 'string') { return { name: param }; } return param; }); } return schema; } var RuleContainer = /** @class */ (function () { function RuleContainer() { } RuleContainer.extend = function (name, schema) { // if rule already exists, overwrite it. var rule = normalizeSchema(schema); if (RULES[name]) { RULES[name] = merge(RULES[name], schema); return; } RULES[name] = __assign({ lazy: false, computesRequired: false }, rule); }; RuleContainer.isLazy = function (name) { var _a; return !!((_a = RULES[name]) === null || _a === void 0 ? void 0 : _a.lazy); }; RuleContainer.isRequireRule = function (name) { var _a; return !!((_a = RULES[name]) === null || _a === void 0 ? void 0 : _a.computesRequired); }; RuleContainer.getRuleDefinition = function (ruleName) { return RULES[ruleName]; }; return RuleContainer; }()); /** * Adds a custom validator to the list of validation rules. */ function extend(name, schema) { // makes sure new rules are properly formatted. guardExtend(name, schema); // Full schema object. if (typeof schema === 'object') { RuleContainer.extend(name, schema); return; } RuleContainer.extend(name, { validate: schema }); } /** * Guards from extension violations. */ function guardExtend(name, validator) { if (isCallable(validator)) { return; } if (isCallable(validator.validate)) { return; } if (RuleContainer.getRuleDefinition(name)) { return; } throw new Error("Extension Error: The validator '" + name + "' must be a function or have a 'validate' method."); } var aggressive = function () { return ({ on: ['input', 'blur'] }); }; var lazy = function () { return ({ on: ['change'] }); }; var eager = function (_a) { var errors = _a.errors; if (errors.length) { return { on: ['input', 'change'] }; } return { on: ['change', 'blur'] }; }; var passive = function () { return ({ on: [] }); }; var modes = { aggressive: aggressive, eager: eager, passive: passive, lazy: lazy }; var setInteractionMode = function (mode, implementation) { setConfig({ mode: mode }); if (!implementation) { return; } if (!isCallable(implementation)) { throw new Error('A mode implementation must be a function'); } modes[mode] = implementation; }; /** * Normalizes the given rules expression. */ function normalizeRules(rules) { // if falsy value return an empty object. var acc = {}; Object.defineProperty(acc, '_$$isNormalized', { value: true, writable: false, enumerable: false, configurable: false }); if (!rules) { return acc; } // Object is already normalized, skip. if (isObject(rules) && rules._$$isNormalized) { return rules; } if (isObject(rules)) { return Object.keys(rules).reduce(function (prev, curr) { var params = []; var preserveArrayParams = false; if (rules[curr] === true) { params = []; } else if (Array.isArray(rules[curr])) { params = rules[curr]; preserveArrayParams = true; } else if (isObject(rules[curr])) { params = rules[curr]; } else { params = [rules[curr]]; } if (rules[curr] !== false) { prev[curr] = buildParams(curr, params, preserveArrayParams); } return prev; }, acc); } /* istanbul ignore if */ if (typeof rules !== 'string') { warn('rules must be either a string or an object.'); return acc; } return rules.split('|').reduce(function (prev, rule) { var parsedRule = parseRule(rule); if (!parsedRule.name) { return prev; } prev[parsedRule.name] = buildParams(parsedRule.name, parsedRule.params); return prev; }, acc); } function buildParams(ruleName, provided, preserveArrayParams) { if (preserveArrayParams === void 0) { preserveArrayParams = false; } var ruleSchema = RuleContainer.getRuleDefinition(ruleName); if (!ruleSchema) { return provided; } var params = {}; if (!ruleSchema.params && !Array.isArray(provided)) { throw new Error('You provided an object params to a rule that has no defined schema.'); } // Rule probably uses an array for their args, keep it as is. if (Array.isArray(provided) && !ruleSchema.params) { return provided; } var definedParams; // collect the params schema. if (!ruleSchema.params || (ruleSchema.params.length < provided.length && Array.isArray(provided))) { var lastDefinedParam_1; // collect any additional parameters in the last item. definedParams = provided.map(function (_, idx) { var _a; var param = (_a = ruleSchema.params) === null || _a === void 0 ? void 0 : _a[idx]; lastDefinedParam_1 = param || lastDefinedParam_1; if (!param) { param = lastDefinedParam_1; } return param; }); } else { definedParams = ruleSchema.params; } // Match the provided array length with a temporary schema. for (var i = 0; i < definedParams.length; i++) { var options = definedParams[i]; var value = options.default; // if the provided is an array, map element value. if (Array.isArray(provided) && !preserveArrayParams) { if (i in provided) { value = provided[i]; } } else { // If the param exists in the provided object. if (options.name in provided) { value = provided[options.name]; // if the provided is the first param value. } else if (definedParams.length === 1) { value = provided; } } // if the param is a target, resolve the target value. if (options.isTarget) { value = createLocator(value, options.cast); } // A target param using interpolation if (typeof value === 'string' && value[0] === '@') { value = createLocator(value.slice(1), options.cast); } // If there is a transformer defined. if (!isLocator(value) && options.cast) { value = options.cast(value); } // already been set, probably multiple values. if (params[options.name]) { params[options.name] = Array.isArray(params[options.name]) ? params[options.name] : [params[options.name]]; params[options.name].push(value); } else { // set the value. params[options.name] = value; } } return params; } /** * Parses a rule string expression. */ var parseRule = function (rule) { var params = []; var name = rule.split(':')[0]; if (includes(rule, ':')) { params = rule .split(':') .slice(1) .join(':') .split(','); } return { name: name, params: params }; }; function createLocator(value, castFn) { var locator = function (crossTable) { var val = crossTable[value]; return castFn ? castFn(val) : val; }; locator.__locatorRef = value; return locator; } function extractLocators(params) { if (Array.isArray(params)) { return params.filter(isLocator); } return Object.keys(params) .filter(function (key) { return isLocator(params[key]); }) .map(function (key) { return params[key]; }); } /** * Validates a value against the rules. */ function validate$r(value, rules, options) { if (options === void 0) { options = {}; } return __awaiter(this, void 0, void 0, function () { var shouldBail, skipIfEmpty, field, result, errors, failedRules, regenerateMap; return __generator(this, function (_a) { switch (_a.label) { case 0: shouldBail = options === null || options === void 0 ? void 0 : options.bails; skipIfEmpty = options === null || options === void 0 ? void 0 : options.skipIfEmpty; field = { name: (options === null || options === void 0 ? void 0 : options.name) || '{field}', rules: normalizeRules(rules), bails: shouldBail !== null && shouldBail !== void 0 ? shouldBail : true, skipIfEmpty: skipIfEmpty !== null && skipIfEmpty !== void 0 ? skipIfEmpty : true, forceRequired: false, crossTable: (options === null || options === void 0 ? void 0 : options.values) || {}, names: (options === null || options === void 0 ? void 0 : options.names) || {}, customMessages: (options === null || options === void 0 ? void 0 : options.customMessages) || {} }; return [4 /*yield*/, _validate(field, value, options)]; case 1: result = _a.sent(); errors = []; failedRules = {}; regenerateMap = {}; result.errors.forEach(function (e) { var msg = e.msg(); errors.push(msg); failedRules[e.rule] = msg; regenerateMap[e.rule] = e.msg; }); return [2 /*return*/, { valid: result.valid, errors: errors, failedRules: failedRules, regenerateMap: regenerateMap }]; } }); }); } /** * Starts the validation process. */ function _validate(field, value, _a) { var _b = (_a === void 0 ? {} : _a).isInitial, isInitial = _b === void 0 ? false : _b; return __awaiter(this, void 0, void 0, function () { var _c, shouldSkip, errors, rules, length, i, rule, result; return __generator(this, function (_d) { switch (_d.label) { case 0: return [4 /*yield*/, _shouldSkip(field, value)]; case 1: _c = _d.sent(), shouldSkip = _c.shouldSkip, errors = _c.errors; if (shouldSkip) { return [2 /*return*/, { valid: !errors.length, errors: errors }]; } rules = Object.keys(field.rules).filter(function (rule) { return !RuleContainer.isRequireRule(rule); }); length = rules.length; i = 0; _d.label = 2; case 2: if (!(i < length)) return [3 /*break*/, 5]; if (isInitial && RuleContainer.isLazy(rules[i])) { return [3 /*break*/, 4]; } rule = rules[i]; return [4 /*yield*/, _test(field, value, { name: rule, params: field.rules[rule] })]; case 3: result = _d.sent(); if (!result.valid && result.error) { errors.push(result.error); if (field.bails) { return [2 /*return*/, { valid: false, errors: errors }]; } } _d.label = 4; case 4: i++; return [3 /*break*/, 2]; case 5: return [2 /*return*/, { valid: !errors.length, errors: errors }]; } }); }); } function _shouldSkip(field, value) { return __awaiter(this, void 0, void 0, function () { var requireRules, length, errors, isEmpty, isEmptyAndOptional, isRequired, i, rule, result; return __generator(this, function (_a) { switch (_a.label) { case 0: requireRules = Object.keys(field.rules).filter(RuleContainer.isRequireRule); length = requireRules.length; errors = []; isEmpty = isNullOrUndefined(value) || value === '' || isEmptyArray(value); isEmptyAndOptional = isEmpty && field.skipIfEmpty; isRequired = false; i = 0; _a.label = 1; case 1: if (!(i < length)) return [3 /*break*/, 4]; rule = requireRules[i]; return [4 /*yield*/, _test(field, value, { name: rule, params: field.rules[rule] })]; case 2: result = _a.sent(); if (!isObject(result)) { throw new Error('Require rules has to return an object (see docs)'); } if (result.required) { isRequired = true; } if (!result.valid && result.error) { errors.push(result.error); // Exit early as the field is required and failed validation. if (field.bails) { return [2 /*return*/, { shouldSkip: true, errors: errors }]; } } _a.label = 3; case 3: