Skip to content

Commit

Permalink
Rename isNull to isEmpty, re #574
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Sep 27, 2016
1 parent 88bef4a commit e33d38a
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#### HEAD

- Renamed `isNull()` to `isEmpty()`
([#574](https://github.com/chriso/validator.js/issues/574))
- Improved `normalizeEmail()`
([#583](https://github.com/chriso/validator.js/pull/583))

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Passing anything other than a string is an error.
- **isDecimal(str)** - check if the string represents a decimal number, such as 0.1, .3, 1.1, 1.00003, 4.0, etc.
- **isDivisibleBy(str, number)** - check if the string is a number that's divisible by another.
- **isEmail(str [, options])** - check if the string is an email. `options` is an object which defaults to `{ allow_display_name: false, allow_utf8_local_part: true, require_tld: true }`. If `allow_display_name` is set to true, the validator will also match `Display Name <email-address>`. If `allow_utf8_local_part` is set to false, the validator will not allow any non-English UTF8 character in email address' local part. If `require_tld` is set to false, e-mail addresses without having TLD in their domain will also be matched.
- **isEmpty(str)** - check if the string has a length of zero.
- **isFQDN(str [, options])** - check if the string is a fully qualified domain name (e.g. domain.com). `options` is an object which defaults to `{ require_tld: true, allow_underscores: false, allow_trailing_dot: false }`.
- **isFloat(str [, options])** - check if the string is a float. `options` is an object which can contain the keys `min` and/or `max` to validate the float is within boundaries (e.g. `{ min: 7.22, max: 9.55 }`).
- **isFullWidth(str)** - check if the string contains any full-width chars.
Expand All @@ -89,7 +90,6 @@ Passing anything other than a string is an error.
- **isMobilePhone(str, locale)** - check if the string is a mobile phone number, (locale is one of `['ar-DZ', 'ar-SA', 'ar-SY', 'cs-CZ', 'de-DE', 'da-DK', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-CA', 'en-ZA', 'en-ZM', 'es-ES', 'fi-FI', 'fr-FR', 'hu-HU', 'it-IT', 'ja-JP', 'ms-MY', 'nb-NO', 'nn-NO', 'pl-PL', 'pt-PT', 'ru-RU', 'sr-RS', 'tr-TR', 'vi-VN', 'zh-CN', 'zh-TW']`).
- **isMongoId(str)** - check if the string is a valid hex-encoded representation of a [MongoDB ObjectId][mongoid].
- **isMultibyte(str)** - check if the string contains one or more multibyte chars.
- **isNull(str)** - check if the string is null (has a length of zero).
- **isNumeric(str)** - check if the string contains only numbers.
- **isSurrogatePair(str)** - check if the string contains any surrogate pairs chars.
- **isURL(str [, options])** - check if the string is an URL. `options` is an object which defaults to `{ protocols: ['http','https','ftp'], require_tld: true, require_protocol: false, require_host: true, require_valid_protocol: true, allow_underscores: false, host_whitelist: false, host_blacklist: false, allow_trailing_dot: false, allow_protocol_relative_urls: false }`.
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ var _isJSON = require('./lib/isJSON');

var _isJSON2 = _interopRequireDefault(_isJSON);

var _isNull = require('./lib/isNull');
var _isEmpty = require('./lib/isEmpty');

var _isNull2 = _interopRequireDefault(_isNull);
var _isEmpty2 = _interopRequireDefault(_isEmpty);

var _isLength = require('./lib/isLength');

Expand Down Expand Up @@ -263,7 +263,7 @@ var validator = {
isHexColor: _isHexColor2.default,
isMD5: _isMD2.default,
isJSON: _isJSON2.default,
isNull: _isNull2.default,
isEmpty: _isEmpty2.default,
isLength: _isLength2.default, isByteLength: _isByteLength2.default,
isUUID: _isUUID2.default, isMongoId: _isMongoId2.default,
isDate: _isDate2.default, isAfter: _isAfter2.default, isBefore: _isBefore2.default,
Expand Down
4 changes: 2 additions & 2 deletions lib/isNull.js → lib/isEmpty.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = isNull;
exports.default = isEmpty;

var _assertString = require('./util/assertString');

var _assertString2 = _interopRequireDefault(_assertString);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function isNull(str) {
function isEmpty(str) {
(0, _assertString2.default)(str);
return str.length === 0;
}
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import isHexColor from './lib/isHexColor';
import isMD5 from './lib/isMD5';

import isJSON from './lib/isJSON';
import isNull from './lib/isNull';
import isEmpty from './lib/isEmpty';

import isLength from './lib/isLength';
import isByteLength from './lib/isByteLength';
Expand Down Expand Up @@ -97,7 +97,7 @@ const validator = {
isHexColor,
isMD5,
isJSON,
isNull,
isEmpty,
isLength, isByteLength,
isUUID, isMongoId,
isDate, isAfter, isBefore,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/isNull.js → src/lib/isEmpty.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assertString from './util/assertString';

export default function isNull(str) {
export default function isEmpty(str) {
assertString(str);
return str.length === 0;
}
4 changes: 2 additions & 2 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,7 @@ describe('Validators', function () {

it('should validate null strings', function () {
test({
validator: 'isNull',
validator: 'isEmpty',
valid: [
'',
],
Expand Down Expand Up @@ -3395,7 +3395,7 @@ describe('Validators', function () {
it('should error on non-string input', function () {
var empty = [undefined, null, [], NaN];
empty.forEach(function (item) {
assert.throws(validator.isNull.bind(null, item));
assert.throws(validator.isEmpty.bind(null, item));
});
});

Expand Down
4 changes: 2 additions & 2 deletions validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@
return false;
}

function isNull(str) {
function isEmpty(str) {
assertString(str);
return str.length === 0;
}
Expand Down Expand Up @@ -1246,7 +1246,7 @@
isHexColor: isHexColor,
isMD5: isMD5,
isJSON: isJSON,
isNull: isNull,
isEmpty: isEmpty,
isLength: isLength, isByteLength: isByteLength,
isUUID: isUUID, isMongoId: isMongoId,
isDate: isDate, isAfter: isAfter, isBefore: isBefore,
Expand Down
2 changes: 1 addition & 1 deletion validator.min.js

Large diffs are not rendered by default.

0 comments on commit e33d38a

Please sign in to comment.