Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

2valid

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

2valid - npm Package Compare versions

Comparing version 2.3.2 to 2.4.1

8

CHANGELOG.md

@@ -8,2 +8,10 @@ # 2valid changelog

- add ```any``` validator type
## [2.3.1](http://github.com/ivanoff/2valid/tree/2.3.1) (2017-02-22)
[Full Changelog](http://github.com/ivanoff/2valid/compare/2.2.4...2.3.1)
**What Was Done:**
- add more examples

@@ -10,0 +18,0 @@ - add getRandomExample function

12

index.js
/*!
* validate-me
* 2valid
* Copyright(c) 2015-2017 ivanoff .$ curl -A cv ivanoff.org.ua

@@ -54,3 +54,3 @@ * MIT Licensed

// Register new model. Return validate-me object
// Register new model. Return 2valid object
// Parameters: modelName - name of the model, modelObject - model object

@@ -98,3 +98,2 @@ exports.registerModel = function (modelName, modelObject) {

function validateObjectRequired(options, modelObject, entity, parents, errors) {
if (!options) options = {};
for (var key in modelObject) {

@@ -145,6 +144,4 @@ if (!modelObject[key].type) {

exports.validate = function (modelName, entity, options, next) {
if (typeof options === 'function') {
next = options;
options = {};
}
if (typeof options === 'function') next = options;
if (!options) options = {};

@@ -156,2 +153,3 @@ var modelObject = this.registeredModels[modelName];

} else if (this.types[modelName]) {
if (options.one) this.types[modelName].one = options.one;
var result = this.types[modelName].check(entity) ? null : { notMatched: modelName };

@@ -158,0 +156,0 @@ return typeof next === 'function' ? next(result) : result;

{
"name": "2valid",
"version": "2.3.2",
"version": "2.4.1",
"description": "JavaScript simple data validator",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -15,3 +15,3 @@

v2.3.2
v2.4.1

@@ -29,4 +29,4 @@

var v = require('2valid');
console.log( v.validate('integer', 111) ); //null
console.log( v.validate('integer', 'aaa') ); // { notMatched: 'integer' }
console.log( v.validate('integer', 111) ); //null
console.log( v.validate('integer', 'aaa') ); // { notMatched: 'integer' }
```

@@ -40,3 +40,3 @@

var v = require('2valid');
console.log( v.validate('password', 'As1eRR') ); // { notMatched: 'password' }
console.log( v.validate('password', 'As1eRR') ); // { notMatched: 'password' }
console.log( v.validate('password', '!A1e') ); // null

@@ -68,2 +68,3 @@ ```

| uuid | UUID string |
| any | any of elements of array |

@@ -238,2 +239,14 @@

### Any validator
Only 'cyan', 'magenta', 'yellow' or 'key' can passed in ```cmyk``` model to validate
```javascript
var v = require('2valid');
console.log(v.validate('any', 'yellow', {one: ['cyan', 'magenta', 'yellow', 'key']})); //passed
console.log(v.validate('any', 123, {one: ['cyan', 'magenta', 'yellow', 'key']})); //{ notMatched: 'any' }
```
### Required keys validator

@@ -240,0 +253,0 @@

@@ -29,3 +29,4 @@ 'use strict';

example.should.be.instanceof(Array);
this.vm.validate(types[i], example[0], function (err) {
var opt = (types[i] !== 'any')? {} : {one:['Male','Female']};
this.vm.validate(types[i], example[0], opt, function (err) {
(err === null).should.be.true;

@@ -42,3 +43,4 @@ });

var example = this.vm.getExample(types[i]);
this.vm.validate(types[i], example, function (err) {
var opt = (types[i] !== 'any')? {} : {one:['Male','Female']};
this.vm.validate(types[i], example, opt, function (err) {
(err === null).should.be.true;

@@ -55,3 +57,4 @@ });

var example = this.vm.getRandomExample(types[i]);
this.vm.validate(types[i], example, function (err) {
var opt = (types[i] !== 'any')? {} : {one:['Male','Female']};
this.vm.validate(types[i], example, opt, function (err) {
(err === null).should.be.true;

@@ -58,0 +61,0 @@ });

@@ -113,2 +113,11 @@ /**** List of types to validate ****/

any: {
check: function (element) {
var hasOne = typeof this.one === 'object' && Array.isArray(this.one) && this.one[0];
return hasOne && this.one.indexOf(element) >= 0;
},
examples: ['Male', 'Female'],
},
object: {

@@ -115,0 +124,0 @@ check: function () { return 1; },

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