Comparing version 2.0.7 to 2.0.9
'use strict'; | ||
var isUrl = require('./validators/url'); | ||
var isUri = require('./validators/uri'); | ||
var isWebUrl = require('./validators/webUrl'); | ||
var isHexColor = require('./validators/hexColor'); | ||
var isString = require('./validators/string'); | ||
var isArray = require('./validators/array'); | ||
var isNull = require('./validators/null'); | ||
var isUndefined = require('./validators/undefined'); | ||
var isExisty = require('./validators/existy'); | ||
var isInteger = require('./validators/integer'); | ||
var isFinite = require('./validators/finite'); | ||
var isNatural = require('./validators/natural'); | ||
var isBuffer = require('./validators/buffer'); | ||
var isBoolean = require('./validators/boolean'); | ||
var isFunction = require('./validators/function'); | ||
var isPlainObject = require('./validators/plainObject'); | ||
var isDate = require('./validators/date'); | ||
var isUrl = require('./predicates/url'); | ||
var isUri = require('./predicates/uri'); | ||
var isWebUrl = require('./predicates/webUrl'); | ||
var isHexColor = require('./predicates/hexColor'); | ||
var isString = require('./predicates/string'); | ||
var isArray = require('./predicates/array'); | ||
var isNull = require('./predicates/null'); | ||
var isUndefined = require('./predicates/undefined'); | ||
var isExisty = require('./predicates/existy'); | ||
var isInteger = require('./predicates/integer'); | ||
var isFinite = require('./predicates/finite'); | ||
var isNatural = require('./predicates/natural'); | ||
var isBuffer = require('./predicates/buffer'); | ||
var isBoolean = require('./predicates/boolean'); | ||
var isFunction = require('./predicates/function'); | ||
var isPlainObject = require('./predicates/plainObject'); | ||
var isDate = require('./predicates/date'); | ||
var validators = { | ||
var predicates = { | ||
uri: isUri, | ||
@@ -44,10 +44,10 @@ url: isUrl, | ||
// Build API | ||
Object.getOwnPropertyNames(validators).forEach(function (validatorName) { | ||
var validator = validators[validatorName]; | ||
api[validatorName] = validator; | ||
api.all[validatorName] = function (values, options) { | ||
return validateAll(values, validator, options); | ||
Object.getOwnPropertyNames(predicates).forEach(function (predicateName) { | ||
var predicate = predicates[predicateName]; | ||
api[predicateName] = predicate; | ||
api.all[predicateName] = function (values, options) { | ||
return validateAll(values, predicate, options); | ||
}; | ||
api.optional[validatorName] = function (value, options) { | ||
return validateOptional(value, validator, options); | ||
api.optional[predicateName] = function (value, options) { | ||
return validateOptional(value, predicate, options); | ||
}; | ||
@@ -60,7 +60,7 @@ }); | ||
* @param {Array<*>} values - Values | ||
* @param {function} validator - Validator | ||
* @param {function} predicate - predicate | ||
* @param {object} options - Options | ||
* @returns {Boolean} | ||
*/ | ||
function validateAll(values, validator, options) { | ||
function validateAll(values, predicate, options) { | ||
if (!isArray(values)) { | ||
@@ -71,3 +71,3 @@ return false; | ||
return values.every(function (value) { | ||
return validator(value, options); | ||
return predicate(value, options); | ||
}); | ||
@@ -81,14 +81,14 @@ } | ||
* @param {*} value - Value | ||
* @param {function} validator - Validator | ||
* @param {function} predicate - predicate | ||
* @param {object} options - Options | ||
* @returns {Boolean} | ||
*/ | ||
function validateOptional(value, validator, options) { | ||
if (isExisty(value)) { | ||
function validateOptional(value, predicate, options) { | ||
if (!isExisty(value)) { | ||
return true; | ||
} | ||
return validator(value, options); | ||
return predicate(value, options); | ||
} | ||
module.exports = api; |
{ | ||
"name": "valido", | ||
"version": "2.0.7", | ||
"version": "2.0.9", | ||
"description": "Check and validation library", | ||
@@ -20,3 +20,4 @@ "main": "dist/index.js", | ||
"check", | ||
"validate" | ||
"validate", | ||
"predicate" | ||
], | ||
@@ -34,7 +35,7 @@ "author": "Steffen Strätz", | ||
"chai": "^3.5.0", | ||
"eslint": "^2.12.0", | ||
"eslint": "^2.13.0", | ||
"eslint-config-airbnb": "^9.0.1", | ||
"eslint-plugin-import": "^1.8.1", | ||
"eslint-plugin-jsx-a11y": "^1.4.2", | ||
"eslint-plugin-react": "^5.1.1", | ||
"eslint-plugin-jsx-a11y": "^1.5.3", | ||
"eslint-plugin-react": "^5.2.2", | ||
"lodash": "^4.13.1", | ||
@@ -41,0 +42,0 @@ "mocha": "^2.5.3", |
'use strict'; | ||
const isUrl = require('./validators/url'); | ||
const isUri = require('./validators/uri'); | ||
const isWebUrl = require('./validators/webUrl'); | ||
const isHexColor = require('./validators/hexColor'); | ||
const isString = require('./validators/string'); | ||
const isArray = require('./validators/array'); | ||
const isNull = require('./validators/null'); | ||
const isUndefined = require('./validators/undefined'); | ||
const isExisty = require('./validators/existy'); | ||
const isInteger = require('./validators/integer'); | ||
const isFinite = require('./validators/finite'); | ||
const isNatural = require('./validators/natural'); | ||
const isBuffer = require('./validators/buffer'); | ||
const isBoolean = require('./validators/boolean'); | ||
const isFunction = require('./validators/function'); | ||
const isPlainObject = require('./validators/plainObject'); | ||
const isDate = require('./validators/date'); | ||
const isUrl = require('./predicates/url'); | ||
const isUri = require('./predicates/uri'); | ||
const isWebUrl = require('./predicates/webUrl'); | ||
const isHexColor = require('./predicates/hexColor'); | ||
const isString = require('./predicates/string'); | ||
const isArray = require('./predicates/array'); | ||
const isNull = require('./predicates/null'); | ||
const isUndefined = require('./predicates/undefined'); | ||
const isExisty = require('./predicates/existy'); | ||
const isInteger = require('./predicates/integer'); | ||
const isFinite = require('./predicates/finite'); | ||
const isNatural = require('./predicates/natural'); | ||
const isBuffer = require('./predicates/buffer'); | ||
const isBoolean = require('./predicates/boolean'); | ||
const isFunction = require('./predicates/function'); | ||
const isPlainObject = require('./predicates/plainObject'); | ||
const isDate = require('./predicates/date'); | ||
const validators = { | ||
const predicates = { | ||
uri: isUri, | ||
@@ -44,7 +44,7 @@ url: isUrl, | ||
// Build API | ||
Object.getOwnPropertyNames(validators).forEach((validatorName) => { | ||
const validator = validators[validatorName]; | ||
api[validatorName] = validator; | ||
api.all[validatorName] = (values, options) => validateAll(values, validator, options); | ||
api.optional[validatorName] = (value, options) => validateOptional(value, validator, options); | ||
Object.getOwnPropertyNames(predicates).forEach((predicateName) => { | ||
const predicate = predicates[predicateName]; | ||
api[predicateName] = predicate; | ||
api.all[predicateName] = (values, options) => validateAll(values, predicate, options); | ||
api.optional[predicateName] = (value, options) => validateOptional(value, predicate, options); | ||
}); | ||
@@ -56,7 +56,7 @@ | ||
* @param {Array<*>} values - Values | ||
* @param {function} validator - Validator | ||
* @param {function} predicate - predicate | ||
* @param {object} options - Options | ||
* @returns {Boolean} | ||
*/ | ||
function validateAll(values, validator, options) { | ||
function validateAll(values, predicate, options) { | ||
if (!isArray(values)) { | ||
@@ -66,3 +66,3 @@ return false; | ||
return values.every((value) => validator(value, options)); | ||
return values.every(value => predicate(value, options)); | ||
} | ||
@@ -75,14 +75,14 @@ | ||
* @param {*} value - Value | ||
* @param {function} validator - Validator | ||
* @param {function} predicate - predicate | ||
* @param {object} options - Options | ||
* @returns {Boolean} | ||
*/ | ||
function validateOptional(value, validator, options) { | ||
if (isExisty(value)) { | ||
function validateOptional(value, predicate, options) { | ||
if (!isExisty(value)) { | ||
return true; | ||
} | ||
return validator(value, options); | ||
return predicate(value, options); | ||
} | ||
module.exports = api; |
@@ -10,11 +10,11 @@ 'use strict'; | ||
const validatorDir = path.join(__dirname, '../dist/validators'); | ||
const validatorTestsDir = path.join(__dirname, './validators'); | ||
const validatorFiles = fs.readdirSync(validatorDir); | ||
const predicateDir = path.join(__dirname, '../dist/predicates'); | ||
const predicateTestsDir = path.join(__dirname, './predicates'); | ||
const predicateFiles = fs.readdirSync(predicateDir); | ||
validatorFiles.forEach(file => { | ||
const testsPath = path.join(validatorTestsDir, file); | ||
const filePath = path.join(validatorDir, file); | ||
predicateFiles.forEach(file => { | ||
const testsPath = path.join(predicateTestsDir, file); | ||
const filePath = path.join(predicateDir, file); | ||
const fileInfo = path.parse(filePath); | ||
const validatorName = fileInfo.name; | ||
const predicateName = fileInfo.name; | ||
const tests = require(testsPath); // eslint-disable-line global-require | ||
@@ -28,3 +28,3 @@ | ||
describe(`Validators - ${validatorName}`, () => { | ||
describe(`predicates - ${predicateName}`, () => { | ||
it('should have tests (valid samples)', () => { | ||
@@ -39,4 +39,4 @@ return expect(validValues).to.not.be.empty; | ||
it('should validate a value', () => { | ||
tests.forEach((test) => { | ||
return expect(valido[validatorName](test.value, test.options)).to.equal(test.result); | ||
tests.forEach(test => { | ||
return expect(valido[predicateName](test.value, test.options)).to.equal(test.result); | ||
}); | ||
@@ -46,6 +46,9 @@ }); | ||
it('should validate an optional value', () => { | ||
optionalValueTests.forEach((test) => { | ||
expect(valido.optional[validatorName](null, test.options)).to.equal(true); | ||
expect(valido.optional[validatorName](undefined, test.options)).to.equal(true); | ||
expect(valido.optional[validatorName](test.value, test.options)).to.equal(test.result); | ||
optionalValueTests.forEach(test => { | ||
expect(valido.optional[predicateName](null, test.options)).to.equal(true); | ||
expect(valido.optional[predicateName](undefined, test.options)).to.equal(true); | ||
if (test.value !== null && test.value !== undefined) { | ||
expect(valido.optional[predicateName](test.value, test.options)).to.equal(test.result); | ||
} | ||
}); | ||
@@ -55,5 +58,5 @@ }); | ||
it('should validate a list of values', () => { | ||
tests.forEach((test) => { | ||
tests.forEach(test => { | ||
const values = [test.value, test.value]; | ||
return expect(valido.all[validatorName](values, test.options)).to.equal(test.result); | ||
return expect(valido.all[predicateName](values, test.options)).to.equal(test.result); | ||
}); | ||
@@ -63,5 +66,5 @@ }); | ||
it('should validate an empty list to true', () => { | ||
return expect(valido.all[validatorName]([])).to.equal(true); | ||
return expect(valido.all[predicateName]([])).to.equal(true); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53274
1446
1