Replace $.type with typeof
authorEd Sanders <esanders@wikimedia.org>
Wed, 12 Dec 2018 13:18:08 +0000 (13:18 +0000)
committerEd Sanders <esanders@wikimedia.org>
Wed, 12 Dec 2018 16:57:48 +0000 (16:57 +0000)
Change-Id: I75857eb205ce2fc3ba8f836f3f2ee66987b45748

resources/src/jquery.spinner/spinner.js
resources/src/mediawiki.Title/Title.js
resources/src/mediawiki.cookie.js
resources/src/mediawiki.widgets/MediaSearch/mw.widgets.APIResultsProvider.js
tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js

index 5024688..5dfbab7 100644 (file)
@@ -61,7 +61,7 @@
                createSpinner: function ( opts ) {
                        var $spinner;
 
-                       if ( opts !== undefined && $.type( opts ) !== 'object' ) {
+                       if ( typeof opts === 'string' ) {
                                opts = {
                                        id: opts
                                };
index 44baa8b..def9f68 100644 (file)
                var namespace, m, id, ext, parts;
 
                // defaultNamespace is optional; check whether options moves up
-               if ( arguments.length < 3 && $.type( defaultNamespace ) === 'object' ) {
+               if ( arguments.length < 3 && typeof defaultNamespace === 'object' ) {
                        options = defaultNamespace;
                        defaultNamespace = undefined;
                }
index 5923ff8..76038f6 100644 (file)
@@ -26,7 +26,7 @@
                 * @param {string} key
                 * @param {string|null} value Value of cookie. If `value` is `null` then this method will
                 *   instead remove a cookie by name of `key`.
-                * @param {Object|Date} [options] Options object, or expiry date
+                * @param {Object|Date|number} [options] Options object, or expiry date
                 * @param {Date|number|null} [options.expires] The expiry date of the cookie, or lifetime in seconds.
                 *
                 *   If `options.expires` is null, then a session cookie is set.
@@ -61,8 +61,8 @@
                        };
 
                        // Options argument can also be a shortcut for the expiry
-                       // Expiry can be a Date or null
-                       if ( $.type( options ) !== 'object' ) {
+                       // Expiry can be a Date, number or null
+                       if ( !options || options instanceof Date || typeof options === 'number' ) {
                                // Also takes care of options = undefined, in which case we also don't need $.extend()
                                defaultOptions.expires = options;
                                options = defaultOptions;
index 8f8ef53..781ad08 100644 (file)
 
                xhr = $.getJSON( this.getAPIurl(), allParams )
                        .done( function ( data ) {
-                               if (
-                                       $.type( data ) !== 'array' ||
-                                       (
-                                               $.type( data ) === 'array' &&
-                                               data.length === 0
-                                       )
-                               ) {
-                                       deferred.resolve();
-                               } else {
+                               if ( Array.isArray( data ) && data.length ) {
                                        deferred.resolve( data );
+                               } else {
+                                       deferred.resolve();
                                }
                        } );
                return deferred.promise( { abort: xhr.abort } );
index 3f3cc2c..4a32157 100644 (file)
                var i;
                for ( i = 0; i < cases.valid.length; i++ ) {
                        assert.strictEqual(
-                               $.type( mw.Title.newFromText( cases.valid[ i ] ) ),
+                               typeof mw.Title.newFromText( cases.valid[ i ] ),
                                'object',
                                cases.valid[ i ]
                        );
                }
                for ( i = 0; i < cases.invalid.length; i++ ) {
                        assert.strictEqual(
-                               $.type( mw.Title.newFromText( cases.invalid[ i ] ) ),
-                               'null',
+                               mw.Title.newFromText( cases.invalid[ i ] ),
+                               null,
                                cases.invalid[ i ]
                        );
                }