2 * JavaScript backwards-compatibility alternatives and other convenience functions
4 * @deprecated since 1.26 Dated collection of miscellaneous utilities. Methods are
5 * either trivially inline, obsolete, or have a better place elsewhere.
9 trimLeft: function ( str ) {
10 return str === null ? '' : str.toString().replace( /^\s+/, '' );
12 trimRight: function ( str ) {
14 '' : str.toString().replace( /\s+$/, '' );
16 ucFirst: function ( str ) {
17 return str.charAt( 0 ).toUpperCase() + str.slice( 1 );
19 isDomElement: function ( el ) {
20 return !!el && !!el.nodeType;
22 isEmpty: function ( v ) {
25 v === '' || v === 0 || v === '0' || v === null || v === false || v === undefined
29 // the for-loop could potentially contain prototypes
30 // to avoid that we check its length first
31 if ( v.length === 0 ) {
34 if ( typeof v === 'object' ) {
42 compareArray: function ( arrThis, arrAgainst ) {
44 if ( arrThis.length !== arrAgainst.length ) {
47 for ( i = 0; i < arrThis.length; i++ ) {
48 if ( $.isArray( arrThis[ i ] ) ) {
49 if ( !$.compareArray( arrThis[ i ], arrAgainst[ i ] ) ) {
52 } else if ( arrThis[ i ] !== arrAgainst[ i ] ) {
58 compareObject: function ( objectA, objectB ) {
61 // Do a simple check if the types match
62 if ( typeof objectA === typeof objectB ) {
64 // Only loop over the contents if it really is an object
65 if ( typeof objectA === 'object' ) {
66 // If they are aliases of the same object (ie. mw and mediaWiki) return now
67 if ( objectA === objectB ) {
70 // Iterate over each property
71 for ( prop in objectA ) {
72 // Check if this property is also present in the other object
73 if ( prop in objectB ) {
74 // Compare the types of the properties
75 type = typeof objectA[ prop ];
76 if ( type === typeof objectB[ prop ] ) {
77 // Recursively check objects inside this one
80 if ( !$.compareObject( objectA[ prop ], objectB[ prop ] ) ) {
85 // Functions need to be strings to compare them properly
86 if ( objectA[ prop ].toString() !== objectB[ prop ].toString() ) {
92 if ( objectA[ prop ] !== objectB[ prop ] ) {
104 // Check for properties in B but not in A
105 // This is about 15% faster (tested in Safari 5 and Firefox 3.6)
106 // ...than incrementing a count variable in the above and below loops
107 // See also: https://www.mediawiki.org/wiki/ResourceLoader/Default_modules/compareObject_test#Results
108 for ( prop in objectB ) {
109 if ( !( prop in objectA ) ) {
120 }, function ( key, value ) {
121 mw.log.deprecate( $, key, value );
124 mw.log.deprecate( $, 'escapeRE', function ( str ) {
125 return str.replace( /([\\{}()|.?*+\-\^$\[\]])/g, '\\$1' );
126 }, 'Use mediawiki.RegExp instead.' );
128 }( jQuery, mediaWiki ) );