New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

js-validate

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-validate - npm Package Compare versions

Comparing version 0.3.1 to 0.4.0

tasks/package.js

2

bower.json
{
"name": "js-validate",
"version": "0.3.1",
"version": "0.4.0",
"homepage": "https://github.com/kshunz/js-validate",

@@ -5,0 +5,0 @@ "authors": [

@@ -1,58 +0,20 @@

var browserify = require('gulp-browserify');
var chai = require('chai');
var gulp = require('gulp');
var minify = require('gulp-uglify');
var mocha = require('gulp-mocha');
var rename = require('gulp-rename');
var bump = require('gulp-bump');
global.gulp = require('gulp');
global.gutil = require('gulp-util');
global.log = global.gutil.log;
global.c = global.gutil.colors;
gulp.task('package', function() {
return gulp.src('./src/validate.js')
.pipe(browserify())
.pipe(rename('js-validate.js'))
.pipe(gulp.dest('./dist'));
});
var taskListing = require('gulp-task-listing');
var fs = require('fs');
var files = fs.readdirSync('./tasks');
gulp.task('package-min', ['package'], function() {
return gulp.src('./dist/js-validate.js')
.pipe(minify({}))
.pipe(rename('js-validate.min.js'))
.pipe(gulp.dest('./dist'));
});
files.forEach(function (file) {
var isJs = (file.split('.js').length > 1);
gulp.task('test', function() {
global.expect = chai.expect;
global.RULES = require('./src/defaults/rules');
return gulp.src(['!./tests/**/*_xtest*', './tests/**/*_test*.js'])
.pipe(mocha());
if(file !== 'plugins' && isJs) {
require('./tasks' + '/' + file);
}
});
gulp.task('test-watch', function() {
gulp.watch([
'!./tests/**/*_xtest*',
'./tests/**/*_test*.js',
'./src/**/*.js'
], ['test']);
});
gulp.task('help', taskListing);
gulp.task('patch', function() {
return gulp.src(['./bower.json', './package.json'])
.pipe(bump())
.pipe(gulp.dest('./'));
});
gulp.task('minor', function() {
return gulp.src(['./bower.json', './package.json'])
.pipe(bump({ type: 'minor' }))
.pipe(gulp.dest('./'));
});
gulp.task('major', function() {
return gulp.src(['./bower.json', './package.json'])
.pipe(bump({ type: 'major' }))
.pipe(gulp.dest('./'));
});
gulp.task('default', ['test', 'package-min']);
gulp.task('default', ['help']);
{
"name": "js-validate",
"version": "0.3.1",
"version": "0.4.0",
"description": "Functional, extensible, input validation. Make sure the value you receive is EXACTLY what you expect.",
"main": "src/validate.js",
"scripts": {
"start": "npm install && ./node_modules/.bin/gulp",
"test": "./node_modules/.bin/gulp test"
"start": "npm install && ./node_modules/.bin/gulp test && ./node_modules/.bin/gulp package-min",
"test": "snyk test && ./node_modules/.bin/gulp test"
},

@@ -29,13 +29,17 @@ "repository": {

"bower": "^1.6.5",
"chai": "^3.4.0",
"gulp": "^3.9.0",
"chai": "^3.5.0",
"gulp": "^3.9.1",
"gulp-browserify": "^0.5.1",
"gulp-bump": "^1.0.0",
"gulp-mocha": "^2.1.3",
"gulp-bump": "^2.1.0",
"gulp-mocha": "^2.2.0",
"gulp-rename": "^1.2.2",
"gulp-uglify": "^1.4.2"
"gulp-task-listing": "^1.0.1",
"gulp-uglify": "^1.4.2",
"gulp-util": "^3.0.7",
"sinon": "^1.17.3"
},
"dependencies": {
"lodash": "^4.5.1"
"lodash": "^4.7.0",
"snyk": "^1.13.2"
}
}

@@ -1,76 +0,32 @@

<h2>js-validate</h2>
<i>Functional, extensible, input validation. Make sure the value you receive is EXACTLY what you expect.</i>
# js-validate #
<h1>Getting Started</h1>
### Functional, extensible, input validation. Make sure the value you receive is EXACTLY what you expect. ###
Getting Started
<h4>Installation</h4>
npm install js-validate
```
npm install js-validate
```
<h4>Quick Use</h4>
```node
```
var validator = require('js-validate');
```
```
var validate = validator.start();
validate(123, 'min-length 2');
```
<h5>Validate against a single rule:</h5>
<h4>Validators</h4>
- Alpha
- Capital
- EndsWith
- Min-Length
- Number (isNumber)
- Numbers (Number Characters)
- Specials (Special Characters)
- StartsWith
validate('123', 'min-length 2'); //--> true
<h5>Validate against multiple rules:</h5>
validate('123', ['min-length 2', 'number']); //-->true
<h4>Built-in Rules</h4>
- alpha
- alphanumeric
- boolean **NEW**
- capitals (counts capital characters)
- ends-with
- equals
- length
- max
- max-length
- min
- min-length
- number (isNumber) ***Altered Rule***
- numbers (Number Characters)
- numeric (consists of numerical digits) **NEW**
- specials (Special Characters)
- starts-with
<h5>Create a validator (rule) group:</h5>
validator.group({
'account-number': [
'alphanumeric',
'min-length 7',
'starts-with 000-',
'ends-with -00'
]
});
<h5>Validate against a group of rules:</h5>
validate('000-KLJ8989123-00', 'account-number'); //--> true
<h5>Create a custom rule:</h5>
validator.rules({
isOkay: function(input) {
return input === 'ok';
}
});
<h5>Keep this in mind when creating custom rules:</h5>
- Validator rules must return a pure boolean (true | false)
- The first parameter must be the user input
- Unlimited additional parameters are supported
- Custom rules are added to the default rule list
- Custom rules may be used in conjunction with defaults in rule groups

@@ -17,11 +17,2 @@ module.exports = function () {

},
'boolean': function(input) {
var pureBoolean = typeof input === 'boolean';
if(!pureBoolean) {
input = String(input).toLowerCase();
}
return pureBoolean || input === 'true' || input === 'false';
},
'capitals': function (input, count) {

@@ -34,3 +25,3 @@ count = Number(count);

'endsWith': function(input, char) {
return _.endsWith(input, char);
return _.endsWith(input, char);
},

@@ -59,13 +50,10 @@ 'equals': function (input, value) {

extraChars.forEach(function(char) {
if(String(char).toLowerCase() === 'space') {
char = ' ';
}
if(String(char).toLowerCase() === 'space') {
char = ' ';
}
input = input.split(char).join('');
input = input.split(char).join('');
});
var decimals = String(input).split('.')[1];
var numDecimals = decimals ? decimals.length : 0;
return String(input) === String(Number(input).toFixed(numDecimals));
return String(input) === String(Number(input));
},

@@ -78,11 +66,2 @@ 'numbers': function (input, count) {

},
'numeric': function(input) {
var inputAsString = String(input);
var numbers = inputAsString.split('');
return !numbers.some(function(num) {
num = num === '.' ? 0 : Number(num);
return num * 1 !== Number(num);
});
},
'specials': function (input, count) {

@@ -99,2 +78,2 @@ count = Number(count);

}();
}();

@@ -63,3 +63,3 @@ module.exports = function Validate() {

//auto-fail the rule if the rule isn't set
result = validator ? validator.apply(null, validatorInput) === false : true;
result = validator ? validator.apply(this, validatorInput) === false : true;

@@ -75,2 +75,1 @@ return flipRule ? !result : result;

}();
describe('Number rule validator', function() {
var number = RULES.number;
it('should accept whole numbers', function() {
expect(number(123)).to.be.true;
});
it('should accept integers', function() {
expect(number('123.0')).to.be.true;
expect(number('123.023')).to.be.true;
expect(number('123.023.55')).to.be.false;
});
it('should accept whole numbers', function() {});
it('should accept integers', function() {});
it('should reject numbers that begin with zero', function() {
expect(number('0123')).to.be.false;
});
});
});
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