123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757 |
- 'use strict';
- var vueDemi = require('vue-demi');
- function ownKeys(object, enumerableOnly) {
- var keys = Object.keys(object);
- if (Object.getOwnPropertySymbols) {
- var symbols = Object.getOwnPropertySymbols(object);
- enumerableOnly && (symbols = symbols.filter(function (sym) {
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
- })), keys.push.apply(keys, symbols);
- }
- return keys;
- }
- function _objectSpread2(target) {
- for (var i = 1; i < arguments.length; i++) {
- var source = null != arguments[i] ? arguments[i] : {};
- i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
- _defineProperty(target, key, source[key]);
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
- });
- }
- return target;
- }
- function _defineProperty(obj, key, value) {
- if (key in obj) {
- Object.defineProperty(obj, key, {
- value: value,
- enumerable: true,
- configurable: true,
- writable: true
- });
- } else {
- obj[key] = value;
- }
- return obj;
- }
- function isFunction(val) {
- return typeof val === 'function';
- }
- function isObject(o) {
- return o !== null && typeof o === 'object' && !Array.isArray(o);
- }
- function normalizeValidatorObject(validator) {
- return isFunction(validator.$validator) ? _objectSpread2({}, validator) : {
- $validator: validator
- };
- }
- function isPromise(object) {
- return isObject(object) && isFunction(object.then);
- }
- function unwrapValidatorResponse(result) {
- if (typeof result === 'object') return result.$valid;
- return result;
- }
- function unwrapNormalizedValidator(validator) {
- return validator.$validator || validator;
- }
- function withParams($params, $validator) {
- if (!isObject($params)) throw new Error(`[@vuelidate/validators]: First parameter to "withParams" should be an object, provided ${typeof $params}`);
- if (!isObject($validator) && !isFunction($validator)) throw new Error(`[@vuelidate/validators]: Validator must be a function or object with $validator parameter`);
- const validatorObj = normalizeValidatorObject($validator);
- validatorObj.$params = _objectSpread2(_objectSpread2({}, validatorObj.$params || {}), $params);
- return validatorObj;
- }
- function withMessage($message, $validator) {
- if (!isFunction($message) && typeof vueDemi.unref($message) !== 'string') throw new Error(`[@vuelidate/validators]: First parameter to "withMessage" should be string or a function returning a string, provided ${typeof $message}`);
- if (!isObject($validator) && !isFunction($validator)) throw new Error(`[@vuelidate/validators]: Validator must be a function or object with $validator parameter`);
- const validatorObj = normalizeValidatorObject($validator);
- validatorObj.$message = $message;
- return validatorObj;
- }
- function withAsync($validator) {
- let $watchTargets = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
- const validatorObj = normalizeValidatorObject($validator);
- return _objectSpread2(_objectSpread2({}, validatorObj), {}, {
- $async: true,
- $watchTargets
- });
- }
- function forEach(validators) {
- return {
- $validator(collection) {
- for (var _len = arguments.length, others = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
- others[_key - 1] = arguments[_key];
- }
- return vueDemi.unref(collection).reduce((previous, collectionItem, index) => {
- const collectionEntryResult = Object.entries(collectionItem).reduce((all, _ref) => {
- let [property, $model] = _ref;
- const innerValidators = validators[property] || {};
- const propertyResult = Object.entries(innerValidators).reduce((all, _ref2) => {
- let [validatorName, currentValidator] = _ref2;
- const validatorFunction = unwrapNormalizedValidator(currentValidator);
- const $response = validatorFunction.call(this, $model, collectionItem, index, ...others);
- const $valid = unwrapValidatorResponse($response);
- all.$data[validatorName] = $response;
- all.$data.$invalid = !$valid || !!all.$data.$invalid;
- all.$data.$error = all.$data.$invalid;
- if (!$valid) {
- let $message = currentValidator.$message || '';
- const $params = currentValidator.$params || {};
- if (typeof $message === 'function') {
- $message = $message({
- $pending: false,
- $invalid: !$valid,
- $params,
- $model,
- $response
- });
- }
- all.$errors.push({
- $property: property,
- $message,
- $params,
- $response,
- $model,
- $pending: false,
- $validator: validatorName
- });
- }
- return {
- $valid: all.$valid && $valid,
- $data: all.$data,
- $errors: all.$errors
- };
- }, {
- $valid: true,
- $data: {},
- $errors: []
- });
- all.$data[property] = propertyResult.$data;
- all.$errors[property] = propertyResult.$errors;
- return {
- $valid: all.$valid && propertyResult.$valid,
- $data: all.$data,
- $errors: all.$errors
- };
- }, {
- $valid: true,
- $data: {},
- $errors: {}
- });
- return {
- $valid: previous.$valid && collectionEntryResult.$valid,
- $data: previous.$data.concat(collectionEntryResult.$data),
- $errors: previous.$errors.concat(collectionEntryResult.$errors)
- };
- }, {
- $valid: true,
- $data: [],
- $errors: []
- });
- },
- $message: _ref3 => {
- let {
- $response
- } = _ref3;
- return $response ? $response.$errors.map(context => {
- return Object.values(context).map(errors => errors.map(error => error.$message)).reduce((a, b) => a.concat(b), []);
- }) : [];
- }
- };
- }
- const req = value => {
- value = vueDemi.unref(value);
- if (Array.isArray(value)) return !!value.length;
- if (value === undefined || value === null) {
- return false;
- }
- if (value === false) {
- return true;
- }
- if (value instanceof Date) {
- return !isNaN(value.getTime());
- }
- if (typeof value === 'object') {
- for (let _ in value) return true;
- return false;
- }
- return !!String(value).length;
- };
- const len = value => {
- value = vueDemi.unref(value);
- if (Array.isArray(value)) return value.length;
- if (typeof value === 'object') {
- return Object.keys(value).length;
- }
- return String(value).length;
- };
- function regex() {
- for (var _len = arguments.length, expr = new Array(_len), _key = 0; _key < _len; _key++) {
- expr[_key] = arguments[_key];
- }
- return value => {
- value = vueDemi.unref(value);
- return !req(value) || expr.every(reg => {
- reg.lastIndex = 0;
- return reg.test(value);
- });
- };
- }
- var common = /*#__PURE__*/Object.freeze({
- __proto__: null,
- forEach: forEach,
- len: len,
- normalizeValidatorObject: normalizeValidatorObject,
- regex: regex,
- req: req,
- unwrap: vueDemi.unref,
- unwrapNormalizedValidator: unwrapNormalizedValidator,
- unwrapValidatorResponse: unwrapValidatorResponse,
- withAsync: withAsync,
- withMessage: withMessage,
- withParams: withParams
- });
- var alpha$1 = regex(/^[a-zA-Z]*$/);
- var alpha = {
- $validator: alpha$1,
- $message: 'The value is not alphabetical',
- $params: {
- type: 'alpha'
- }
- };
- var alphaNum$1 = regex(/^[a-zA-Z0-9]*$/);
- var alphaNum = {
- $validator: alphaNum$1,
- $message: 'The value must be alpha-numeric',
- $params: {
- type: 'alphaNum'
- }
- };
- var numeric$1 = regex(/^\d*(\.\d+)?$/);
- var numeric = {
- $validator: numeric$1,
- $message: 'Value must be numeric',
- $params: {
- type: 'numeric'
- }
- };
- function between$1 (min, max) {
- return value => !req(value) || (!/\s/.test(value) || value instanceof Date) && +vueDemi.unref(min) <= +value && +vueDemi.unref(max) >= +value;
- }
- function between (min, max) {
- return {
- $validator: between$1(min, max),
- $message: _ref => {
- let {
- $params
- } = _ref;
- return `The value must be between ${$params.min} and ${$params.max}`;
- },
- $params: {
- min,
- max,
- type: 'between'
- }
- };
- }
- const emailRegex = /^(?:[A-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[A-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]{2,}(?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i;
- var email$1 = regex(emailRegex);
- var email = {
- $validator: email$1,
- $message: 'Value is not a valid email address',
- $params: {
- type: 'email'
- }
- };
- function ipAddress$1 (value) {
- if (!req(value)) {
- return true;
- }
- if (typeof value !== 'string') {
- return false;
- }
- const nibbles = value.split('.');
- return nibbles.length === 4 && nibbles.every(nibbleValid);
- }
- const nibbleValid = nibble => {
- if (nibble.length > 3 || nibble.length === 0) {
- return false;
- }
- if (nibble[0] === '0' && nibble !== '0') {
- return false;
- }
- if (!nibble.match(/^\d+$/)) {
- return false;
- }
- const numeric = +nibble | 0;
- return numeric >= 0 && numeric <= 255;
- };
- var ipAddress = {
- $validator: ipAddress$1,
- $message: 'The value is not a valid IP address',
- $params: {
- type: 'ipAddress'
- }
- };
- function macAddress$1 () {
- let separator = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ':';
- return value => {
- separator = vueDemi.unref(separator);
- if (!req(value)) {
- return true;
- }
- if (typeof value !== 'string') {
- return false;
- }
- const parts = typeof separator === 'string' && separator !== '' ? value.split(separator) : value.length === 12 || value.length === 16 ? value.match(/.{2}/g) : null;
- return parts !== null && (parts.length === 6 || parts.length === 8) && parts.every(hexValid);
- };
- }
- const hexValid = hex => hex.toLowerCase().match(/^[0-9a-f]{2}$/);
- function macAddress (separator) {
- return {
- $validator: macAddress$1(separator),
- $message: 'The value is not a valid MAC Address',
- $params: {
- type: 'macAddress'
- }
- };
- }
- function maxLength$1 (length) {
- return value => !req(value) || len(value) <= vueDemi.unref(length);
- }
- function maxLength (max) {
- return {
- $validator: maxLength$1(max),
- $message: _ref => {
- let {
- $params
- } = _ref;
- return `The maximum length allowed is ${$params.max}`;
- },
- $params: {
- max,
- type: 'maxLength'
- }
- };
- }
- function minLength$1 (length) {
- return value => !req(value) || len(value) >= vueDemi.unref(length);
- }
- function minLength (min) {
- return {
- $validator: minLength$1(min),
- $message: _ref => {
- let {
- $params
- } = _ref;
- return `This field should be at least ${$params.min} characters long`;
- },
- $params: {
- min,
- type: 'minLength'
- }
- };
- }
- function required$1 (value) {
- if (typeof value === 'string') {
- value = value.trim();
- }
- return req(value);
- }
- var required = {
- $validator: required$1,
- $message: 'Value is required',
- $params: {
- type: 'required'
- }
- };
- const validate$1 = (prop, val) => prop ? req(typeof val === 'string' ? val.trim() : val) : true;
- function requiredIf$1(propOrFunction) {
- return function (value, parentVM) {
- if (typeof propOrFunction !== 'function') {
- return validate$1(vueDemi.unref(propOrFunction), value);
- }
- const result = propOrFunction.call(this, value, parentVM);
- return validate$1(result, value);
- };
- }
- function requiredIf (prop) {
- return {
- $validator: requiredIf$1(prop),
- $message: 'The value is required',
- $params: {
- type: 'requiredIf',
- prop
- }
- };
- }
- const validate = (prop, val) => !prop ? req(typeof val === 'string' ? val.trim() : val) : true;
- function requiredUnless$1(propOrFunction) {
- return function (value, parentVM) {
- if (typeof propOrFunction !== 'function') {
- return validate(vueDemi.unref(propOrFunction), value);
- }
- const result = propOrFunction.call(this, value, parentVM);
- return validate(result, value);
- };
- }
- function requiredUnless (prop) {
- return {
- $validator: requiredUnless$1(prop),
- $message: 'The value is required',
- $params: {
- type: 'requiredUnless',
- prop
- }
- };
- }
- function sameAs$1 (equalTo) {
- return value => vueDemi.unref(value) === vueDemi.unref(equalTo);
- }
- function sameAs (equalTo) {
- let otherName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'other';
- return {
- $validator: sameAs$1(equalTo),
- $message: _ref => {
- return `The value must be equal to the ${otherName} value`;
- },
- $params: {
- equalTo,
- otherName,
- type: 'sameAs'
- }
- };
- }
- const urlRegex = /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)+(?:[a-z\u00a1-\uffff]{2,}\.?))(?::\d{2,5})?(?:[/?#]\S*)?$/i;
- var url$1 = regex(urlRegex);
- var url = {
- $validator: url$1,
- $message: 'The value is not a valid URL address',
- $params: {
- type: 'url'
- }
- };
- function syncOr(validators) {
- return function () {
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
- args[_key] = arguments[_key];
- }
- return validators.reduce((valid, fn) => {
- if (unwrapValidatorResponse(valid)) return valid;
- return unwrapNormalizedValidator(fn).apply(this, args);
- }, false);
- };
- }
- function asyncOr(validators) {
- return function () {
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
- args[_key2] = arguments[_key2];
- }
- return validators.reduce(async (valid, fn) => {
- const r = await valid;
- if (unwrapValidatorResponse(r)) return r;
- return unwrapNormalizedValidator(fn).apply(this, args);
- }, Promise.resolve(false));
- };
- }
- function or$1() {
- for (var _len3 = arguments.length, validators = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
- validators[_key3] = arguments[_key3];
- }
- const $async = validators.some(v => v.$async);
- const $watchTargets = validators.reduce((all, v) => {
- if (!v.$watchTargets) return all;
- return all.concat(v.$watchTargets);
- }, []);
- let $validator = () => false;
- if (validators.length) $validator = $async ? asyncOr(validators) : syncOr(validators);
- return {
- $async,
- $validator,
- $watchTargets
- };
- }
- function or () {
- return withParams({
- type: 'or'
- }, withMessage('The value does not match any of the provided validators', or$1(...arguments)));
- }
- function syncAnd(validators) {
- return function () {
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
- args[_key] = arguments[_key];
- }
- return validators.reduce((valid, fn) => {
- if (!unwrapValidatorResponse(valid)) return valid;
- return unwrapNormalizedValidator(fn).apply(this, args);
- }, true);
- };
- }
- function asyncAnd(validators) {
- return function () {
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
- args[_key2] = arguments[_key2];
- }
- return validators.reduce(async (valid, fn) => {
- const r = await valid;
- if (!unwrapValidatorResponse(r)) return r;
- return unwrapNormalizedValidator(fn).apply(this, args);
- }, Promise.resolve(true));
- };
- }
- function and$1() {
- for (var _len3 = arguments.length, validators = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
- validators[_key3] = arguments[_key3];
- }
- const $async = validators.some(v => v.$async);
- const $watchTargets = validators.reduce((all, v) => {
- if (!v.$watchTargets) return all;
- return all.concat(v.$watchTargets);
- }, []);
- let $validator = () => false;
- if (validators.length) $validator = $async ? asyncAnd(validators) : syncAnd(validators);
- return {
- $async,
- $validator,
- $watchTargets
- };
- }
- function and () {
- return withParams({
- type: 'and'
- }, withMessage('The value does not match all of the provided validators', and$1(...arguments)));
- }
- function not$1 (validator) {
- return function (value, vm) {
- if (!req(value)) return true;
- const response = unwrapNormalizedValidator(validator).call(this, value, vm);
- if (!isPromise(response)) return !unwrapValidatorResponse(response);
- return response.then(r => !unwrapValidatorResponse(r));
- };
- }
- function not (validator) {
- return {
- $validator: not$1(validator),
- $message: `The value does not match the provided validator`,
- $params: {
- type: 'not'
- }
- };
- }
- function minValue$1 (min) {
- return value => !req(value) || (!/\s/.test(value) || value instanceof Date) && +value >= +vueDemi.unref(min);
- }
- function minValue (min) {
- return {
- $validator: minValue$1(min),
- $message: _ref => {
- let {
- $params
- } = _ref;
- return `The minimum value allowed is ${$params.min}`;
- },
- $params: {
- min,
- type: 'minValue'
- }
- };
- }
- function maxValue$1 (max) {
- return value => !req(value) || (!/\s/.test(value) || value instanceof Date) && +value <= +vueDemi.unref(max);
- }
- var maxValue = (max => ({
- $validator: maxValue$1(max),
- $message: _ref => {
- let {
- $params
- } = _ref;
- return `The maximum value allowed is ${$params.max}`;
- },
- $params: {
- max,
- type: 'maxValue'
- }
- }));
- var integer$1 = regex(/(^[0-9]*$)|(^-[0-9]+$)/);
- var integer = {
- $validator: integer$1,
- $message: 'Value is not an integer',
- $params: {
- type: 'integer'
- }
- };
- var decimal$1 = regex(/^[-]?\d*(\.\d+)?$/);
- var decimal = {
- $validator: decimal$1,
- $message: 'Value must be decimal',
- $params: {
- type: 'decimal'
- }
- };
- function createI18nMessage(_ref) {
- let {
- t,
- messagePath = _ref2 => {
- let {
- $validator
- } = _ref2;
- return `validations.${$validator}`;
- },
- messageParams = params => params
- } = _ref;
- return function withI18nMessage(validator) {
- let {
- withArguments = false,
- messagePath: localMessagePath = messagePath,
- messageParams: localMessageParams = messageParams
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
- function message(props) {
- return t(localMessagePath(props), localMessageParams(_objectSpread2({
- model: props.$model,
- property: props.$property,
- pending: props.$pending,
- invalid: props.$invalid,
- response: props.$response,
- validator: props.$validator,
- propertyPath: props.$propertyPath
- }, props.$params)));
- }
- if (withArguments && typeof validator === 'function') {
- return function () {
- return withMessage(message, validator(...arguments));
- };
- }
- return withMessage(message, validator);
- };
- }
- exports.alpha = alpha;
- exports.alphaNum = alphaNum;
- exports.and = and;
- exports.between = between;
- exports.createI18nMessage = createI18nMessage;
- exports.decimal = decimal;
- exports.email = email;
- exports.helpers = common;
- exports.integer = integer;
- exports.ipAddress = ipAddress;
- exports.macAddress = macAddress;
- exports.maxLength = maxLength;
- exports.maxValue = maxValue;
- exports.minLength = minLength;
- exports.minValue = minValue;
- exports.not = not;
- exports.numeric = numeric;
- exports.or = or;
- exports.required = required;
- exports.requiredIf = requiredIf;
- exports.requiredUnless = requiredUnless;
- exports.sameAs = sameAs;
- exports.url = url;
|