Validator.js: isNull() throwing deprecation warnings

Created on 22 Feb 2016  路  1Comment  路  Source: validatorjs/validator.js

I am trying to use validator.isNull() with a var that I have tried to instantiate as null, undefined or as new String(null), but none of these cases seem to work with isNull, I am always receiving the same error:

validator deprecated you tried to validate a object but this library (validator.js) validates strings only. Please update your code as this will be an error soon.

How can this be coerced correctly, or should this function be modified or removed in light of the String only validation?

Looking at the source for isNull would suggest a better name name and description would be isEmpty seeing as this is a simple length check.

>All comments

The library validates strings only. Automatic coercion of input to a string was deprecated and then removed in the latest release. Passing anything that isn't a string will now result in an error.

isNull() should have probably been renamed to isEmpty() (or similar) in that release. Previously null and undefined input would have been coerced to an empty string; now all the validator does is check if the input string has a length of zero. I'll update the README so that this is clear.

I only just bumped v4 to v5 so I'm not prepared to make a breaking change to rename it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

IOAyman picture IOAyman  路  4Comments

mfbx9da4 picture mfbx9da4  路  4Comments

spyshower picture spyshower  路  3Comments

frontendmonster picture frontendmonster  路  4Comments

philfreo picture philfreo  路  3Comments