From 1f67e1e15198c0ae735151290dc8dc2bf14da254 Mon Sep 17 00:00:00 2001 From: Chris O'Hara Date: Thu, 4 Feb 2016 11:19:43 +0900 Subject: [PATCH] Print a deprecation warning if input is not a string, cc #486 --- validator.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/validator.js b/validator.js index d30686157..98bf256f0 100644 --- a/validator.js +++ b/validator.js @@ -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();