Skip to content

Commit

Permalink
Print a deprecation warning if input is not a string, cc #486
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Feb 4, 2016
1 parent 5302518 commit 1f67e1e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@
};

validator.toString = function (input) {
// The library validates strings only. Currently it coerces all input to a string, but this
// will go away in an upcoming major version change. Print a deprecation notice for now
if (typeof input !== 'string' && typeof console === 'object' && console
&& typeof console.warn === 'function') {
console.warn('warning: you tried to validate a ' + typeof input + ' but this library ' +
'(github.com/chriso/validator.js) validates strings only. Please update your code ' +
'as this will be an error soon.')
}
if (typeof input === 'object' && input !== null) {
if (typeof input.toString === 'function') {
input = input.toString();
Expand Down

0 comments on commit 1f67e1e

Please sign in to comment.