.replace( /__+/g, '_' )
.replace( /^_+/, '' )
.replace( /_+$/, '' );
- value = value.substr( 0, 1 ).toUpperCase() + value.substr( 1 );
+ value = value.charAt( 0 ).toUpperCase() + value.slice( 1 );
$label.text( labelText.replace( '$1', value ) );
}
r = trimmableText.length;
do {
m = Math.ceil( ( l + r ) / 2 );
- $trimmableText.text( trimmableText.substr( 0, m ) + '...' );
+ $trimmableText.text( trimmableText.slice( 0, m ) + '...' );
if ( $trimmableText.width() + pw > w ) {
// Text is too long
r = m - 1;
l = m;
}
} while ( l < r );
- $trimmableText.text( trimmableText.substr( 0, l ) + '...' );
+ $trimmableText.text( trimmableText.slice( 0, l ) + '...' );
break;
case 'center':
// TODO: Use binary search like for 'right'
// Begin with making the end shorter
side = 1;
while ( $trimmableText.outerWidth() + pw > w && i[0] > 0 ) {
- $trimmableText.text( trimmableText.substr( 0, i[0] ) + '...' + trimmableText.substr( i[1] ) );
+ $trimmableText.text( trimmableText.slice( 0, i[0] ) + '...' + trimmableText.slice( i[1] ) );
// Alternate between trimming the end and begining
if ( side === 0 ) {
// Make the begining shorter
// TODO: Use binary search like for 'right'
r = 0;
while ( $trimmableText.outerWidth() + pw > w && r < trimmableText.length ) {
- $trimmableText.text( '...' + trimmableText.substr( r ) );
+ $trimmableText.text( '...' + trimmableText.slice( r ) );
r++;
}
break;
inpParts = [
// Same start
- newVal.substring( 0, startMatches ),
+ newVal.slice( 0, startMatches ),
// Inserted content
- newVal.substring( startMatches, newVal.length - endMatches ),
+ newVal.slice( startMatches, newVal.length - endMatches ),
// Same end
- newVal.substring( newVal.length - endMatches )
+ newVal.slice( newVal.length - endMatches )
];
// Chop off characters from the end of the "inserted content" string
$('*', e).each(function () {
if (this.currentStyle.backgroundImage != 'none') {
var image = this.currentStyle.backgroundImage;
- image = this.currentStyle.backgroundImage.substring(5, image.length - 2);
+ image = this.currentStyle.backgroundImage.slice(5, image.length - 2);
$(this).css({
'backgroundImage': 'none',
'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='" + image + "')"
bits = candidate.split( / +/ );
src = bits[0];
if ( bits.length > 1 && bits[1].charAt( bits[1].length - 1 ) === 'x' ) {
- ratioStr = bits[1].substr( 0, bits[1].length - 1 );
+ ratioStr = bits[1].slice( 0, -1 );
ratio = parseFloat( ratioStr );
if ( ratio <= devicePixelRatio && ratio > selectedRatio ) {
selectedRatio = ratio;
'' : str.toString().replace( /\s+$/, '' );
},
ucFirst: function ( str ) {
- return str.charAt( 0 ).toUpperCase() + str.substr( 1 );
+ return str.charAt( 0 ).toUpperCase() + str.slice( 1 );
},
escapeRE: function ( str ) {
return str.replace ( /([\\{}()|.?*+\-\^$\[\]])/g, '\\$1' );
} else {
while ( selText.charAt( selText.length - 1 ) === ' ' ) {
// Exclude ending space char
- selText = selText.substring( 0, selText.length - 1 );
+ selText = selText.slice( 0, -1 );
post += ' ';
}
while ( selText.charAt( 0 ) === ' ' ) {
// Exclude prepending space char
- selText = selText.substring( 1, selText.length );
+ selText = selText.slice( 1 );
pre = ' ' + pre;
}
}
post += '\n';
}
}
- this.value = this.value.substring( 0, startPos ) + insertText +
- this.value.substring( endPos, this.value.length );
+ this.value = this.value.slice( 0, startPos ) + insertText +
+ this.value.slice( endPos );
// Setting this.value scrolls the textarea to the top, restore the scroll position
this.scrollTop = scrollTop;
if ( window.opera ) {
break;
case 'illative':
// Double the last letter and add 'n'
- word += word.substr( word.length - 1 ) + 'n';
+ word += word.slice( -1 ) + 'n';
break;
case 'inessive':
word += ( aou ? 'ssa' : 'ssä' );
case 'prefixed':
case 'תחילית': // the same word in Hebrew
// Duplicate prefixed "Waw", but only if it's not already double
- if ( word.substr( 0, 1 ) === 'ו' && word.substr( 0, 2 ) !== 'וו' ) {
+ if ( word.slice( 0, 1 ) === 'ו' && word.slice( 0, 2 ) !== 'וו' ) {
word = 'ו' + word;
}
// Remove the "He" if prefixed
- if ( word.substr( 0, 1 ) === 'ה' ) {
- word = word.substr( 1, word.length );
+ if ( word.slice( 0, 1 ) === 'ה' ) {
+ word = word.slice( 1 );
}
// Add a hyphen (maqaf) before numbers and non-Hebrew letters
- if ( word.substr( 0, 1 ) < 'א' || word.substr( 0, 1 ) > 'ת' ) {
+ if ( word.slice( 0, 1 ) < 'א' || word.slice( 0, 1 ) > 'ת' ) {
word = '־' + word;
}
}
switch ( form ) {
case 'genitive': // սեռական հոլով
- if ( word.substr( -1 ) === 'ա' ) {
- word = word.substr( 0, word.length - 1 ) + 'այի';
- } else if ( word.substr( -1 ) === 'ո' ) {
- word = word.substr( 0, word.length - 1 ) + 'ոյի';
- } else if ( word.substr( -4 ) === 'գիրք' ) {
- word = word.substr( 0, word.length - 4 ) + 'գրքի';
+ if ( word.slice( -1 ) === 'ա' ) {
+ word = word.slice( 0, -1 ) + 'այի';
+ } else if ( word.slice( -1 ) === 'ո' ) {
+ word = word.slice( 0, -1 ) + 'ոյի';
+ } else if ( word.slice( -4 ) === 'գիրք' ) {
+ word = word.slice( 0, -4 ) + 'գրքի';
} else {
word = word + 'ի';
}
}
// Checking if the $word is in plural form
if ( word.match( /тæ$/i ) ) {
- word = word.substring( 0, word.length - 1 );
+ word = word.slice( 0, -1 );
endAllative = 'æм';
}
// Works if word is in singular form.
// Checking if word ends on 'у'. 'У' can be either consonant 'W' or vowel 'U' in cyrillic Ossetic.
// Examples: {{grammar:genitive|аунеу}} = аунеуы, {{grammar:genitive|лæппу}} = лæппуйы.
else if ( word.match( /у$/i ) ) {
- if ( !word.substring( word.length - 2, word.length - 1 ).match( /[аæеёиоыэюя]$/i ) ) {
+ if ( !word.slice( -2, -1 ).match( /[аæеёиоыэюя]$/i ) ) {
jot = 'й';
}
} else if ( !word.match( /[бвгджзйклмнопрстфхцчшщьъ]$/i ) ) {
}
switch ( form ) {
case 'genitive': // родительный падеж
- if ( word.substr( word.length - 1 ) === 'ь' ) {
- word = word.substr(0, word.length - 1 ) + 'я';
- } else if ( word.substr( word.length - 2 ) === 'ия' ) {
- word = word.substr(0, word.length - 2 ) + 'ии';
- } else if ( word.substr( word.length - 2 ) === 'ка' ) {
- word = word.substr(0, word.length - 2 ) + 'ки';
- } else if ( word.substr( word.length - 2 ) === 'ти' ) {
- word = word.substr(0, word.length - 2 ) + 'тей';
- } else if ( word.substr( word.length - 2 ) === 'ды' ) {
- word = word.substr(0, word.length - 2 ) + 'дов';
- } else if ( word.substr( word.length - 1 ) === 'д' ) {
- word = word.substr(0, word.length - 1 ) + 'да';
- } else if ( word.substr( word.length - 3 ) === 'ные' ) {
- word = word.substr(0, word.length - 3 ) + 'ных';
- } else if ( word.substr( word.length - 3 ) === 'ник' ) {
- word = word.substr(0, word.length - 3 ) + 'ника';
+ if ( word.slice( -1 ) === 'ь' ) {
+ word = word.slice( 0, -1 ) + 'я';
+ } else if ( word.slice( -2 ) === 'ия' ) {
+ word = word.slice( 0, -2 ) + 'ии';
+ } else if ( word.slice( -2 ) === 'ка' ) {
+ word = word.slice( 0, -2 ) + 'ки';
+ } else if ( word.slice( -2 ) === 'ти' ) {
+ word = word.slice( 0, -2 ) + 'тей';
+ } else if ( word.slice( -2 ) === 'ды' ) {
+ word = word.slice( 0, -2 ) + 'дов';
+ } else if ( word.slice( -1 ) === 'д' ) {
+ word = word.slice( 0, -1 ) + 'да';
+ } else if ( word.slice( -3 ) === 'ные' ) {
+ word = word.slice( 0, -3 ) + 'ных';
+ } else if ( word.slice( -3 ) === 'ник' ) {
+ word = word.slice( 0, -3 ) + 'ника';
}
break;
case 'prepositional': // предложный падеж
- if ( word.substr( word.length - 1 ) === 'ь' ) {
- word = word.substr(0, word.length - 1 ) + 'е';
- } else if ( word.substr( word.length - 2 ) === 'ия' ) {
- word = word.substr(0, word.length - 2 ) + 'ии';
- } else if ( word.substr( word.length - 2 ) === 'ка' ) {
- word = word.substr(0, word.length - 2 ) + 'ке';
- } else if ( word.substr( word.length - 2 ) === 'ти' ) {
- word = word.substr(0, word.length - 2 ) + 'тях';
- } else if ( word.substr( word.length - 2 ) === 'ды' ) {
- word = word.substr(0, word.length - 2 ) + 'дах';
- } else if ( word.substr( word.length - 1 ) === 'д' ) {
- word = word.substr(0, word.length - 1 ) + 'де';
- } else if ( word.substr( word.length - 3 ) === 'ные' ) {
- word = word.substr(0, word.length - 3 ) + 'ных';
- } else if ( word.substr( word.length - 3 ) === 'ник' ) {
- word = word.substr(0, word.length - 3 ) + 'нике';
+ if ( word.slice( -1 ) === 'ь' ) {
+ word = word.slice( 0, -1 ) + 'е';
+ } else if ( word.slice( -2 ) === 'ия' ) {
+ word = word.slice( 0, -2 ) + 'ии';
+ } else if ( word.slice( -2 ) === 'ка' ) {
+ word = word.slice( 0, -2 ) + 'ке';
+ } else if ( word.slice( -2 ) === 'ти' ) {
+ word = word.slice( 0, -2 ) + 'тях';
+ } else if ( word.slice( -2 ) === 'ды' ) {
+ word = word.slice( 0, -2 ) + 'дах';
+ } else if ( word.slice( -1 ) === 'д' ) {
+ word = word.slice( 0, -1 ) + 'де';
+ } else if ( word.slice( -3 ) === 'ные' ) {
+ word = word.slice( 0, -3 ) + 'ных';
+ } else if ( word.slice( -3 ) === 'ник' ) {
+ word = word.slice( 0, -3 ) + 'нике';
}
break;
}
}
switch ( form ) {
case 'genitive': // родовий відмінок
- if ( word.substr( word.length - 4 ) !== 'вікі' && word.substr( word.length - 4 ) !== 'Вікі' ) {
- if ( word.substr( word.length - 1 ) === 'ь' ) {
- word = word.substr(0, word.length - 1 ) + 'я';
- } else if ( word.substr( word.length - 2 ) === 'ія' ) {
- word = word.substr(0, word.length - 2 ) + 'ії';
- } else if ( word.substr( word.length - 2 ) === 'ка' ) {
- word = word.substr(0, word.length - 2 ) + 'ки';
- } else if ( word.substr( word.length - 2 ) === 'ти' ) {
- word = word.substr(0, word.length - 2 ) + 'тей';
- } else if ( word.substr( word.length - 2 ) === 'ды' ) {
- word = word.substr(0, word.length - 2 ) + 'дов';
- } else if ( word.substr( word.length - 3 ) === 'ник' ) {
- word = word.substr(0, word.length - 3 ) + 'ника';
+ if ( word.slice( -4 ) !== 'вікі' && word.slice( -4 ) !== 'Вікі' ) {
+ if ( word.slice( -1 ) === 'ь' ) {
+ word = word.slice(0, -1 ) + 'я';
+ } else if ( word.slice( -2 ) === 'ія' ) {
+ word = word.slice(0, -2 ) + 'ії';
+ } else if ( word.slice( -2 ) === 'ка' ) {
+ word = word.slice(0, -2 ) + 'ки';
+ } else if ( word.slice( -2 ) === 'ти' ) {
+ word = word.slice(0, -2 ) + 'тей';
+ } else if ( word.slice( -2 ) === 'ды' ) {
+ word = word.slice(0, -2 ) + 'дов';
+ } else if ( word.slice( -3 ) === 'ник' ) {
+ word = word.slice(0, -3 ) + 'ника';
}
}
break;
case 'accusative': // знахідний відмінок
- if ( word.substr( word.length - 4 ) !== 'вікі' && word.substr( word.length - 4 ) !== 'Вікі' ) {
- if ( word.substr( word.length - 2 ) === 'ія' ) {
- word = word.substr(0, word.length - 2 ) + 'ію';
+ if ( word.slice( -4 ) !== 'вікі' && word.slice( -4 ) !== 'Вікі' ) {
+ if ( word.slice( -2 ) === 'ія' ) {
+ word = word.slice(0, -2 ) + 'ію';
}
}
break;
form = forms[index];
if ( /^\d+=/.test( form ) ) {
equalsPosition = form.indexOf( '=' );
- formCount = parseInt( form.substring( 0, equalsPosition ), 10 );
+ formCount = parseInt( form.slice( 0, equalsPosition ), 10 );
if ( formCount === count ) {
- return form.substr( equalsPosition + 1 );
+ return form.slice( equalsPosition + 1 );
}
forms[index] = undefined;
}
// Truncate fractional
if ( maxPlaces < fractional.length ) {
- valueParts[1] = fractional.substr( 0, maxPlaces );
+ valueParts[1] = fractional.slice( 0, maxPlaces );
}
} else {
if ( valueParts[1] ) {
// Truncate whole
if ( patternDigits.indexOf( '#' ) === -1 ) {
- valueParts[0] = valueParts[0].substr( valueParts[0].length - padLength );
+ valueParts[0] = valueParts[0].slice( valueParts[0].length - padLength );
}
}
if ( index !== -1 ) {
groupSize = patternParts[0].length - index - 1;
- remainder = patternParts[0].substr( 0, index );
+ remainder = patternParts[0].slice( 0, index );
index = remainder.lastIndexOf( ',' );
if ( index !== -1 ) {
groupSize2 = remainder.length - index - 1;
for ( whole = valueParts[0]; whole; ) {
off = groupSize ? whole.length - groupSize : 0;
- pieces.push( ( off > 0 ) ? whole.substr( off ) : whole );
+ pieces.push( ( off > 0 ) ? whole.slice( off ) : whole );
whole = ( off > 0 ) ? whole.slice( 0, off ) : '';
if ( groupSize2 ) {
if ( slash === -1 && backslash === -1 ) {
fname = path;
} else if ( slash > backslash ) {
- fname = path.substring( slash + 1 );
+ fname = path.slice( slash + 1 );
} else {
- fname = path.substring( backslash + 1 );
+ fname = path.slice( backslash + 1 );
}
// Clear the filename if it does not have a valid extension.
if (
fname.lastIndexOf( '.' ) === -1 ||
$.inArray(
- fname.substr( fname.lastIndexOf( '.' ) + 1 ).toLowerCase(),
+ fname.slice( fname.lastIndexOf( '.' ) + 1 ).toLowerCase(),
$.map( mw.config.get( 'wgFileExtensions' ), function ( element ) {
return element.toLowerCase();
} )
fname = fname.replace( / /g, '_' );
// Capitalise first letter if needed
if ( mw.config.get( 'wgCapitalizeUploads' ) ) {
- fname = fname.charAt( 0 ).toUpperCase().concat( fname.substring( 1 ) );
+ fname = fname.charAt( 0 ).toUpperCase().concat( fname.slice( 1 ) );
}
// Output result
var parts = $( this ).attr( 'href' ).split( 'search=' ),
lastpart = '',
prefix = 'search=';
- if ( parts.length > 1 && parts[1].indexOf( '&' ) >= 0 ) {
- lastpart = parts[1].substring( parts[1].indexOf( '&' ) );
+ if ( parts.length > 1 && parts[1].indexOf( '&' ) !== -1 ) {
+ lastpart = parts[1].slice( parts[1].indexOf( '&' ) );
} else {
prefix = '&search=';
}
namespace = NS_MAIN;
title = title
// Strip colon
- .substr( 1 )
+ .slice( 1 )
// Trim underscores
.replace( rUnderscoreTrim, '' );
}
} else {
fragment = title
// Get segment starting after the hash
- .substr( i + 1 )
+ .slice( i + 1 )
// Convert to text
// NB: Must not be trimmed ("Example#_foo" is not the same as "Example#foo")
.replace( /_/g, ' ' );
title = title
// Strip hash
- .substr( 0, i )
+ .slice( 0, i )
// Trim underscores, again (strips "_" from "bar" in "Foo_bar_#quux")
.replace( rUnderscoreTrim, '' );
}
title.indexOf( '../' ) === 0 ||
title.indexOf( '/./' ) !== -1 ||
title.indexOf( '/../' ) !== -1 ||
- title.substr( title.length - 2 ) === '/.' ||
- title.substr( title.length - 3 ) === '/..'
+ title.slice( -2 ) === '/.' ||
+ title.slice( -3 ) === '/..'
)
) {
return false;
// Extensions are the non-empty segment after the last dot
ext = null;
} else {
- ext = title.substr( i + 1 );
- title = title.substr( 0, i );
+ ext = title.slice( i + 1 );
+ title = title.slice( 0, i );
}
return {
*/
switchPane: function ( e ) {
var currentPaneId = debug.$container.data( 'currentPane' ),
- requestedPaneId = $( this ).prop( 'id' ).substr( 9 ),
+ requestedPaneId = $( this ).prop( 'id' ).slice( 9 ),
$currentPane = $( '#mw-debug-pane-' + currentPaneId ),
$requestedPane = $( '#mw-debug-pane-' + requestedPaneId ),
hovDone = false;
gitInfo = '';
if ( this.data.gitRevision !== false ) {
- gitInfo = '(' + this.data.gitRevision.substring( 0, 7 ) + ')';
+ gitInfo = '(' + this.data.gitRevision.slice( 0, 7 ) + ')';
if ( this.data.gitViewUrl !== false ) {
gitInfo = $( '<a>' )
.attr( 'href', this.data.gitViewUrl )
ProfileData.groupOf = function ( label ) {
var pos, prefix = 'Profile section ended by close(): ';
if ( label.indexOf( prefix ) === 0 ) {
- label = label.substring( prefix.length );
+ label = label.slice( prefix.length );
}
pos = [ '::', ':', '-' ].reduce( function ( result, separator ) {
if ( pos === -1 ) {
return label;
} else {
- return label.substring( 0, pos );
+ return label.slice( 0, pos );
}
};
},
/**
- * Perform a substring search across the JavaScript and CSS source code
+ * Perform a string search across the JavaScript and CSS source code
* of all loaded modules and return an array of the names of the
* modules that matched.
*
*/
function makeRegexParser( regex ) {
return function () {
- var matches = input.substr( pos ).match( regex );
+ var matches = input.slice( pos ).match( regex );
if ( matches === null ) {
return null;
}
if ( parsedCloseTagResult === null ) {
// Closing tag failed. Return the start tag and contents.
- return [ 'CONCAT', input.substring( startOpenTagPos, endOpenTagPos ) ]
+ return [ 'CONCAT', input.slice( startOpenTagPos, endOpenTagPos ) ]
.concat( parsedHtmlContents );
}
// parsed HTML link.
//
// Concatenate everything from the tag, flattening the contents.
- result = [ 'CONCAT', input.substring( startOpenTagPos, endOpenTagPos ) ]
- .concat( parsedHtmlContents, input.substring( startCloseTagPos, endCloseTagPos ) );
+ result = [ 'CONCAT', input.slice( startOpenTagPos, endOpenTagPos ) ]
+ .concat( parsedHtmlContents, input.slice( startCloseTagPos, endCloseTagPos ) );
}
return result;
for ( i = 0; i < modules.length; i += 1 ) {
// Determine how many bytes this module would add to the query string
lastDotIndex = modules[i].lastIndexOf( '.' );
- // Note that these substr() calls work even if lastDotIndex == -1
+
+ // If lastDotIndex is -1, substr() returns an empty string
prefix = modules[i].substr( 0, lastDotIndex );
- suffix = modules[i].substr( lastDotIndex + 1 );
+ suffix = modules[i].slice( lastDotIndex + 1 );
+
bytesAdded = moduleMap[prefix] !== undefined
? suffix.length + 3 // '%2C'.length == 3
: modules[i].length + 3; // '%7C'.length == 3
}
for ( key in mw.loader.store.items ) {
- module = key.substring( 0, key.indexOf( '@' ) );
+ module = key.slice( 0, key.indexOf( '@' ) );
if ( mw.loader.store.getModuleKey( module ) !== key ) {
mw.loader.store.stats.expired++;
delete mw.loader.store.items[key];
seed = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
for ( i = 0; i < 32; i++ ) {
r = Math.floor( Math.random() * seed.length );
- id += seed.substring( r, r + 1 );
+ id += seed.charAt( r );
}
return id;
},
// Add two characters using scary black magic
spanText = $span.text();
d = findDivergenceIndex( origText, spanText );
- spanTextNew = spanText.substr( 0, d ) + origText[d] + origText[d] + '...';
+ spanTextNew = spanText.slice( 0, d ) + origText[d] + origText[d] + '...';
assert.gt( spanTextNew.length, spanText.length, 'Verify that the new span-length is indeed greater' );
// Confirm that mw.loader.load() works with protocol-relative URLs
target = target.replace( /https?:/, '' );
- assert.equal( target.substr( 0, 2 ), '//',
+ assert.equal( target.slice( 0, 2 ), '//',
'URL must be relative to test relative URLs!'
);