Git Product home page Git Product logo

iz's People

Contributors

christophermeek avatar dependabot[bot] avatar gleenn avatar jschill avatar justinrknowles avatar nickclaw avatar parris avatar pkyeck avatar thedumbterminal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

iz's Issues

yarn installation broken (invalid tar file)

Hi! I get the following error while installing package via yarn (yarn add iz):

error An unexpected error occurred: "https://registry.yarnpkg.com/iz/-/iz-2.1.2.tgz: invalid tar file".

Tested on clean project (yarn init, yarn add iz). As the yarn issue says (yarnpkg/yarn#1619):

Reporting as of May 14, 2017, that yarn publish seems to be borking things. npm publish works though

So, looks like the solution is to bump the version and to republish iz with npm.

required rule doesn't work

const rules = {
  name: [
    {
      rule: 'required',
      error: 'You must specify a name'
    }
  ]
}

are(rules).for({ name: '' }).valid // true

iz('foo').ip().valid; // Returns true

The ip validators seems to accept any string of letters:

iz('foo').ip().valid; // Retuns true
iz('asdf').ip().valid; // Retuns true
iz('qwertyuiop').ip().valid; // Retuns true

I found the regex iz.ip() was using and it does accept all those strings. The IPv4 part of the regex works correctly, so I assume there is an issue in the (long) IPv6 regex.

/(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])/.test('foo'); // Returns false
/(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])/.test('0.0.0.0'); // Returns true

betweenLength validation

Thought it would be useful to have a betweenLength validation so that you don't have to use both the minLength and maxLength validations.

Something like:

iz.betweenLength(val, min, max);           // val (str or arr) is greater than or equal to min and shorter than or equal to max

Happy to do a pull request if you'd accept the idea.

Thanks!

Add "Present" Validator

Sometimes it's useful to be able to validate presence of a value separately to validating it's format. We are using this to support validation of mandatory fields.

Suggested syntax...

iz(value).present()

Date validation doesn't work

var rules = {
  "myDate": [
    {
      "rule": "blank",
      "error": "Additional insured cannot be blank"
    },
    {
      "rule": "date",
      "error": "Additional insured must be valid date"
    },
  ],
};

const result = are(rules).for({
  myDate: "09/23/2012"
});

this throws an exception

