Comparing version 0.6.0 to 0.7.0
29
core.js
@@ -240,8 +240,8 @@ // Checkit.js 0.6.0 | ||
} | ||
else if (Checkit.Regex[rule]) { | ||
result = Checkit.Regex[rule].test(params[0]); | ||
} | ||
else if (typeof _['is' + capitalize(rule)] === 'function') { | ||
result = _['is' + capitalize(rule)].apply(_, params); | ||
} | ||
else if (Checkit.Regex[rule]) { | ||
result = Checkit.Regex[rule].test(params[0]); | ||
} | ||
else { | ||
@@ -301,3 +301,3 @@ throw new ValidationError('No validation defined for ' + rule); | ||
accepted: function(val) { | ||
return _.contains(this._language.accepted, val); | ||
return _.includes(this._language.accepted, val); | ||
}, | ||
@@ -383,2 +383,7 @@ | ||
// Check if the value is a string | ||
string: function(val) { | ||
return (typeof val === 'string'); | ||
}, | ||
// Check if the value is numeric | ||
@@ -412,3 +417,3 @@ numeric: numeric | ||
base64: /^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/, | ||
email: /^[a-z0-9._%+\-]+@[a-z0-9.\-]+\.[a-z]{2,63}$/i, | ||
email: /^(.+)@(.+)\.(.+)$/i, | ||
integer: /^\-?[0-9]+$/, | ||
@@ -456,3 +461,3 @@ ipv4: /^((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})$/i, | ||
return this.key + ': ' + | ||
_.pluck(errors, 'message').join(', '); | ||
_.map(errors, 'message').join(', '); | ||
}, | ||
@@ -479,3 +484,3 @@ | ||
CheckitError.prototype = new Error; | ||
CheckitError.prototype = new Error(); | ||
@@ -491,3 +496,3 @@ _.extend(CheckitError.prototype, { | ||
toString: function(flat) { | ||
return 'Checkit Errors - ' + this.invoke('toString', flat).join('; '); | ||
return 'Checkit Errors - ' + this.invokeMap('toString', flat).join('; '); | ||
}, | ||
@@ -508,6 +513,6 @@ | ||
// methods that make sense to act on `CheckitError.errors` or `FieldError.errors`. | ||
var objMethods = ['keys', 'values', 'pairs', 'invert', 'pick', 'omit']; | ||
var arrMethods = ['first', 'initial', 'rest', 'last']; | ||
var objMethods = ['keys', 'values', 'toPairs', 'invert', 'pick', 'omit']; | ||
var arrMethods = ['head', 'initial', 'tail', 'last']; | ||
var shareMethods = ['forEach', 'each', 'map', 'reduce', 'transform', 'reduceRight', | ||
'find', 'filter', 'reject', 'invoke', 'toArray', 'size', 'shuffle']; | ||
'find', 'filter', 'reject', 'invokeMap', 'toArray', 'size', 'shuffle']; | ||
@@ -562,3 +567,3 @@ _.each(shareMethods.concat(objMethods), function(method) { | ||
if (_.isEmpty(validation.params)) { | ||
validation.params = _.rest(splitRule); | ||
validation.params = _.tail(splitRule); | ||
} | ||
@@ -565,0 +570,0 @@ } else if (!_.isFunction(validation.rule)) { |
@@ -24,2 +24,3 @@ module.exports = { | ||
contains: 'The {{label}} must contain {{var_1}}', | ||
string: 'The {{label}} must be type "string"', | ||
numeric: 'The {{label}} must be a numeric value', | ||
@@ -50,2 +51,3 @@ matchesField: 'The {{label}} must exactly match the {{var_1}}', | ||
naturalNonZero: 'The {{label}} must be a number greater than zero', | ||
integer: 'The {{label}} must be a valid integer', | ||
ipv4: 'The {{label}} must be a valid IPv4 string', | ||
@@ -52,0 +54,0 @@ ipv6: 'The {{label}} must be a valid IPv6 address', |
@@ -18,2 +18,3 @@ module.exports = { | ||
greaterThanEqualTo: '{{label}} debe de ser un número mayor o igual a {{var_1}}', | ||
string: '{{label}} debe de ser de tipo "string"', | ||
numeric: '{{label}} debe de ser un valor numérico', | ||
@@ -20,0 +21,0 @@ matchesField: '{{label}} debe de ser exactamente igual a {{var_1}}', |
@@ -24,2 +24,3 @@ module.exports = { | ||
contains: 'Le champ {{label}} doit contenir {{var_1}}', | ||
string: 'Le champ {{label}} doit être de type "string"', | ||
numeric: 'Le champ {{label}} doit être une valeur numérique', | ||
@@ -50,2 +51,3 @@ matchesField: 'Le champ {{label}} doit doit correspondre exactement à {{var_1}}', | ||
naturalNonZero: 'Le champ {{label}} doit être un nombre supérieur à zéro', | ||
integer: 'Le champ {{label}} doit être un entier', | ||
ipv4: 'Le champ {{label}} doit être une chaîne IPv4 valide', | ||
@@ -52,0 +54,0 @@ ipv6: 'Le champ {{label}} doit être une adresse IPv6 valide', |
@@ -24,2 +24,3 @@ module.exports = { | ||
contains: '{{label}} должно содержать {{var_1}}', | ||
string: '{{label}} должно быть "string"', | ||
numeric: '{{label}} должно быть числом', | ||
@@ -26,0 +27,0 @@ matchesField: '{{label}} должно точно совпадать с {{var_1}}', |
{ | ||
"name": "checkit", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "Simple validations for node and the browser.", | ||
"main": "server.js", | ||
"browser": "browser.js", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "mocha -R spec test/index.js", | ||
"prepublish": "npm test && npm run build", | ||
"build": "npm run build:main && npm run build:dist", | ||
"build:main": "webpack --output-library Checkit --output-library-target umd browser.js dist/checkit.js", | ||
"build:dist": "webpack --output-library Checkit --output-library-target umd --optimize-minimize browser.js dist/checkit.min.js" | ||
"build:main": "webpack --output-library Checkit --output-library-target umd index.js dist/checkit.js", | ||
"build:dist": "webpack --output-library Checkit --output-library-target umd --optimize-minimize index.js dist/checkit.min.js" | ||
}, | ||
@@ -17,10 +17,9 @@ "directories": { | ||
"dependencies": { | ||
"bluebird": "^2.9.14", | ||
"inherits": "^2.0.1", | ||
"lodash": "^2.4.0 || ^3.0.0", | ||
"when": "^3.0.0" | ||
"lodash": "^4.0.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "~1.15.0", | ||
"node-uuid": "~1.4.1" | ||
"mocha": "~2.4.5", | ||
"node-uuid": "~1.4.1", | ||
"webpack": "1.12.13" | ||
}, | ||
@@ -27,0 +26,0 @@ "repository": { |
@@ -19,3 +19,3 @@ # Checkit.js | ||
$("#errors").html(err.map(function(val, key) { | ||
return '<li>' key + ': ' + val.first().message + '</li>'; | ||
return '<li>' + key + ': ' + val.first().message + '</li>'; | ||
}).join('')); | ||
@@ -307,2 +307,6 @@ }); | ||
<tr> | ||
<td>string</td> | ||
<td>The value must be a string type.</td> | ||
</tr> | ||
<tr> | ||
<td>url</td> | ||
@@ -410,3 +414,3 @@ <td>The value must be formatted as an URL.</td> | ||
Checkit.Validator.prototype.unused = function(val, table, column) { | ||
return knex(table).where(column, '=', val).then(function(resp) { | ||
return knex(table).where(column, '=', val).andWhere('id', '<>', this._target.id).then(function(resp) { | ||
if (resp.length > 0) { | ||
@@ -507,2 +511,11 @@ throw new Error('The ' + table + '.' + column + ' field is already in use.'); | ||
### 0.7.0 | ||
- Expect a global `Promise` instance. **Breaking change** #69 | ||
- Add meaningful message for integer validation. #46 | ||
- Add string validation. #58 | ||
- Compatible with Lodash 4.x only. #55 | ||
- More permissive email regex. #61, #68 | ||
- Only bundle required lodash methods. #69 | ||
### 0.6.0 | ||
@@ -509,0 +522,0 @@ |
@@ -1,4 +0,3 @@ | ||
global.Promise = require('bluebird'); | ||
global._ = require('lodash'); | ||
global.Checkit = require('../server'); | ||
global.Checkit = require('../index'); | ||
@@ -5,0 +4,0 @@ global.assert = require('assert'); |
@@ -111,2 +111,10 @@ describe('Checkit', function() { | ||
describe('string', function() { | ||
it('should pass for strings', function() { | ||
return Checkit({ | ||
isString: 'string' | ||
}).run(testBlock); | ||
}); | ||
}); | ||
describe('integer', function() { | ||
@@ -336,3 +344,3 @@ it('should pass for numbers and strings (positive and negative)', function() { | ||
describe('custom validation rules', function() { | ||
it('should run the rule function on the supplied value', function() { | ||
@@ -349,3 +357,3 @@ var value = 'value'; | ||
}) | ||
it('should fail when the validation rule throws an error', function(){ | ||
@@ -363,3 +371,3 @@ var rulesTest = { | ||
}) | ||
it('should pass the supplied parameter to the validation rule', function(){ | ||
@@ -377,3 +385,3 @@ var parameter = 'parameter'; | ||
}) | ||
it('should pass the context property supplied to the run function to the rule function', function(){ | ||
@@ -390,3 +398,3 @@ var runContext = 'the context'; | ||
}) | ||
}); | ||
@@ -393,0 +401,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
2
542
9
10
641660
3
32
7104
+ Addedlodash@4.17.21(transitive)
- Removedbluebird@^2.9.14
- Removedwhen@^3.0.0
- Removedbluebird@2.11.0(transitive)
- Removedlodash@3.10.1(transitive)
- Removedwhen@3.7.8(transitive)
Updatedlodash@^4.0.0