Skip to content

Commit

Permalink
Fix server-side detection, closes #494
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Feb 10, 2016
1 parent 05b5b8c commit 06e2080
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
([#489](https://github.com/chriso/validator.js/pull/489))
- Reject IPv4 addresses with invalid zero padding
([#490](https://github.com/chriso/validator.js/pull/490))
- Fix the client-side version when used with RequireJS
([#494](https://github.com/chriso/validator.js/issues/494))

#### 4.7.1

Expand Down
12 changes: 10 additions & 2 deletions validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,25 @@
validator.init = function () {
for (var name in validator) {
if (typeof validator[name] !== 'function' || name === 'toString' ||
name === 'toDate' || name === 'extend' || name === 'init') {
name === 'toDate' || name === 'extend' || name === 'init' ||
name === 'isServerSide') {
continue;
}
validator.extend(name, validator[name]);
}
};

validator.isServerSide = function () {
return typeof module === 'object' && module &&
typeof module.exports === 'object' &&
typeof process === 'object' &&
typeof require === 'function';
};

var depd = null;
validator.deprecation = function (msg) {
if (depd === null) {
if (typeof require !== 'function') {
if (!validator.isServerSide()) {
return;
}
depd = require('depd')('validator');
Expand Down
Loading

0 comments on commit 06e2080

Please sign in to comment.