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

iz

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

iz - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

5

package.json
{
"name": "iz",
"version": "0.3.0",
"version": "0.4.0",
"description": "Validation for node and the web.",
"main": "app.js",
"url" : "https://github.com/parris/iz/issues",
"homepage": "https://github.com/parris/iz",

@@ -22,3 +23,3 @@ "keywords": [

"grunt-shell": "~0.2.2",
"grunt-simple-mocha": "~0.3.2",
"grunt-simple-mocha": "git://github.com/yaymukund/grunt-simple-mocha.git#a4946466e9ce5504ecbda4d8419ff28ab74585ff",
"requirejs": "2.1.6",

@@ -25,0 +26,0 @@ "grunt-cli": "~0.1.9"

14

README.md

@@ -107,3 +107,3 @@ [![Build Status](https://secure.travis-ci.org/parris/iz.png)](http://travis-ci.org/parris/iz)

int: 'Must be an whole number',
between: 'This wine is too young, it's no good'
between: 'This wine is too young, it\'s no good'
},

@@ -131,2 +131,13 @@ rules = {

It is often useful to get back error messages from an Are object. Regardless of
how you create your Are object (JSON or Iz objects) the result is a set of Iz
objects stored within `.fields`. Iz objects contain an attribute called `errors`.
The `.getInvalidFields` helper will retrieve all iz objects with errors.
var rules = Are(...);
if (!rules.validFor(someAttributeObject)) {
return rules.getInvalidFields();
}
Required Fields:

@@ -172,2 +183,3 @@ ----

iz.ssn(*); // Is a social security number
iz.string(*); // Is the argument of type string

@@ -174,0 +186,0 @@ Almost all possible use cases that will definitely work (and definitely not work) are in the spec folder.

@@ -94,2 +94,12 @@ /*global describe, it, xit, xdescribe, before, require */

it('returns error messages', function() {
var myAre = are(this.rules),
errorFields;
myAre.validFor(this.invalidObject);
errorFields = myAre.getInvalidFields();
errorFields['producer.id'].length.should.be.ok;
});
describe('with required fields', function() {

@@ -96,0 +106,0 @@

@@ -24,2 +24,29 @@ /*global describe, it, xit, xdescribe, before, require */

it('can validate string values', function () {
iz.string('').should.be.ok;
iz.string('a2d1kf0v9r9fje9fdgnsdksdf9240uyjsdfgkj').should.be.ok;
iz.string('aaaaaaa').should.be.ok;
iz.string('999999').should.be.ok;
iz.string('_3423423').should.be.ok;
iz.string('342 3423').should.be.ok;
iz.string('alals*fd').should.be.ok;
iz.string(new String('')).should.be.ok;
iz.string(new String('239084203')).should.be.ok;
iz.string(new String('alals*fd')).should.be.ok;
iz.string(9999999).should.not.be.ok;
iz.string({}).should.not.be.ok;
iz.string([]).should.not.be.ok;
iz.string(function () {}).should.not.be.ok;
iz.string(/[ \-]/g).should.not.be.ok;
iz.string(new Date()).should.not.be.ok;
function Car() {}
iz.string(new Car()).should.not.be.ok;
iz.string(null).should.be.ok;
iz.string(undefined).should.be.ok;
});
it('can validate that a primitive is between 2 other primitives', function () {

@@ -26,0 +53,0 @@ iz.between(5, 5, 6).should.be.ok;

@@ -16,3 +16,3 @@ /*global module, exports */

self._fields = {};
self.fields = {};

@@ -26,3 +26,3 @@ for (key in rules) {

if (typeof rules[key].revalidate !== 'undefined') {
self._fields[key] = rules[key];
self.fields[key] = rules[key];
} else {

@@ -61,3 +61,3 @@ errors = {};

self._fields[key] = currentRule;
self.fields[key] = currentRule;
}

@@ -67,9 +67,9 @@ }

this.valid = function() {
for (var key in self._fields) {
if (!self._fields[key].hasOwnProperty(key)) {
for (var key in self.fields) {
if (!self.fields[key].hasOwnProperty(key)) {
continue;
}
self._fields[key].revalidate();
if (!self._fields[key].valid) {
self.fields[key].revalidate();
if (!self.fields[key].valid) {
return false;

@@ -88,4 +88,4 @@ }

for (field in self._fields) {
if (!self._fields.hasOwnProperty(field)) {
for (field in self.fields) {
if (!self.fields.hasOwnProperty(field)) {
continue;

@@ -102,5 +102,5 @@ }

self._fields[field].setValue(currentValue);
self.fields[field].setValue(currentValue);
if (!self._fields[field].valid) {
if (!self.fields[field].valid) {
return false;

@@ -112,2 +112,15 @@ }

};
this.getInvalidFields = function() {
var errorFields = {},
key;
for (key in self.fields) {
if(self.fields[key].errors && self.fields[key].errors.length) {
errorFields[key] = self.fields[key].errors;
}
}
return errorFields;
};
}

@@ -114,0 +127,0 @@

@@ -11,2 +11,6 @@ /*global module, exports */

function izString(value) {
return typeof value === 'string' || value instanceof String;
}
function izNumber(val) {

@@ -363,2 +367,3 @@ if ((typeof val === 'string' || typeof val === 'number') && !isNaN(val % 1)) {

validators.alphaNumeric = izRequiredOr(izAlphaNumeric);
validators.string = izRequiredOr(izString);
validators.between = izRequiredOr(izBetween);

@@ -365,0 +370,0 @@ validators.blank = izRequiredOr(izBlank);

Sorry, the diff of this file is not supported yet

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