From 5f691b1cf83c388edb2938a8c032ad0cbb2e6505 Mon Sep 17 00:00:00 2001 From: Ray Clanan Date: Wed, 25 Nov 2015 20:23:31 -0600 Subject: [PATCH] New isUndefined utility method Updated all test for undefined to use new utility method isUndefined --- src/lib/locale/locales.js | 5 +++-- src/lib/moment/compare.js | 5 +++-- src/lib/moment/constructor.js | 23 ++++++++++++----------- src/lib/units/offset.js | 3 ++- src/lib/utils/deprecate.js | 4 ++-- src/lib/utils/is-undefined.js | 3 +++ 6 files changed, 25 insertions(+), 18 deletions(-) create mode 100644 src/lib/utils/is-undefined.js diff --git a/src/lib/locale/locales.js b/src/lib/locale/locales.js index a32e5aced..cf2c3292e 100644 --- a/src/lib/locale/locales.js +++ b/src/lib/locale/locales.js @@ -1,4 +1,5 @@ import isArray from '../utils/is-array'; +import isUndefined from '../utils/is-undefined'; import compareArrays from '../utils/compare-arrays'; import { Locale } from './constructor'; @@ -40,7 +41,7 @@ function chooseLocale(names) { function loadLocale(name) { var oldLocale = null; // TODO: Find a better way to register and load all the locales in Node - if (!locales[name] && typeof module !== 'undefined' && + if (!locales[name] && !isUndefined(module) && module && module.exports) { try { oldLocale = globalLocale._abbr; @@ -59,7 +60,7 @@ function loadLocale(name) { export function getSetGlobalLocale (key, values) { var data; if (key) { - if (typeof values === 'undefined') { + if (isUndefined(values)) { data = getLocale(key); } else { diff --git a/src/lib/moment/compare.js b/src/lib/moment/compare.js index 35132f2c4..d196a9806 100644 --- a/src/lib/moment/compare.js +++ b/src/lib/moment/compare.js @@ -1,13 +1,14 @@ import { isMoment } from './constructor'; import { normalizeUnits } from '../units/aliases'; import { createLocal } from '../create/local'; +import isUndefined from '../utils/is-undefined'; export function isAfter (input, units) { var localInput = isMoment(input) ? input : createLocal(input); if (!(this.isValid() && localInput.isValid())) { return false; } - units = normalizeUnits(typeof units !== 'undefined' ? units : 'millisecond'); + units = normalizeUnits(!isUndefined(units) ? units : 'millisecond'); if (units === 'millisecond') { return +this > +localInput; } else { @@ -20,7 +21,7 @@ export function isBefore (input, units) { if (!(this.isValid() && localInput.isValid())) { return false; } - units = normalizeUnits(typeof units !== 'undefined' ? units : 'millisecond'); + units = normalizeUnits(!isUndefined(units) ? units : 'millisecond'); if (units === 'millisecond') { return +this < +localInput; } else { diff --git a/src/lib/moment/constructor.js b/src/lib/moment/constructor.js index f5f3da0fb..964c0aef6 100644 --- a/src/lib/moment/constructor.js +++ b/src/lib/moment/constructor.js @@ -1,5 +1,6 @@ import { hooks } from '../utils/hooks'; import hasOwnProp from '../utils/has-own-prop'; +import isUndefined from '../utils/is-undefined'; import getParsingFlags from '../create/parsing-flags'; // Plugins that add properties should also add the key here (null value), @@ -9,34 +10,34 @@ var momentProperties = hooks.momentProperties = []; export function copyConfig(to, from) { var i, prop, val; - if (typeof from._isAMomentObject !== 'undefined') { + if (!isUndefined(from._isAMomentObject)) { to._isAMomentObject = from._isAMomentObject; } - if (typeof from._i !== 'undefined') { + if (!isUndefined(from._i)) { to._i = from._i; } - if (typeof from._f !== 'undefined') { + if (!isUndefined(from._f)) { to._f = from._f; } - if (typeof from._l !== 'undefined') { + if (!isUndefined(from._l)) { to._l = from._l; } - if (typeof from._strict !== 'undefined') { + if (!isUndefined(from._strict)) { to._strict = from._strict; } - if (typeof from._tzm !== 'undefined') { + if (!isUndefined(from._tzm)) { to._tzm = from._tzm; } - if (typeof from._isUTC !== 'undefined') { + if (!isUndefined(from._isUTC)) { to._isUTC = from._isUTC; } - if (typeof from._offset !== 'undefined') { + if (!isUndefined(from._offset)) { to._offset = from._offset; } - if (typeof from._pf !== 'undefined') { + if (!isUndefined(from._pf)) { to._pf = getParsingFlags(from); } - if (typeof from._locale !== 'undefined') { + if (!isUndefined(from._locale)) { to._locale = from._locale; } @@ -44,7 +45,7 @@ export function copyConfig(to, from) { for (i in momentProperties) { prop = momentProperties[i]; val = from[prop]; - if (typeof val !== 'undefined') { + if (!isUndefined(val)) { to[prop] = val; } } diff --git a/src/lib/units/offset.js b/src/lib/units/offset.js index 3d21f6aa4..6c4487b85 100644 --- a/src/lib/units/offset.js +++ b/src/lib/units/offset.js @@ -10,6 +10,7 @@ import { prepareConfig } from '../create/from-anything'; import { createUTC } from '../create/utc'; import isDate from '../utils/is-date'; import toInt from '../utils/to-int'; +import isUndefined from '../utils/is-undefined'; import compareArrays from '../utils/compare-arrays'; import { hooks } from '../utils/hooks'; @@ -186,7 +187,7 @@ export function isDaylightSavingTime () { } export function isDaylightSavingTimeShifted () { - if (typeof this._isDSTShifted !== 'undefined') { + if (!isUndefined(this._isDSTShifted)) { return this._isDSTShifted; } diff --git a/src/lib/utils/deprecate.js b/src/lib/utils/deprecate.js index 44326c072..1b7813177 100644 --- a/src/lib/utils/deprecate.js +++ b/src/lib/utils/deprecate.js @@ -1,8 +1,9 @@ import extend from './extend'; import { hooks } from './hooks'; +import isUndefined from './is-undefined'; function warn(msg) { - if (hooks.suppressDeprecationWarnings === false && typeof console !== 'undefined' && console.warn) { + if (hooks.suppressDeprecationWarnings === false && !isUndefined(console) && console.warn) { console.warn('Deprecation warning: ' + msg); } } @@ -29,4 +30,3 @@ export function deprecateSimple(name, msg) { } hooks.suppressDeprecationWarnings = false; - diff --git a/src/lib/utils/is-undefined.js b/src/lib/utils/is-undefined.js new file mode 100644 index 000000000..de57a8b28 --- /dev/null +++ b/src/lib/utils/is-undefined.js @@ -0,0 +1,3 @@ +export default function isUndefined(input) { + return input === void 0; +} -- 2.47.2