]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
New isUndefined utility method
authorRay Clanan <rclanan@utopianconcept.com>
Thu, 26 Nov 2015 02:23:31 +0000 (20:23 -0600)
committerIskren Chernev <iskren.chernev@gmail.com>
Wed, 9 Dec 2015 08:16:29 +0000 (00:16 -0800)
Updated all test for undefined to use new utility method isUndefined

src/lib/locale/locales.js
src/lib/moment/compare.js
src/lib/moment/constructor.js
src/lib/units/offset.js
src/lib/utils/deprecate.js
src/lib/utils/is-undefined.js [new file with mode: 0644]

index a32e5aced265b215b3042b3694e639950b618418..cf2c3292e03d01880c77ac3cadccbdac45ac0e98 100644 (file)
@@ -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 {
index 35132f2c4dc0743c98522d4495073381ff285572..d196a9806610518f35a0acc11f78c0c18b1afb4a 100644 (file)
@@ -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 {
index f5f3da0fb0ab49122fc57b125bbff81d83c0ad8a..964c0aef6a67d96a756cd7d24433ba331cc527ab 100644 (file)
@@ -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;
             }
         }
index 3d21f6aa4aca62f45d1dd06a8388fd0048aeaec3..6c4487b853ba93b4e4f341fd0c53c7acb5efb6f4 100644 (file)
@@ -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;
     }
 
index 44326c0721d9582629117b2f3d1ca1750274969f..1b7813177c664a23fe71cbd11b117d0b264a26c0 100644 (file)
@@ -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 (file)
index 0000000..de57a8b
--- /dev/null
@@ -0,0 +1,3 @@
+export default function isUndefined(input) {
+    return input === void 0;
+}