/home/aleksandar/Code/theguarantors.com/node_modules/iz/lib/utils/nameOfClass.js:6
  if (obj.constructor && obj.constructor.displayName) {
         ^
TypeError: Cannot read property 'constructor' of undefined
    at izGetObjectClass (/home/aleksandar/Code/theguarantors.com/node_modules/iz/lib/utils/nam
eOfClass.js:6:10)                                        

param to izDate is undefined.

Apologies if I misunderstood something, but didn't have issues with other validators.

are(rules).validFor() doesn't revalidate all fields

For example:

    var rules = {
          'address.city': [
            {
              'rule': 'required',
              'error': 'You must specify a city'
            },
            {
              'rule': 'minLength',
              'args': [5],
              'error': 'The city name length must be more than 5'
            }
          ],
          'address.street': [
            {
              'rule': 'required',
              'error': 'You must specify a street'
            },
            {
              'rule': 'minLength',
              'args': [5],
              'error': 'The street name length must be more than 5'
            }
          ]
        };

        var are = require('iz').are;
        var validationObject = are(rules);

        validationObject.validFor(
          {
            address: {
              city: 'Test',
              street: "Street test name"
            }
          }
        );
        var invalidFields = validationObject.getInvalidFields();
        console.log(invalidFields);

Console log:

invalidFields
{ 
    'address.city': [ 'The city name length must be more than 5' ],
    'address.street': [ 'The street name length must be more than 5' ] 
}

I expect method getInvalidFields will return only one incorrect field (city)

Async validators

Thinking of returning a promise from the provided callback argument provided to addValidator. For instance, a unique validator for usernames..

iz.email(null) === true

iz.email(null) === true

This caused a really weird error in my application. I don't think it's desired behavior.

how to access custom error messages with ARE

I'm trying to use the are syntax with a ruleset. looks good so far but how can I access the error message?

var iz = require("iz");

var test = {
  description: "",
  value: 2343
};

var rules = {
  description: [
    {
      "rule": "required",
      "error": "You must specify a description"
    }
  ],
  value: [
    {
      "rule": "required",
      "error": "value is missing"
    },
    {
      "rule": "number",
      "error": "value must be a number"
    },
    {
      "rule": "between",
      "args": [0, 1000000],
      "error": "value must be between 0 and 1000000"
    },
  ]
};

console.log(iz.are(rules).validFor(test));  // false

how validate a field in array ?

var rules = {
    code: [{
        'rule': 'required',
        'error': 'is not be empty'
    }],
//    params: {
//        fieldcode: [{
//            'rule': 'required',
//            'error': 'is not be empty'
//        }]
//    }
};

var date = {code: "fff", params: [{fieldcode: "fff"}]}

how validate a field in array ? i want validate date.params[x].fieldcode ?waht should i do

IE support

Trying to run this with IE11, i think it fails on some ES proxy issue (im using https://github.com/GoogleChrome/proxy-polyfill).

Problem code:
https://github.com/parris/iz/blob/v2.2.2/src/are.js#L81

How that line looks compiled:
currentIz = (_currentIz = currentIz)[rule.rule].apply(_currentIz, _toConsumableArray(args));

Error message:

Unhandled promise rejection TypeError: Unable to get property 'apply' of undefined or null reference

So, currentIz[rule.rule] is undefined.

Would you recommend another proxy polyfill?

izEqual throws if value is null

When using izEqual on a null value, valueType is set to 'object' and then when doing the check on value.equals it throws:

Uncaught TypeError: Cannot read property 'equals' of null

[feature request] adding support for some simple schema validation

what i got in mind is something like using your group validation logic:

// My rules, I can look at the keys and inspect the errors
rules = {
    cost: iz(costErrors).decimal(),
    age: iz(ageErrors).int().between(17, 10000),
    producer: {
        id: iz(producerErrors).int()
    }
};

are(rules).validFor({
   cost: 100,
   age: 18,
   producer: {
       id: 1001
   }
});

Comparison between iz/chai/validator

I'm currently comparing some of the most popular validation libraries, specifically chai and validator, but also came across iz on SO. From what I can tell, chai/validator seems to cover all of the examples in the README, and a bunch of additional ones too. Could you explain what makes iz a better choice than these two libraries? Have I missed something? Thank you

are(rules).for(dataObject) ignored the fact that field is not required

Are seems to ignore the fact that field should be ignored if it doesn't have a required validator.

const name = [
    {
        rule: 'string',
        error: 'Name must be a string'
    },
    {
        rule: 'required',
        error: 'Name cannot be empty.'
    },
]
const promoCode = [
    {
        rule: 'string',
        error: 'Promo code must be a string.'
    },
    {
        rule: 'minLength',
        args: [4],
        error: 'Promo Code must be at least 4 characters long.'
    },
    {
        rule: 'maxLength',
        args: [12],
        error: 'Promo Code can be at most 12 characters.'
    },
    {
        rule: 'notMatch',
        args: [REGEX_INVALID_PROMO],
        error: 'Promo code contains invalid characters.'
    }
]

const rules = {name, promoCode}
are(rules).for({ name: 'PACK1' }).valid // false

Returns valid = false with the following errors even though promoCode is not required.

"promoCode": [
      "Promo code must be a string.",
      "Promo Code must be at least 4 characters long.",
      "Promo Code can be at most 12 characters."
    ]

Validate a field against another

Validating a field against another one (say a start date before an end date) is tricky.
One can pass the entire model as the args argument, but it's not easy to understand.

It will be very helpful if the validators could be called with two parameters:

  • the first will be the value, like now
  • the last will be the object in validation

If there is args, they are still passed after the value. Something like:

validators.validate = function(value, args*, values) {..}

Multiple doesn't handle floats correctly

e.g.

const iz = require('iz')
const validators = require('iz/lib/validators')

iz.register(validators)

console.log(iz(2.3).multiple(0.01).valid)

logs false instead of true.

This is because 2.3 % 0.01 is 0.009999999999999775 in JavaScript ๐Ÿคฆโ€โ™‚๏ธ

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.