Socket
Socket
Sign inDemoInstall

@vuelidate/validators

Package Overview
Dependencies
Maintainers
3
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vuelidate/validators - npm Package Compare versions

Comparing version 2.0.0-alpha.2 to 2.0.0-alpha.3

coverage/clover.xml

19

CHANGELOG.md

@@ -6,2 +6,21 @@ # Change Log

# [2.0.0-alpha.3](https://github.com/vuelidate/vuelidate/compare/@vuelidate/validators@2.0.0-alpha.2...@vuelidate/validators@2.0.0-alpha.3) (2020-10-23)
### Bug Fixes
* **validators:** fix `not`,`or`, `and` validators ([#724](https://github.com/vuelidate/vuelidate/issues/724)) ([995c6f9](https://github.com/vuelidate/vuelidate/commit/995c6f909e43e4e03622d96986123498e6fa6378))
* **validators:** Unify minLength validator format ([#726](https://github.com/vuelidate/vuelidate/issues/726)) ([e5d755a](https://github.com/vuelidate/vuelidate/commit/e5d755a429ee9bbb20c24d893e98fa7a082aaf0a))
* **validators:** update "numeric" validator ([#711](https://github.com/vuelidate/vuelidate/issues/711)) ([a80b157](https://github.com/vuelidate/vuelidate/commit/a80b1574f3e456970b92da61efe0e1e4a7a1e101))
* **validators:** update email regex validator ([#718](https://github.com/vuelidate/vuelidate/issues/718)) ([d68a480](https://github.com/vuelidate/vuelidate/commit/d68a48062c2cf21512d8c7e72ceb843a083ac4c5))
### Features
* typings ([#722](https://github.com/vuelidate/vuelidate/issues/722)) ([b99b8ab](https://github.com/vuelidate/vuelidate/commit/b99b8ab14fe6fdd81c3796594053147feb647961))
# [2.0.0-alpha.2](https://github.com/vuelidate/vuelidate/compare/@vuelidate/validators@2.0.0-alpha.1...@vuelidate/validators@2.0.0-alpha.2) (2020-09-13)

@@ -8,0 +27,0 @@

369

dist/index.esm.js

@@ -26,11 +26,2 @@ import { unref } from 'vue-demi';

/**
* Unwraps a ref, returning its value
* @param val
* @return {*}
*/
function unwrap(val) {
return unref(val);
}
/**
* Returns a standard ValidatorObject

@@ -55,4 +46,23 @@ * Wraps a plain function into a ValidatorObject

}
/**
* Unwraps a ValidatorResponse object, into a boolean.
* @param {ValidatorResponse} result
* @return {boolean}
*/
function unwrapValidatorResponse(result) {
if (_typeof(result) === 'object') return result.$invalid;
return result;
}
/**
* Unwraps a `NormalizedValidator` object, returning it's validator function.
* @param {NormalizedValidator | Function} validator
* @return {function}
*/
function unwrapNormalizedValidator(validator) {
return validator.$validator || validator;
}
/**
* Allows attaching parameters to a validator

@@ -82,6 +92,7 @@ * @param {Object} $params

* @param {NormalizedValidator|Function} $validator
* @return {NormalizedValidator}
*/
function withMessage($message, $validator) {
if (!isFunction($message) && typeof unwrap($message) !== 'string') throw new Error("[@vuelidate/validators]: First parameter to \"withMessage\" should be string or a function returning a string, provided ".concat(_typeof($message)));
if (!isFunction($message) && typeof unref($message) !== 'string') throw new Error("[@vuelidate/validators]: First parameter to \"withMessage\" should be string or a function returning a string, provided ".concat(_typeof($message)));
if (!isObject($validator) && !isFunction($validator)) throw new Error("[@vuelidate/validators]: Validator must be a function or object with $validator parameter");

@@ -94,3 +105,3 @@ var validatorObj = normalizeValidatorObject($validator);

var req = function req(value) {
value = unwrap(value);
value = unref(value);
if (Array.isArray(value)) return !!value.length;

@@ -128,3 +139,3 @@

var len = function len(value) {
value = unwrap(value);
value = unref(value);
if (Array.isArray(value)) return value.length;

@@ -144,8 +155,8 @@

var regex = function regex(expr) {
function regex(expr) {
return function (value) {
value = unwrap(value);
value = unref(value);
return !req(value) || expr.test(value);
};
};
}

@@ -161,3 +172,3 @@

regex: regex,
unwrap: unwrap,
unwrap: unref,
withAsync: withAsync

@@ -168,2 +179,7 @@ });

/**
* Validate if value is alphabetical string.
* @type {NormalizedValidator}
*/
var alpha$1 = {

@@ -176,2 +192,7 @@ $validator: alpha,

/**
* Validate if value is alpha-numeric string.
* @type {NormalizedValidator}
*/
var alphaNum$1 = {

@@ -182,4 +203,9 @@ $validator: alphaNum,

var numeric = regex(/^[0-9]*$/);
var numeric = regex(/^\d*(\.\d+)?$/);
/**
* Check whether a value is numeric.
* @type NormalizedValidator
*/
var numeric$1 = {

@@ -190,9 +216,23 @@ $validator: numeric,

var between = (function (min, max) {
/**
* Check if a numeric value is between two values.
* @param {Ref<Number> | Number} min
* @param {Ref<Number> | Number} max
* @return {function(*=): boolean}
*/
function between (min, max) {
return function (value) {
return !req(value) || (!/\s/.test(value) || value instanceof Date) && +unwrap(min) <= +value && +unwrap(max) >= +value;
return !req(value) || (!/\s/.test(value) || value instanceof Date) && +unref(min) <= +value && +unref(max) >= +value;
};
});
}
var between$1 = (function (min, max) {
/**
* Checks if a value is between two values.
* @param {Ref<Number> | Number} min
* @param {Ref<Number> | Number} max
* @return {NormalizedValidator}
*/
function between$1 (min, max) {
return {

@@ -209,7 +249,12 @@ $validator: between(min, max),

};
});
}
var emailRegex = /(^$|^(([^<>()[\]\\.,;:\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,}))$)/;
var 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])+)\])$/;
var email = regex(emailRegex);
/**
* Validate if value is an email.
* @type {NormalizedValidator}
*/
var email$1 = {

@@ -220,3 +265,9 @@ $validator: email,

var ipAddress = (function (value) {
/**
* Check if a string is an IP Address
* @param {String} value
* @returns {boolean}
*/
function ipAddress (value) {
if (!req(value)) {

@@ -232,3 +283,3 @@ return true;

return nibbles.length === 4 && nibbles.every(nibbleValid);
});
}

@@ -252,2 +303,7 @@ var nibbleValid = function nibbleValid(nibble) {

/**
* Validate if value is an ipAddress string.
* @type {NormalizedValidator}
*/
var ipAddress$1 = {

@@ -258,6 +314,12 @@ $validator: ipAddress,

var macAddress = (function () {
/**
* Check if value is a properly formatted Mac Address.
* @param {String | Ref<String>} [separator]
* @returns {function(*): boolean}
*/
function macAddress () {
var separator = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ':';
return function (value) {
separator = unwrap(separator);
separator = unref(separator);

@@ -275,3 +337,3 @@ if (!req(value)) {

};
});
}

@@ -282,3 +344,8 @@ var hexValid = function hexValid(hex) {

var macAddress$1 = (function (separator) {
/**
* Validate if value is a valid Mac Address string.
* @returns {NormalizedValidator}
*/
function macAddress$1 (separator) {
return {

@@ -288,11 +355,23 @@ $validator: macAddress(separator),

};
});
}
var maxLength = (function (length) {
/**
* Check if provided value has a maximum length
* @param {Number | Ref<Number>} length
* @returns {function(Array|Object|String): boolean}
*/
function maxLength (length) {
return function (value) {
return !req(value) || len(value) <= unwrap(length);
return !req(value) || len(value) <= unref(length);
};
});
}
var maxLength$1 = (function (max) {
/**
* Validate the max length of a string.
* @param {Number} max
* @return {NormalizedValidator}
*/
function maxLength$1 (max) {
return {

@@ -308,35 +387,54 @@ $validator: maxLength(max),

};
}); // Still figuring out which is less error prone
// export default (max) => withMessage(
// withParams({ max }, maxLength),
// ({ $params }) => `The maximum length allowed is ${$params.max}`
// )
}
var minLength = (function (length) {
/**
* Check if value is above a threshold.
* @param {Number | Ref<Number>} length
* @returns {function(Array|Object|String): boolean}
*/
function minLength (length) {
return function (value) {
return !req(value) || len(value) >= unwrap(length);
return !req(value) || len(value) >= unref(length);
};
});
}
var minLength$1 = (function (length) {
/**
* Check if value is above a threshold.
* @param {Number | Ref<Number>} min
* @returns {NormalizedValidator}
*/
function minLength$1 (min) {
return {
$validator: minLength(length),
$validator: minLength(min),
$message: function $message(_ref) {
var $params = _ref.$params;
return "This field should be at least ".concat($params.length, " long.");
return "This field should be at least ".concat($params.min, " long.");
},
$params: {
length: length
min: min
}
};
});
}
var required = (function (value) {
/**
* Validates if a value is empty.
* @param {String | Array | Date | Object} value
* @returns {boolean}
*/
function required (value) {
if (typeof value === 'string') {
return req(value.trim());
value = value.trim();
}
return req(value);
});
}
/**
* Check if a value is empty or not.
* @type {NormalizedValidator}
*/
var required$1 = {

@@ -357,3 +455,3 @@ $validator: required,

var requiredIf = (function (prop) {
function requiredIf (prop) {
return function (value) {

@@ -374,5 +472,11 @@ if (typeof prop !== 'function') {

};
});
}
var requiredIf$1 = (function (prop) {
/**
* Returns required if the passed property is truthy
* @param {Boolean | String | function(): (Boolean | Promise<boolean>)} prop
* @return {NormalizedValidator}
*/
function requiredIf$1 (prop) {
return {

@@ -382,3 +486,3 @@ $validator: requiredIf(prop),

};
});
}

@@ -389,3 +493,3 @@ var validate$1 = function validate(prop, val) {

/**
* Returns required if the passed property is truthy
* Returns required if the passed property is falsy.
* @param {Boolean | String | function(): (Boolean | Promise<boolean>)} prop

@@ -396,3 +500,3 @@ * @return {function(*): (Boolean | Promise<Boolean>)}

var requiredUnless = (function (prop) {
function requiredUnless (prop) {
return function (value) {

@@ -413,4 +517,10 @@ if (typeof prop !== 'function') {

};
});
}
/**
* Returns required unless the passed property is truthy
* @param {Boolean | String | function(): (Boolean | Promise<boolean>)} prop
* @return {NormalizedValidator}
*/
var requiredUnless$1 = (function (prop) {

@@ -423,9 +533,23 @@ return {

var sameAs = (function (equalTo) {
/**
* Check if two values are identical.
* @param {*} equalTo
* @return {function(*=): boolean}
*/
function sameAs (equalTo) {
return function (value) {
return unwrap(value) === unwrap(equalTo);
return unref(value) === unref(equalTo);
};
});
}
var sameAs$1 = (function (equalTo, otherName) {
/**
* Check if two values are identical
* @param {*} equalTo
* @param {String} [otherName]
* @return {NormalizedValidator}
*/
function sameAs$1 (equalTo) {
var otherName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'other';
return {

@@ -442,3 +566,3 @@ $validator: sameAs(equalTo),

};
});
}

@@ -448,2 +572,7 @@ var 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-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S*)?$/i;

/**
* Check if a value is a url
* @type {NormalizedValidator}
*/
var url$1 = {

@@ -454,3 +583,9 @@ $validator: url,

var or = (function () {
/**
* Returns true when one of the provided functions returns true.
* @param {...(NormalizedValidator|Function)} validators
* @return {function(...[*]=): boolean}
*/
function or () {
for (var _len = arguments.length, validators = new Array(_len), _key = 0; _key < _len; _key++) {

@@ -468,8 +603,14 @@ validators[_key] = arguments[_key];

return validators.length > 0 && validators.reduce(function (valid, fn) {
return valid || fn.apply(_this, args);
return valid || unwrapValidatorResponse(unwrapNormalizedValidator(fn).apply(_this, args));
}, false);
};
});
}
var or$1 = (function () {
/**
* Returns true when one of the provided functions returns true.
* @param {...(NormalizedValidator|Function)} validators
* @return {NormalizedValidator}
*/
function or$1 () {
return {

@@ -479,5 +620,11 @@ $validator: or.apply(void 0, arguments),

};
});
}
var and = (function () {
/**
* Returns true when all validators are truthy
* @param {...(NormalizedValidator|Function)} validators
* @return {function(...[*]=): boolean}
*/
function and () {
for (var _len = arguments.length, validators = new Array(_len), _key = 0; _key < _len; _key++) {

@@ -495,8 +642,14 @@ validators[_key] = arguments[_key];

return validators.length > 0 && validators.reduce(function (valid, fn) {
return valid && fn.apply(_this, args);
return valid && unwrapValidatorResponse(unwrapNormalizedValidator(fn).apply(_this, args));
}, true);
};
});
}
var and$1 = (function () {
/**
* Validate if all validators match.
* @param {...*} validators
* @returns {NormalizedValidator}
*/
function and$1 () {
return {

@@ -506,11 +659,23 @@ $validator: and.apply(void 0, arguments),

};
});
}
var not = (function (validator) {
/**
* Swaps the result of a value
* @param {NormalizedValidator|Function} validator
* @returns {function(*=, *=): boolean}
*/
function not (validator) {
return function (value, vm) {
return !req(value) || !validator.call(this, value, vm);
return !req(value) || !unwrapValidatorResponse(unwrapNormalizedValidator(validator).call(this, value, vm));
};
});
}
var not$1 = (function (validator) {
/**
* Swaps the result of a value
* @param {NormalizedValidator|Function} validator
* @returns {NormalizedValidator}
*/
function not$1 (validator) {
return {

@@ -520,11 +685,23 @@ $validator: not(validator),

};
});
}
var minValue = (function (min) {
/**
* Check if a value is above a threshold.
* @param {String | Number | Ref<Number> | Ref<String>} min
* @returns {function(*=): boolean}
*/
function minValue (min) {
return function (value) {
return !req(value) || (!/\s/.test(value) || value instanceof Date) && +value >= +unwrap(min);
return !req(value) || (!/\s/.test(value) || value instanceof Date) && +value >= +unref(min);
};
});
}
var minValue$1 = (function (min) {
/**
* Check if a value is above a threshold.
* @param {String | Number | Ref<Number> | Ref<String>} min
* @returns {NormalizedValidator}
*/
function minValue$1 (min) {
return {

@@ -540,10 +717,22 @@ $validator: minValue(min),

};
});
}
var maxValue = (function (max) {
/**
* Check if value is below a threshold.
* @param {Number | Ref<Number> | Ref<String>} max
* @returns {function(*=): boolean}
*/
function maxValue (max) {
return function (value) {
return !req(value) || (!/\s/.test(value) || value instanceof Date) && +value <= +unwrap(max);
return !req(value) || (!/\s/.test(value) || value instanceof Date) && +value <= +unref(max);
};
});
}
/**
* Check if value is below a threshold.
* @param {Number | Ref<Number> | Ref<String>} max
* @return {NormalizedValidator}
*/
var maxValue$1 = (function (max) {

@@ -566,2 +755,7 @@ return {

/**
* Validate if value is integer.
* @type {NormalizedValidator}
*/
var integer$1 = {

@@ -574,2 +768,7 @@ $validator: integer,

/**
* Validate if value is decimal number.
* @type {NormalizedValidator}
*/
var decimal$1 = {

@@ -576,0 +775,0 @@ $validator: decimal,

@@ -30,11 +30,2 @@ 'use strict';

/**
* Unwraps a ref, returning its value
* @param val
* @return {*}
*/
function unwrap(val) {
return vueDemi.unref(val);
}
/**
* Returns a standard ValidatorObject

@@ -59,4 +50,23 @@ * Wraps a plain function into a ValidatorObject

}
/**
* Unwraps a ValidatorResponse object, into a boolean.
* @param {ValidatorResponse} result
* @return {boolean}
*/
function unwrapValidatorResponse(result) {
if (_typeof(result) === 'object') return result.$invalid;
return result;
}
/**
* Unwraps a `NormalizedValidator` object, returning it's validator function.
* @param {NormalizedValidator | Function} validator
* @return {function}
*/
function unwrapNormalizedValidator(validator) {
return validator.$validator || validator;
}
/**
* Allows attaching parameters to a validator

@@ -86,6 +96,7 @@ * @param {Object} $params

* @param {NormalizedValidator|Function} $validator
* @return {NormalizedValidator}
*/
function withMessage($message, $validator) {
if (!isFunction($message) && typeof unwrap($message) !== 'string') throw new Error("[@vuelidate/validators]: First parameter to \"withMessage\" should be string or a function returning a string, provided ".concat(_typeof($message)));
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 ".concat(_typeof($message)));
if (!isObject($validator) && !isFunction($validator)) throw new Error("[@vuelidate/validators]: Validator must be a function or object with $validator parameter");

@@ -98,3 +109,3 @@ var validatorObj = normalizeValidatorObject($validator);

var req = function req(value) {
value = unwrap(value);
value = vueDemi.unref(value);
if (Array.isArray(value)) return !!value.length;

@@ -132,3 +143,3 @@

var len = function len(value) {
value = unwrap(value);
value = vueDemi.unref(value);
if (Array.isArray(value)) return value.length;

@@ -148,8 +159,8 @@

var regex = function regex(expr) {
function regex(expr) {
return function (value) {
value = unwrap(value);
value = vueDemi.unref(value);
return !req(value) || expr.test(value);
};
};
}

@@ -165,3 +176,3 @@

regex: regex,
unwrap: unwrap,
unwrap: vueDemi.unref,
withAsync: withAsync

@@ -172,2 +183,7 @@ });

/**
* Validate if value is alphabetical string.
* @type {NormalizedValidator}
*/
var alpha$1 = {

@@ -180,2 +196,7 @@ $validator: alpha,

/**
* Validate if value is alpha-numeric string.
* @type {NormalizedValidator}
*/
var alphaNum$1 = {

@@ -186,4 +207,9 @@ $validator: alphaNum,

var numeric = regex(/^[0-9]*$/);
var numeric = regex(/^\d*(\.\d+)?$/);
/**
* Check whether a value is numeric.
* @type NormalizedValidator
*/
var numeric$1 = {

@@ -194,9 +220,23 @@ $validator: numeric,

var between = (function (min, max) {
/**
* Check if a numeric value is between two values.
* @param {Ref<Number> | Number} min
* @param {Ref<Number> | Number} max
* @return {function(*=): boolean}
*/
function between (min, max) {
return function (value) {
return !req(value) || (!/\s/.test(value) || value instanceof Date) && +unwrap(min) <= +value && +unwrap(max) >= +value;
return !req(value) || (!/\s/.test(value) || value instanceof Date) && +vueDemi.unref(min) <= +value && +vueDemi.unref(max) >= +value;
};
});
}
var between$1 = (function (min, max) {
/**
* Checks if a value is between two values.
* @param {Ref<Number> | Number} min
* @param {Ref<Number> | Number} max
* @return {NormalizedValidator}
*/
function between$1 (min, max) {
return {

@@ -213,7 +253,12 @@ $validator: between(min, max),

};
});
}
var emailRegex = /(^$|^(([^<>()[\]\\.,;:\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,}))$)/;
var 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])+)\])$/;
var email = regex(emailRegex);
/**
* Validate if value is an email.
* @type {NormalizedValidator}
*/
var email$1 = {

@@ -224,3 +269,9 @@ $validator: email,

var ipAddress = (function (value) {
/**
* Check if a string is an IP Address
* @param {String} value
* @returns {boolean}
*/
function ipAddress (value) {
if (!req(value)) {

@@ -236,3 +287,3 @@ return true;

return nibbles.length === 4 && nibbles.every(nibbleValid);
});
}

@@ -256,2 +307,7 @@ var nibbleValid = function nibbleValid(nibble) {

/**
* Validate if value is an ipAddress string.
* @type {NormalizedValidator}
*/
var ipAddress$1 = {

@@ -262,6 +318,12 @@ $validator: ipAddress,

var macAddress = (function () {
/**
* Check if value is a properly formatted Mac Address.
* @param {String | Ref<String>} [separator]
* @returns {function(*): boolean}
*/
function macAddress () {
var separator = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ':';
return function (value) {
separator = unwrap(separator);
separator = vueDemi.unref(separator);

@@ -279,3 +341,3 @@ if (!req(value)) {

};
});
}

@@ -286,3 +348,8 @@ var hexValid = function hexValid(hex) {

var macAddress$1 = (function (separator) {
/**
* Validate if value is a valid Mac Address string.
* @returns {NormalizedValidator}
*/
function macAddress$1 (separator) {
return {

@@ -292,11 +359,23 @@ $validator: macAddress(separator),

};
});
}
var maxLength = (function (length) {
/**
* Check if provided value has a maximum length
* @param {Number | Ref<Number>} length
* @returns {function(Array|Object|String): boolean}
*/
function maxLength (length) {
return function (value) {
return !req(value) || len(value) <= unwrap(length);
return !req(value) || len(value) <= vueDemi.unref(length);
};
});
}
var maxLength$1 = (function (max) {
/**
* Validate the max length of a string.
* @param {Number} max
* @return {NormalizedValidator}
*/
function maxLength$1 (max) {
return {

@@ -312,35 +391,54 @@ $validator: maxLength(max),

};
}); // Still figuring out which is less error prone
// export default (max) => withMessage(
// withParams({ max }, maxLength),
// ({ $params }) => `The maximum length allowed is ${$params.max}`
// )
}
var minLength = (function (length) {
/**
* Check if value is above a threshold.
* @param {Number | Ref<Number>} length
* @returns {function(Array|Object|String): boolean}
*/
function minLength (length) {
return function (value) {
return !req(value) || len(value) >= unwrap(length);
return !req(value) || len(value) >= vueDemi.unref(length);
};
});
}
var minLength$1 = (function (length) {
/**
* Check if value is above a threshold.
* @param {Number | Ref<Number>} min
* @returns {NormalizedValidator}
*/
function minLength$1 (min) {
return {
$validator: minLength(length),
$validator: minLength(min),
$message: function $message(_ref) {
var $params = _ref.$params;
return "This field should be at least ".concat($params.length, " long.");
return "This field should be at least ".concat($params.min, " long.");
},
$params: {
length: length
min: min
}
};
});
}
var required = (function (value) {
/**
* Validates if a value is empty.
* @param {String | Array | Date | Object} value
* @returns {boolean}
*/
function required (value) {
if (typeof value === 'string') {
return req(value.trim());
value = value.trim();
}
return req(value);
});
}
/**
* Check if a value is empty or not.
* @type {NormalizedValidator}
*/
var required$1 = {

@@ -361,3 +459,3 @@ $validator: required,

var requiredIf = (function (prop) {
function requiredIf (prop) {
return function (value) {

@@ -378,5 +476,11 @@ if (typeof prop !== 'function') {

};
});
}
var requiredIf$1 = (function (prop) {
/**
* Returns required if the passed property is truthy
* @param {Boolean | String | function(): (Boolean | Promise<boolean>)} prop
* @return {NormalizedValidator}
*/
function requiredIf$1 (prop) {
return {

@@ -386,3 +490,3 @@ $validator: requiredIf(prop),

};
});
}

@@ -393,3 +497,3 @@ var validate$1 = function validate(prop, val) {

/**
* Returns required if the passed property is truthy
* Returns required if the passed property is falsy.
* @param {Boolean | String | function(): (Boolean | Promise<boolean>)} prop

@@ -400,3 +504,3 @@ * @return {function(*): (Boolean | Promise<Boolean>)}

var requiredUnless = (function (prop) {
function requiredUnless (prop) {
return function (value) {

@@ -417,4 +521,10 @@ if (typeof prop !== 'function') {

};
});
}
/**
* Returns required unless the passed property is truthy
* @param {Boolean | String | function(): (Boolean | Promise<boolean>)} prop
* @return {NormalizedValidator}
*/
var requiredUnless$1 = (function (prop) {

@@ -427,9 +537,23 @@ return {

var sameAs = (function (equalTo) {
/**
* Check if two values are identical.
* @param {*} equalTo
* @return {function(*=): boolean}
*/
function sameAs (equalTo) {
return function (value) {
return unwrap(value) === unwrap(equalTo);
return vueDemi.unref(value) === vueDemi.unref(equalTo);
};
});
}
var sameAs$1 = (function (equalTo, otherName) {
/**
* Check if two values are identical
* @param {*} equalTo
* @param {String} [otherName]
* @return {NormalizedValidator}
*/
function sameAs$1 (equalTo) {
var otherName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'other';
return {

@@ -446,3 +570,3 @@ $validator: sameAs(equalTo),

};
});
}

@@ -452,2 +576,7 @@ var 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-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S*)?$/i;

/**
* Check if a value is a url
* @type {NormalizedValidator}
*/
var url$1 = {

@@ -458,3 +587,9 @@ $validator: url,

var or = (function () {
/**
* Returns true when one of the provided functions returns true.
* @param {...(NormalizedValidator|Function)} validators
* @return {function(...[*]=): boolean}
*/
function or () {
for (var _len = arguments.length, validators = new Array(_len), _key = 0; _key < _len; _key++) {

@@ -472,8 +607,14 @@ validators[_key] = arguments[_key];

return validators.length > 0 && validators.reduce(function (valid, fn) {
return valid || fn.apply(_this, args);
return valid || unwrapValidatorResponse(unwrapNormalizedValidator(fn).apply(_this, args));
}, false);
};
});
}
var or$1 = (function () {
/**
* Returns true when one of the provided functions returns true.
* @param {...(NormalizedValidator|Function)} validators
* @return {NormalizedValidator}
*/
function or$1 () {
return {

@@ -483,5 +624,11 @@ $validator: or.apply(void 0, arguments),

};
});
}
var and = (function () {
/**
* Returns true when all validators are truthy
* @param {...(NormalizedValidator|Function)} validators
* @return {function(...[*]=): boolean}
*/
function and () {
for (var _len = arguments.length, validators = new Array(_len), _key = 0; _key < _len; _key++) {

@@ -499,8 +646,14 @@ validators[_key] = arguments[_key];

return validators.length > 0 && validators.reduce(function (valid, fn) {
return valid && fn.apply(_this, args);
return valid && unwrapValidatorResponse(unwrapNormalizedValidator(fn).apply(_this, args));
}, true);
};
});
}
var and$1 = (function () {
/**
* Validate if all validators match.
* @param {...*} validators
* @returns {NormalizedValidator}
*/
function and$1 () {
return {

@@ -510,11 +663,23 @@ $validator: and.apply(void 0, arguments),

};
});
}
var not = (function (validator) {
/**
* Swaps the result of a value
* @param {NormalizedValidator|Function} validator
* @returns {function(*=, *=): boolean}
*/
function not (validator) {
return function (value, vm) {
return !req(value) || !validator.call(this, value, vm);
return !req(value) || !unwrapValidatorResponse(unwrapNormalizedValidator(validator).call(this, value, vm));
};
});
}
var not$1 = (function (validator) {
/**
* Swaps the result of a value
* @param {NormalizedValidator|Function} validator
* @returns {NormalizedValidator}
*/
function not$1 (validator) {
return {

@@ -524,11 +689,23 @@ $validator: not(validator),

};
});
}
var minValue = (function (min) {
/**
* Check if a value is above a threshold.
* @param {String | Number | Ref<Number> | Ref<String>} min
* @returns {function(*=): boolean}
*/
function minValue (min) {
return function (value) {
return !req(value) || (!/\s/.test(value) || value instanceof Date) && +value >= +unwrap(min);
return !req(value) || (!/\s/.test(value) || value instanceof Date) && +value >= +vueDemi.unref(min);
};
});
}
var minValue$1 = (function (min) {
/**
* Check if a value is above a threshold.
* @param {String | Number | Ref<Number> | Ref<String>} min
* @returns {NormalizedValidator}
*/
function minValue$1 (min) {
return {

@@ -544,10 +721,22 @@ $validator: minValue(min),

};
});
}
var maxValue = (function (max) {
/**
* Check if value is below a threshold.
* @param {Number | Ref<Number> | Ref<String>} max
* @returns {function(*=): boolean}
*/
function maxValue (max) {
return function (value) {
return !req(value) || (!/\s/.test(value) || value instanceof Date) && +value <= +unwrap(max);
return !req(value) || (!/\s/.test(value) || value instanceof Date) && +value <= +vueDemi.unref(max);
};
});
}
/**
* Check if value is below a threshold.
* @param {Number | Ref<Number> | Ref<String>} max
* @return {NormalizedValidator}
*/
var maxValue$1 = (function (max) {

@@ -570,2 +759,7 @@ return {

/**
* Validate if value is integer.
* @type {NormalizedValidator}
*/
var integer$1 = {

@@ -578,2 +772,7 @@ $validator: integer,

/**
* Validate if value is decimal number.
* @type {NormalizedValidator}
*/
var decimal$1 = {

@@ -580,0 +779,0 @@ $validator: decimal,

@@ -26,11 +26,2 @@ import { unref } from 'vue-demi';

/**
* Unwraps a ref, returning its value
* @param val
* @return {*}
*/
function unwrap(val) {
return unref(val);
}
/**
* Returns a standard ValidatorObject

@@ -55,4 +46,23 @@ * Wraps a plain function into a ValidatorObject

}
/**
* Unwraps a ValidatorResponse object, into a boolean.
* @param {ValidatorResponse} result
* @return {boolean}
*/
function unwrapValidatorResponse(result) {
if (_typeof(result) === 'object') return result.$invalid;
return result;
}
/**
* Unwraps a `NormalizedValidator` object, returning it's validator function.
* @param {NormalizedValidator | Function} validator
* @return {function}
*/
function unwrapNormalizedValidator(validator) {
return validator.$validator || validator;
}
/**
* Allows attaching parameters to a validator

@@ -82,6 +92,7 @@ * @param {Object} $params

* @param {NormalizedValidator|Function} $validator
* @return {NormalizedValidator}
*/
function withMessage($message, $validator) {
if (!isFunction($message) && typeof unwrap($message) !== 'string') throw new Error("[@vuelidate/validators]: First parameter to \"withMessage\" should be string or a function returning a string, provided ".concat(_typeof($message)));
if (!isFunction($message) && typeof unref($message) !== 'string') throw new Error("[@vuelidate/validators]: First parameter to \"withMessage\" should be string or a function returning a string, provided ".concat(_typeof($message)));
if (!isObject($validator) && !isFunction($validator)) throw new Error("[@vuelidate/validators]: Validator must be a function or object with $validator parameter");

@@ -94,3 +105,3 @@ var validatorObj = normalizeValidatorObject($validator);

var req = function req(value) {
value = unwrap(value);
value = unref(value);
if (Array.isArray(value)) return !!value.length;

@@ -128,3 +139,3 @@

var len = function len(value) {
value = unwrap(value);
value = unref(value);
if (Array.isArray(value)) return value.length;

@@ -144,8 +155,8 @@

var regex = function regex(expr) {
function regex(expr) {
return function (value) {
value = unwrap(value);
value = unref(value);
return !req(value) || expr.test(value);
};
};
}

@@ -161,3 +172,3 @@

regex: regex,
unwrap: unwrap,
unwrap: unref,
withAsync: withAsync

@@ -170,14 +181,27 @@ });

var numeric = regex(/^[0-9]*$/);
var numeric = regex(/^\d*(\.\d+)?$/);
var between = (function (min, max) {
/**
* Check if a numeric value is between two values.
* @param {Ref<Number> | Number} min
* @param {Ref<Number> | Number} max
* @return {function(*=): boolean}
*/
function between (min, max) {
return function (value) {
return !req(value) || (!/\s/.test(value) || value instanceof Date) && +unwrap(min) <= +value && +unwrap(max) >= +value;
return !req(value) || (!/\s/.test(value) || value instanceof Date) && +unref(min) <= +value && +unref(max) >= +value;
};
});
}
var emailRegex = /(^$|^(([^<>()[\]\\.,;:\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,}))$)/;
var 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])+)\])$/;
var email = regex(emailRegex);
var ipAddress = (function (value) {
/**
* Check if a string is an IP Address
* @param {String} value
* @returns {boolean}
*/
function ipAddress (value) {
if (!req(value)) {

@@ -193,3 +217,3 @@ return true;

return nibbles.length === 4 && nibbles.every(nibbleValid);
});
}

@@ -213,6 +237,12 @@ var nibbleValid = function nibbleValid(nibble) {

var macAddress = (function () {
/**
* Check if value is a properly formatted Mac Address.
* @param {String | Ref<String>} [separator]
* @returns {function(*): boolean}
*/
function macAddress () {
var separator = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ':';
return function (value) {
separator = unwrap(separator);
separator = unref(separator);

@@ -230,3 +260,3 @@ if (!req(value)) {

};
});
}

@@ -237,21 +267,39 @@ var hexValid = function hexValid(hex) {

var maxLength = (function (length) {
/**
* Check if provided value has a maximum length
* @param {Number | Ref<Number>} length
* @returns {function(Array|Object|String): boolean}
*/
function maxLength (length) {
return function (value) {
return !req(value) || len(value) <= unwrap(length);
return !req(value) || len(value) <= unref(length);
};
});
}
var minLength = (function (length) {
/**
* Check if value is above a threshold.
* @param {Number | Ref<Number>} length
* @returns {function(Array|Object|String): boolean}
*/
function minLength (length) {
return function (value) {
return !req(value) || len(value) >= unwrap(length);
return !req(value) || len(value) >= unref(length);
};
});
}
var required = (function (value) {
/**
* Validates if a value is empty.
* @param {String | Array | Date | Object} value
* @returns {boolean}
*/
function required (value) {
if (typeof value === 'string') {
return req(value.trim());
value = value.trim();
}
return req(value);
});
}

@@ -268,3 +316,3 @@ var validate = function validate(prop, val) {

var requiredIf = (function (prop) {
function requiredIf (prop) {
return function (value) {

@@ -285,3 +333,3 @@ if (typeof prop !== 'function') {

};
});
}

@@ -292,3 +340,3 @@ var validate$1 = function validate(prop, val) {

/**
* Returns required if the passed property is truthy
* Returns required if the passed property is falsy.
* @param {Boolean | String | function(): (Boolean | Promise<boolean>)} prop

@@ -299,3 +347,3 @@ * @return {function(*): (Boolean | Promise<Boolean>)}

var requiredUnless = (function (prop) {
function requiredUnless (prop) {
return function (value) {

@@ -316,9 +364,15 @@ if (typeof prop !== 'function') {

};
});
}
var sameAs = (function (equalTo) {
/**
* Check if two values are identical.
* @param {*} equalTo
* @return {function(*=): boolean}
*/
function sameAs (equalTo) {
return function (value) {
return unwrap(value) === unwrap(equalTo);
return unref(value) === unref(equalTo);
};
});
}

@@ -328,3 +382,9 @@ var 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-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S*)?$/i;

var or = (function () {
/**
* Returns true when one of the provided functions returns true.
* @param {...(NormalizedValidator|Function)} validators
* @return {function(...[*]=): boolean}
*/
function or () {
for (var _len = arguments.length, validators = new Array(_len), _key = 0; _key < _len; _key++) {

@@ -342,8 +402,14 @@ validators[_key] = arguments[_key];

return validators.length > 0 && validators.reduce(function (valid, fn) {
return valid || fn.apply(_this, args);
return valid || unwrapValidatorResponse(unwrapNormalizedValidator(fn).apply(_this, args));
}, false);
};
});
}
var and = (function () {
/**
* Returns true when all validators are truthy
* @param {...(NormalizedValidator|Function)} validators
* @return {function(...[*]=): boolean}
*/
function and () {
for (var _len = arguments.length, validators = new Array(_len), _key = 0; _key < _len; _key++) {

@@ -361,24 +427,42 @@ validators[_key] = arguments[_key];

return validators.length > 0 && validators.reduce(function (valid, fn) {
return valid && fn.apply(_this, args);
return valid && unwrapValidatorResponse(unwrapNormalizedValidator(fn).apply(_this, args));
}, true);
};
});
}
var not = (function (validator) {
/**
* Swaps the result of a value
* @param {NormalizedValidator|Function} validator
* @returns {function(*=, *=): boolean}
*/
function not (validator) {
return function (value, vm) {
return !req(value) || !validator.call(this, value, vm);
return !req(value) || !unwrapValidatorResponse(unwrapNormalizedValidator(validator).call(this, value, vm));
};
});
}
var minValue = (function (min) {
/**
* Check if a value is above a threshold.
* @param {String | Number | Ref<Number> | Ref<String>} min
* @returns {function(*=): boolean}
*/
function minValue (min) {
return function (value) {
return !req(value) || (!/\s/.test(value) || value instanceof Date) && +value >= +unwrap(min);
return !req(value) || (!/\s/.test(value) || value instanceof Date) && +value >= +unref(min);
};
});
}
var maxValue = (function (max) {
/**
* Check if value is below a threshold.
* @param {Number | Ref<Number> | Ref<String>} max
* @returns {function(*=): boolean}
*/
function maxValue (max) {
return function (value) {
return !req(value) || (!/\s/.test(value) || value instanceof Date) && +value <= +unwrap(max);
return !req(value) || (!/\s/.test(value) || value instanceof Date) && +value <= +unref(max);
};
});
}

@@ -385,0 +469,0 @@ // ^-[0-9]+$ - only for negative integer (minus sign without at least 1 digit is not a number)

@@ -30,11 +30,2 @@ 'use strict';

/**
* Unwraps a ref, returning its value
* @param val
* @return {*}
*/
function unwrap(val) {
return vueDemi.unref(val);
}
/**
* Returns a standard ValidatorObject

@@ -59,4 +50,23 @@ * Wraps a plain function into a ValidatorObject

}
/**
* Unwraps a ValidatorResponse object, into a boolean.
* @param {ValidatorResponse} result
* @return {boolean}
*/
function unwrapValidatorResponse(result) {
if (_typeof(result) === 'object') return result.$invalid;
return result;
}
/**
* Unwraps a `NormalizedValidator` object, returning it's validator function.
* @param {NormalizedValidator | Function} validator
* @return {function}
*/
function unwrapNormalizedValidator(validator) {
return validator.$validator || validator;
}
/**
* Allows attaching parameters to a validator

@@ -86,6 +96,7 @@ * @param {Object} $params

* @param {NormalizedValidator|Function} $validator
* @return {NormalizedValidator}
*/
function withMessage($message, $validator) {
if (!isFunction($message) && typeof unwrap($message) !== 'string') throw new Error("[@vuelidate/validators]: First parameter to \"withMessage\" should be string or a function returning a string, provided ".concat(_typeof($message)));
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 ".concat(_typeof($message)));
if (!isObject($validator) && !isFunction($validator)) throw new Error("[@vuelidate/validators]: Validator must be a function or object with $validator parameter");

@@ -98,3 +109,3 @@ var validatorObj = normalizeValidatorObject($validator);

var req = function req(value) {
value = unwrap(value);
value = vueDemi.unref(value);
if (Array.isArray(value)) return !!value.length;

@@ -132,3 +143,3 @@

var len = function len(value) {
value = unwrap(value);
value = vueDemi.unref(value);
if (Array.isArray(value)) return value.length;

@@ -148,8 +159,8 @@

var regex = function regex(expr) {
function regex(expr) {
return function (value) {
value = unwrap(value);
value = vueDemi.unref(value);
return !req(value) || expr.test(value);
};
};
}

@@ -165,3 +176,3 @@

regex: regex,
unwrap: unwrap,
unwrap: vueDemi.unref,
withAsync: withAsync

@@ -174,14 +185,27 @@ });

var numeric = regex(/^[0-9]*$/);
var numeric = regex(/^\d*(\.\d+)?$/);
var between = (function (min, max) {
/**
* Check if a numeric value is between two values.
* @param {Ref<Number> | Number} min
* @param {Ref<Number> | Number} max
* @return {function(*=): boolean}
*/
function between (min, max) {
return function (value) {
return !req(value) || (!/\s/.test(value) || value instanceof Date) && +unwrap(min) <= +value && +unwrap(max) >= +value;
return !req(value) || (!/\s/.test(value) || value instanceof Date) && +vueDemi.unref(min) <= +value && +vueDemi.unref(max) >= +value;
};
});
}
var emailRegex = /(^$|^(([^<>()[\]\\.,;:\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,}))$)/;
var 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])+)\])$/;
var email = regex(emailRegex);
var ipAddress = (function (value) {
/**
* Check if a string is an IP Address
* @param {String} value
* @returns {boolean}
*/
function ipAddress (value) {
if (!req(value)) {

@@ -197,3 +221,3 @@ return true;

return nibbles.length === 4 && nibbles.every(nibbleValid);
});
}

@@ -217,6 +241,12 @@ var nibbleValid = function nibbleValid(nibble) {

var macAddress = (function () {
/**
* Check if value is a properly formatted Mac Address.
* @param {String | Ref<String>} [separator]
* @returns {function(*): boolean}
*/
function macAddress () {
var separator = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ':';
return function (value) {
separator = unwrap(separator);
separator = vueDemi.unref(separator);

@@ -234,3 +264,3 @@ if (!req(value)) {

};
});
}

@@ -241,21 +271,39 @@ var hexValid = function hexValid(hex) {

var maxLength = (function (length) {
/**
* Check if provided value has a maximum length
* @param {Number | Ref<Number>} length
* @returns {function(Array|Object|String): boolean}
*/
function maxLength (length) {
return function (value) {
return !req(value) || len(value) <= unwrap(length);
return !req(value) || len(value) <= vueDemi.unref(length);
};
});
}
var minLength = (function (length) {
/**
* Check if value is above a threshold.
* @param {Number | Ref<Number>} length
* @returns {function(Array|Object|String): boolean}
*/
function minLength (length) {
return function (value) {
return !req(value) || len(value) >= unwrap(length);
return !req(value) || len(value) >= vueDemi.unref(length);
};
});
}
var required = (function (value) {
/**
* Validates if a value is empty.
* @param {String | Array | Date | Object} value
* @returns {boolean}
*/
function required (value) {
if (typeof value === 'string') {
return req(value.trim());
value = value.trim();
}
return req(value);
});
}

@@ -272,3 +320,3 @@ var validate = function validate(prop, val) {

var requiredIf = (function (prop) {
function requiredIf (prop) {
return function (value) {

@@ -289,3 +337,3 @@ if (typeof prop !== 'function') {

};
});
}

@@ -296,3 +344,3 @@ var validate$1 = function validate(prop, val) {

/**
* Returns required if the passed property is truthy
* Returns required if the passed property is falsy.
* @param {Boolean | String | function(): (Boolean | Promise<boolean>)} prop

@@ -303,3 +351,3 @@ * @return {function(*): (Boolean | Promise<Boolean>)}

var requiredUnless = (function (prop) {
function requiredUnless (prop) {
return function (value) {

@@ -320,9 +368,15 @@ if (typeof prop !== 'function') {

};
});
}
var sameAs = (function (equalTo) {
/**
* Check if two values are identical.
* @param {*} equalTo
* @return {function(*=): boolean}
*/
function sameAs (equalTo) {
return function (value) {
return unwrap(value) === unwrap(equalTo);
return vueDemi.unref(value) === vueDemi.unref(equalTo);
};
});
}

@@ -332,3 +386,9 @@ var 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-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S*)?$/i;

var or = (function () {
/**
* Returns true when one of the provided functions returns true.
* @param {...(NormalizedValidator|Function)} validators
* @return {function(...[*]=): boolean}
*/
function or () {
for (var _len = arguments.length, validators = new Array(_len), _key = 0; _key < _len; _key++) {

@@ -346,8 +406,14 @@ validators[_key] = arguments[_key];

return validators.length > 0 && validators.reduce(function (valid, fn) {
return valid || fn.apply(_this, args);
return valid || unwrapValidatorResponse(unwrapNormalizedValidator(fn).apply(_this, args));
}, false);
};
});
}
var and = (function () {
/**
* Returns true when all validators are truthy
* @param {...(NormalizedValidator|Function)} validators
* @return {function(...[*]=): boolean}
*/
function and () {
for (var _len = arguments.length, validators = new Array(_len), _key = 0; _key < _len; _key++) {

@@ -365,24 +431,42 @@ validators[_key] = arguments[_key];

return validators.length > 0 && validators.reduce(function (valid, fn) {
return valid && fn.apply(_this, args);
return valid && unwrapValidatorResponse(unwrapNormalizedValidator(fn).apply(_this, args));
}, true);
};
});
}
var not = (function (validator) {
/**
* Swaps the result of a value
* @param {NormalizedValidator|Function} validator
* @returns {function(*=, *=): boolean}
*/
function not (validator) {
return function (value, vm) {
return !req(value) || !validator.call(this, value, vm);
return !req(value) || !unwrapValidatorResponse(unwrapNormalizedValidator(validator).call(this, value, vm));
};
});
}
var minValue = (function (min) {
/**
* Check if a value is above a threshold.
* @param {String | Number | Ref<Number> | Ref<String>} min
* @returns {function(*=): boolean}
*/
function minValue (min) {
return function (value) {
return !req(value) || (!/\s/.test(value) || value instanceof Date) && +value >= +unwrap(min);
return !req(value) || (!/\s/.test(value) || value instanceof Date) && +value >= +vueDemi.unref(min);
};
});
}
var maxValue = (function (max) {
/**
* Check if value is below a threshold.
* @param {Number | Ref<Number> | Ref<String>} max
* @returns {function(*=): boolean}
*/
function maxValue (max) {
return function (value) {
return !req(value) || (!/\s/.test(value) || value instanceof Date) && +value <= +unwrap(max);
return !req(value) || (!/\s/.test(value) || value instanceof Date) && +value <= +vueDemi.unref(max);
};
});
}

@@ -389,0 +473,0 @@ // ^-[0-9]+$ - only for negative integer (minus sign without at least 1 digit is not a number)

{
"name": "@vuelidate/validators",
"version": "2.0.0-alpha.2",
"version": "2.0.0-alpha.3",
"description": "Validators for Vuelidate",
"main": "dist/index.js",
"types": "index.d.ts",
"module": "dist/index.esm.js",

@@ -32,3 +33,3 @@ "repository": "https://github.com/vuelidate/vuelidate",

},
"gitHead": "d5a6afa502aab9ef8dac306a172e07ec088770d0"
"gitHead": "32dee5288f44b66d895d4b87e500bab26772f72c"
}

@@ -1,6 +0,4 @@

import withParams from './utils/withParams'
import withMessage from './utils/withMessage'
import { req, len, regex } from './raw/core'
export { withParams, withMessage, req, len, regex }
export { default as withParams } from './utils/withParams'
export { default as withMessage } from './utils/withMessage'
export { req, len, regex } from './raw/core'
export { unwrap, withAsync } from './utils/common'
import and from '../and'
import {
F,
T,
ValidatorResponseT,
ValidatorResponseF,
NormalizedF,
NormalizedT,
NormalizedValidatorResponseF,
NormalizedValidatorResponseT
} from '../../../tests/fixtures'
describe('and validator', () => {
const T = () => true
const F = () => false
it('should not validate no functions', () => {

@@ -36,2 +43,14 @@ expect(and()()).toBe(false)

})
it('should work with functions returning ValidatorResponse', () => {
expect(and(ValidatorResponseT, ValidatorResponseT, ValidatorResponseT)()).toBe(true)
expect(and(ValidatorResponseF, ValidatorResponseF, ValidatorResponseF)()).toBe(false)
})
it('should work with Normalized Validators', () => {
expect(and(NormalizedT, NormalizedT)()).toBe(true)
expect(and(NormalizedF, NormalizedF)()).toBe(false)
expect(and(NormalizedValidatorResponseT, NormalizedValidatorResponseT)()).toBe(true)
expect(and(NormalizedValidatorResponseF, NormalizedValidatorResponseF)()).toBe(false)
})
})

@@ -41,2 +41,5 @@ import email from '../email'

expect(email('"someone@gmail.com')).toBe(false)
expect(email('nonvalid±@gmail.com')).toBe(false)
expect(email('joão@gmail.com')).toBe(false)
expect(email('someõne@gmail.com')).toBe(false)
})

@@ -48,2 +51,3 @@

expect(email(' someone@gmail.com')).toBe(false)
expect(email('some one@gmail.com')).toBe(false)
})

@@ -61,3 +65,5 @@

expect(email('"some one"@gmail.com')).toBe(true)
expect(email('user.name+tag+sorting@example.com')).toBe(true)
expect(email('"john..doe"@example.org')).toBe(true)
})
})
import not from '../not'
import {
F,
T,
ValidatorResponseT,
ValidatorResponseF,
NormalizedF,
NormalizedT,
NormalizedValidatorResponseF,
NormalizedValidatorResponseT
} from '../../../tests/fixtures'
describe('not validator', () => {
const T = () => true
const F = () => false
it('should not validate with true function', () => {

@@ -28,2 +35,15 @@ expect(not(T)('test')).toBe(false)

})
it('should work with functions returning ValidatorResponse', () => {
expect(not(ValidatorResponseT)('test')).toBe(false)
expect(not(ValidatorResponseT)('')).toBe(true)
expect(not(ValidatorResponseF)('test')).toBe(true)
})
it('should work with Normalized Validators', () => {
expect(not(NormalizedT)('test')).toBe(false)
expect(not(NormalizedF)('')).toBe(true)
expect(not(NormalizedValidatorResponseT)('test')).toBe(false)
expect(not(NormalizedValidatorResponseF)('')).toBe(true)
})
})

@@ -48,5 +48,5 @@ import numeric from '../numeric'

it('should not validate decimal numbers', () => {
expect(numeric('0.1')).toBe(false)
expect(numeric('1.0')).toBe(false)
it('should validate decimal numbers', () => {
expect(numeric('0.1')).toBe(true)
expect(numeric('1.0')).toBe(true)
})

@@ -53,0 +53,0 @@

import or from '../or'
import {
T,
F,
NormalizedF,
NormalizedT,
NormalizedValidatorResponseF,
NormalizedValidatorResponseT,
ValidatorResponseF,
ValidatorResponseT
} from '../../../tests/fixtures'
describe('or validator', () => {
const T = () => true
const F = () => false
it('should not validate no functions', () => {

@@ -36,2 +43,14 @@ expect(or()()).toBe(false)

})
it('should work with functions returning ValidatorResponse', () => {
expect(or(ValidatorResponseT, ValidatorResponseF, ValidatorResponseF)()).toBe(true)
expect(or(ValidatorResponseF, ValidatorResponseF, ValidatorResponseF)()).toBe(false)
})
it('should work with Normalized Validators', () => {
expect(or(NormalizedT, NormalizedT)()).toBe(true)
expect(or(NormalizedF, NormalizedT)()).toBe(true)
expect(or(NormalizedValidatorResponseT, NormalizedValidatorResponseT)()).toBe(true)
expect(or(NormalizedValidatorResponseF, NormalizedValidatorResponseT)()).toBe(true)
})
})
import requiredIf from '../requiredIf'
import { T, F } from '../../../tests/fixtures'
const T = () => true
const F = () => false
const promiseT = () => Promise.resolve(true)

@@ -6,0 +5,0 @@ const promiseF = () => Promise.resolve(false)

import requiredUnless from '../requiredUnless'
import { T, F } from '../../../tests/fixtures'
const T = () => true
const F = () => false
describe('requiredUnless validator', () => {

@@ -7,0 +5,0 @@ it('should not validate if prop is falsy', () => {

@@ -1,8 +0,15 @@

export default (...validators) => {
import { unwrapNormalizedValidator, unwrapValidatorResponse } from '../utils/common'
/**
* Returns true when all validators are truthy
* @param {...(NormalizedValidator|Function)} validators
* @return {function(...[*]=): boolean}
*/
export default function (...validators) {
return function (...args) {
return (
validators.length > 0 &&
validators.reduce((valid, fn) => valid && fn.apply(this, args), true)
validators.reduce((valid, fn) => valid && unwrapValidatorResponse(unwrapNormalizedValidator(fn).apply(this, args)), true)
)
}
}
import { req } from '../common'
import { unwrap } from '../utils/common'
export default (min, max) =>
(value) =>
/**
* Check if a numeric value is between two values.
* @param {Ref<Number> | Number} min
* @param {Ref<Number> | Number} max
* @return {function(*=): boolean}
*/
export default function (min, max) {
return (value) =>
!req(value) ||

@@ -10,1 +16,2 @@ ((!/\s/.test(value) || value instanceof Date) &&

+unwrap(max) >= +value)
}

@@ -48,5 +48,7 @@ // "required" core, used in almost every validator to allow empty values

*/
export const regex = expr => value => {
value = unwrap(value)
return !req(value) || expr.test(value)
export function regex (expr) {
return value => {
value = unwrap(value)
return !req(value) || expr.test(value)
}
}
import { regex } from '../common'
const emailRegex = /(^$|^(([^<>()[\]\\.,;:\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,}))$)/
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])+)\])$/
export default regex(emailRegex)
import { req } from '../common'
export default (value) => {
/**
* Check if a string is an IP Address
* @param {String} value
* @returns {boolean}
*/
export default function (value) {
if (!req(value)) {

@@ -5,0 +10,0 @@ return true

import { req } from '../common'
import { unwrap } from '../utils/common'
export default (separator = ':') => (value) => {
separator = unwrap(separator)
/**
* Check if value is a properly formatted Mac Address.
* @param {String | Ref<String>} [separator]
* @returns {function(*): boolean}
*/
export default function (separator = ':') {
return value => {
separator = unwrap(separator)
if (!req(value)) {
return true
}
if (!req(value)) {
return true
}
if (typeof value !== 'string') {
return false
}
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
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)
)
return (
parts !== null &&
(parts.length === 6 || parts.length === 8) &&
parts.every(hexValid)
)
}
}
const hexValid = (hex) => hex.toLowerCase().match(/^[0-9a-f]{2}$/)
import { req, len } from '../common'
import { unwrap } from '../utils/common'
export default (length) =>
(value) => !req(value) || len(value) <= unwrap(length)
/**
* Check if provided value has a maximum length
* @param {Number | Ref<Number>} length
* @returns {function(Array|Object|String): boolean}
*/
export default function (length) {
return (value) => !req(value) || len(value) <= unwrap(length)
}
import { req } from '../common'
import { unwrap } from '../utils/common'
export default (max) =>
(value) =>
/**
* Check if value is below a threshold.
* @param {Number | Ref<Number> | Ref<String>} max
* @returns {function(*=): boolean}
*/
export default function (max) {
return value =>
!req(value) ||
((!/\s/.test(value) || value instanceof Date) && +value <= +unwrap(max))
}
import { req, len } from './core'
import { unwrap } from '../utils/common'
export default (length) => value => !req(value) || len(value) >= unwrap(length)
/**
* Check if value is above a threshold.
* @param {Number | Ref<Number>} length
* @returns {function(Array|Object|String): boolean}
*/
export default function (length) {
return value => !req(value) || len(value) >= unwrap(length)
}
import { req } from '../common'
import { unwrap } from '../utils/common'
export default (min) =>
(value) =>
/**
* Check if a value is above a threshold.
* @param {String | Number | Ref<Number> | Ref<String>} min
* @returns {function(*=): boolean}
*/
export default function (min) {
return (value) =>
!req(value) ||
((!/\s/.test(value) || value instanceof Date) && +value >= +unwrap(min))
}
import { req } from '../common'
import { unwrapNormalizedValidator, unwrapValidatorResponse } from '../utils/common'
// TODO: Double check this
export default (validator) => function (value, vm) {
return !req(value) || !validator.call(this, value, vm)
/**
* Swaps the result of a value
* @param {NormalizedValidator|Function} validator
* @returns {function(*=, *=): boolean}
*/
export default function (validator) {
return function (value, vm) {
return !req(value) || !unwrapValidatorResponse(unwrapNormalizedValidator(validator).call(this, value, vm))
}
}
import { regex } from '../common'
export default regex(/^[0-9]*$/)
export default regex(/^\d*(\.\d+)?$/)

@@ -1,8 +0,15 @@

export default (...validators) => {
import { unwrapNormalizedValidator, unwrapValidatorResponse } from '../utils/common'
/**
* Returns true when one of the provided functions returns true.
* @param {...(NormalizedValidator|Function)} validators
* @return {function(...[*]=): boolean}
*/
export default function (...validators) {
return function (...args) {
return (
validators.length > 0 &&
validators.reduce((valid, fn) => valid || fn.apply(this, args), false)
validators.reduce((valid, fn) => valid || unwrapValidatorResponse(unwrapNormalizedValidator(fn).apply(this, args)), false)
)
}
}
import { req } from '../common'
export default (value) => {
/**
* Validates if a value is empty.
* @param {String | Array | Date | Object} value
* @returns {boolean}
*/
export default function (value) {
if (typeof value === 'string') {
return req(value.trim())
value = value.trim()
}
return req(value)
}

@@ -10,13 +10,15 @@ import { req } from '../common'

*/
export default (prop) => (value) => {
if (typeof prop !== 'function') {
return validate(prop, value)
export default function (prop) {
return (value) => {
if (typeof prop !== 'function') {
return validate(prop, value)
}
const result = prop()
if (isPromise(result)) {
return result.then((response) => {
return validate(response, value)
})
}
return validate(result, value)
}
const result = prop()
if (isPromise(result)) {
return result.then((response) => {
return validate(response, value)
})
}
return validate(result, value)
}

@@ -6,17 +6,19 @@ import { req } from '../common'

/**
* Returns required if the passed property is truthy
* Returns required if the passed property is falsy.
* @param {Boolean | String | function(): (Boolean | Promise<boolean>)} prop
* @return {function(*): (Boolean | Promise<Boolean>)}
*/
export default (prop) => (value) => {
if (typeof prop !== 'function') {
return validate(prop, value)
export default function (prop) {
return (value) => {
if (typeof prop !== 'function') {
return validate(prop, value)
}
const result = prop()
if (isPromise(result)) {
return result.then((response) => {
return validate(response, value)
})
}
return validate(result, value)
}
const result = prop()
if (isPromise(result)) {
return result.then((response) => {
return validate(response, value)
})
}
return validate(result, value)
}
import { unwrap } from '../utils/common'
export default equalTo => value => unwrap(value) === unwrap(equalTo)
/**
* Check if two values are identical.
* @param {*} equalTo
* @return {function(*=): boolean}
*/
export default function (equalTo) {
return value => unwrap(value) === unwrap(equalTo)
}

@@ -1,3 +0,5 @@

import { unref } from 'vue-demi'
import { unref as unwrap } from 'vue-demi'
export { unwrap }
export function isFunction (val) {

@@ -12,11 +14,2 @@ return typeof val === 'function'

/**
* Unwraps a ref, returning its value
* @param val
* @return {*}
*/
export function unwrap (val) {
return unref(val)
}
/**
* Returns a standard ValidatorObject

@@ -54,1 +47,20 @@ * Wraps a plain function into a ValidatorObject

}
/**
* Unwraps a ValidatorResponse object, into a boolean.
* @param {ValidatorResponse} result
* @return {boolean}
*/
export function unwrapValidatorResponse (result) {
if (typeof result === 'object') return result.$invalid
return result
}
/**
* Unwraps a `NormalizedValidator` object, returning it's validator function.
* @param {NormalizedValidator | Function} validator
* @return {function}
*/
export function unwrapNormalizedValidator (validator) {
return validator.$validator || validator
}

@@ -13,2 +13,3 @@ import { normalizeValidatorObject, isFunction, isObject, unwrap } from './common'

* @param {NormalizedValidator|Function} $validator
* @return {NormalizedValidator}
*/

@@ -15,0 +16,0 @@ export default function withMessage ($message, $validator) {

import alpha from '../raw/alpha'
/**
* Validate if value is alphabetical string.
* @type {NormalizedValidator}
*/
export default {

@@ -4,0 +8,0 @@ $validator: alpha,

import alphaNum from '../raw/alphaNum'
/**
* Validate if value is alpha-numeric string.
* @type {NormalizedValidator}
*/
export default {

@@ -4,0 +8,0 @@ $validator: alphaNum,

import and from '../raw/and'
export default (...validators) => ({
$validator: and(...validators),
$message: 'The value does not match all of the provided validators'
})
/**
* Validate if all validators match.
* @param {...*} validators
* @returns {NormalizedValidator}
*/
export default function (...validators) {
return {
$validator: and(...validators),
$message: 'The value does not match all of the provided validators'
}
}
import between from '../raw/between'
export default (min, max) => ({
$validator: between(min, max),
$message: ({ $params }) => `The value must be between ${$params.min} and ${$params.max}`,
$params: { min, max }
})
/**
* Checks if a value is between two values.
* @param {Ref<Number> | Number} min
* @param {Ref<Number> | Number} max
* @return {NormalizedValidator}
*/
export default function (min, max) {
return {
$validator: between(min, max),
$message: ({ $params }) => `The value must be between ${$params.min} and ${$params.max}`,
$params: { min, max }
}
}
import decimal from '../raw/decimal'
/**
* Validate if value is decimal number.
* @type {NormalizedValidator}
*/
export default {

@@ -4,0 +8,0 @@ $validator: decimal,

import email from '../raw/email'
/**
* Validate if value is an email.
* @type {NormalizedValidator}
*/
export default {

@@ -4,0 +8,0 @@ $validator: email,

import integer from '../raw/integer'
/**
* Validate if value is integer.
* @type {NormalizedValidator}
*/
export default {

@@ -4,0 +8,0 @@ $validator: integer,

import ipAddress from '../raw/ipAddress'
/**
* Validate if value is an ipAddress string.
* @type {NormalizedValidator}
*/
export default {

@@ -4,0 +8,0 @@ $validator: ipAddress,

import macAddress from '../raw/macAddress'
export default (separator) => ({
$validator: macAddress(separator),
$message: 'The value is not a valid MAC Address'
})
/**
* Validate if value is a valid Mac Address string.
* @returns {NormalizedValidator}
*/
export default function (separator) {
return {
$validator: macAddress(separator),
$message: 'The value is not a valid MAC Address'
}
}
import maxLength from '../raw/maxLength'
// import { withMessage, withParams } from '../common'
export default (max) => ({
$validator: maxLength(max),
$message: ({ $params }) => `The maximum length allowed is ${$params.max}`,
$params: { max }
})
// Still figuring out which is less error prone
// export default (max) => withMessage(
// withParams({ max }, maxLength),
// ({ $params }) => `The maximum length allowed is ${$params.max}`
// )
/**
* Validate the max length of a string.
* @param {Number} max
* @return {NormalizedValidator}
*/
export default function (max) {
return {
$validator: maxLength(max),
$message: ({ $params }) => `The maximum length allowed is ${$params.max}`,
$params: { max }
}
}
import maxValue from '../raw/maxValue'
/**
* Check if value is below a threshold.
* @param {Number | Ref<Number> | Ref<String>} max
* @return {NormalizedValidator}
*/
export default max => ({

@@ -4,0 +9,0 @@ $validator: maxValue(max),

import minLength from '../raw/minLength'
export default length => ({
$validator: minLength(length),
$message: ({ $params }) => `This field should be at least ${$params.length} long.`,
$params: { length }
})
/**
* Check if value is above a threshold.
* @param {Number | Ref<Number>} min
* @returns {NormalizedValidator}
*/
export default function (min) {
return {
$validator: minLength(min),
$message: ({ $params }) => `This field should be at least ${$params.min} long.`,
$params: { min }
}
}
import minValue from '../raw/minValue'
export default min => ({
$validator: minValue(min),
$message: ({ $params }) => `The minimum value allowed is ${$params.min}`,
$params: { min }
})
/**
* Check if a value is above a threshold.
* @param {String | Number | Ref<Number> | Ref<String>} min
* @returns {NormalizedValidator}
*/
export default function (min) {
return {
$validator: minValue(min),
$message: ({ $params }) => `The minimum value allowed is ${$params.min}`,
$params: { min }
}
}
import not from '../raw/not'
export default validator => ({
$validator: not(validator),
$message: `The value does not match the provided validator`
})
/**
* Swaps the result of a value
* @param {NormalizedValidator|Function} validator
* @returns {NormalizedValidator}
*/
export default function (validator) {
return {
$validator: not(validator),
$message: `The value does not match the provided validator`
}
}
import numeric from '../raw/numeric'
/**
* Check whether a value is numeric.
* @type NormalizedValidator
*/
export default {

@@ -4,0 +8,0 @@ $validator: numeric,

import or from '../raw/or'
export default (...validators) => ({
$validator: or(...validators),
$message: 'The value does not match any of the provided validators'
})
/**
* Returns true when one of the provided functions returns true.
* @param {...(NormalizedValidator|Function)} validators
* @return {NormalizedValidator}
*/
export default function (...validators) {
return {
$validator: or(...validators),
$message: 'The value does not match any of the provided validators'
}
}
import required from '../raw/required'
/**
* Check if a value is empty or not.
* @type {NormalizedValidator}
*/
export default {

@@ -4,0 +8,0 @@ $validator: required,

import requiredIf from '../raw/requiredIf'
export default prop => ({
$validator: requiredIf(prop),
$message: 'The value is required'
})
/**
* Returns required if the passed property is truthy
* @param {Boolean | String | function(): (Boolean | Promise<boolean>)} prop
* @return {NormalizedValidator}
*/
export default function (prop) {
return {
$validator: requiredIf(prop),
$message: 'The value is required'
}
}
import requiredUnless from '../raw/requiredUnless'
/**
* Returns required unless the passed property is truthy
* @param {Boolean | String | function(): (Boolean | Promise<boolean>)} prop
* @return {NormalizedValidator}
*/
export default prop => ({

@@ -4,0 +9,0 @@ $validator: requiredUnless(prop),

import sameAs from '../raw/sameAs'
export default (equalTo, otherName) => ({
$validator: sameAs(equalTo),
$message: ({ $params }) => `The value must be equal to the ${otherName} value.`,
$params: { equalTo, otherName }
})
/**
* Check if two values are identical
* @param {*} equalTo
* @param {String} [otherName]
* @return {NormalizedValidator}
*/
export default function (equalTo, otherName = 'other') {
return {
$validator: sameAs(equalTo),
$message: ({ $params }) => `The value must be equal to the ${otherName} value.`,
$params: { equalTo, otherName }
}
}
import url from '../raw/url'
/**
* Check if a value is a url
* @type {NormalizedValidator}
*/
export default {

@@ -4,0 +8,0 @@ $validator: url,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc