Skip to content

Commit 219b7a3

Browse files
CommanderRootdonmccurdy
authored andcommitted
Replace deprecated String.prototype.substr() (mrdoob#23525)
String.prototype.substr() is deprecated (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr) so we replace it with slice() which works similarily but isn't deprecated. Signed-off-by: Tobias Speicher <[email protected]>
1 parent b4064cf commit 219b7a3

39 files changed

+98
-97
lines changed

docs/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,9 @@ <h1><a href="https://threejs.org">three.js</a></h1>
327327

328328
const hash = location.hash;
329329
if ( hash === '' ) return;
330-
const docType = hash.substr( 0, hash.indexOf( '/' ) + 1 );
331-
let docLink = hash.substr( hash.indexOf( '/' ) + 1 );
332-
docLink = docLink.substr( docLink.indexOf( '/' ) );
330+
const docType = hash.slice( 0, hash.indexOf( '/' ) + 1 );
331+
let docLink = hash.slice( hash.indexOf( '/' ) + 1 );
332+
docLink = docLink.slice( docLink.indexOf( '/' ) );
333333
location.href = docType + language + docLink;
334334

335335
}
@@ -342,7 +342,7 @@ <h1><a href="https://threejs.org">three.js</a></h1>
342342

343343
if ( search.indexOf( '?q=' ) !== - 1 ) {
344344

345-
return decodeURI( search.substr( 3 ) );
345+
return decodeURI( search.slice( 3 ) );
346346

347347
}
348348

docs/page.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ if ( ! window.frameElement && window.location.protocol !== 'file:' ) {
66

77
let href = window.location.href;
88
const splitIndex = href.lastIndexOf( '/docs/' ) + 6;
9-
const docsBaseURL = href.substr( 0, splitIndex );
9+
const docsBaseURL = href.slice( 0, splitIndex );
1010

1111
let hash = window.location.hash;
1212

@@ -36,22 +36,22 @@ function onDocumentLoad() {
3636
switch ( section ) {
3737

3838
case 'api':
39-
localizedPath = /\/api\/[A-Za-z0-9\/]+/.exec( pathname ).toString().substr( 5 );
39+
localizedPath = /\/api\/[A-Za-z0-9\/]+/.exec( pathname ).toString().slice( 5 );
4040

4141
// Remove localized part of the path (e.g. 'en/' or 'es-MX/'):
4242
path = localizedPath.replace( /^[A-Za-z0-9-]+\//, '' );
4343

4444
break;
4545

4646
case 'examples':
47-
path = localizedPath = /\/examples\/[A-Za-z0-9\/]+/.exec( pathname ).toString().substr( 10 );
47+
path = localizedPath = /\/examples\/[A-Za-z0-9\/]+/.exec( pathname ).toString().slice( 10 );
4848
break;
4949

5050
case 'manual':
5151
name = name.replace( /\-/g, ' ' );
5252

5353
path = pathname.replace( /\ /g, '-' );
54-
path = localizedPath = /\/manual\/[-A-Za-z0-9\/]+/.exec( path ).toString().substr( 8 );
54+
path = localizedPath = /\/manual\/[-A-Za-z0-9\/]+/.exec( path ).toString().slice( 8 );
5555
break;
5656

5757
}

editor/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,9 @@
223223
var isLoadingFromHash = false;
224224
var hash = window.location.hash;
225225

226-
if ( hash.substr( 1, 5 ) === 'file=' ) {
226+
if ( hash.slice( 1, 6 ) === 'file=' ) {
227227

228-
var file = hash.substr( 6 );
228+
var file = hash.slice( 6 );
229229

230230
if ( confirm( 'Any unsaved data will be lost. Are you sure?' ) ) {
231231

editor/js/LoaderUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const LoaderUtils = {
6060

6161
files.push( file );
6262

63-
filesMap[ entry.fullPath.substr( 1 ) ] = file;
63+
filesMap[ entry.fullPath.slice( 1 ) ] = file;
6464
onEntryHandled();
6565

6666
} );

examples/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ <h1><a href="https://threejs.org">three.js</a></h1>
381381

382382
if ( search.indexOf( '?q=' ) !== - 1 ) {
383383

384-
return decodeURI( search.substr( 3 ) );
384+
return decodeURI( search.slice( 3 ) );
385385

386386
}
387387

examples/js/exporters/GLTFExporter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,7 @@
13521352
for ( let attributeName in geometry.attributes ) {
13531353

13541354
// Ignore morph target attributes, which are exported later.
1355-
if ( attributeName.substr( 0, 5 ) === 'morph' ) continue;
1355+
if ( attributeName.slice( 0, 5 ) === 'morph' ) continue;
13561356
const attribute = geometry.attributes[ attributeName ];
13571357
attributeName = nameConversion[ attributeName ] || attributeName.toUpperCase(); // Prefix all geometry attributes except the ones specifically
13581358
// listed in the spec; non-spec attributes are considered custom.

examples/js/loaders/ColladaLoader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2805,7 +2805,7 @@
28052805
const param = child.getElementsByTagName( 'param' )[ 0 ];
28062806
data.axis = param.textContent;
28072807
const tmpJointIndex = data.axis.split( 'inst_' ).pop().split( 'axis' )[ 0 ];
2808-
data.jointIndex = tmpJointIndex.substr( 0, tmpJointIndex.length - 1 );
2808+
data.jointIndex = tmpJointIndex.substring( 0, tmpJointIndex.length - 1 );
28092809
break;
28102810

28112811
}

examples/js/loaders/KMZLoader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
for ( const path in zip ) {
5050

51-
if ( path.substr( - url.length ) === url ) {
51+
if ( path.slice( - url.length ) === url ) {
5252

5353
return zip[ path ];
5454

examples/js/loaders/LWOLoader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@
955955

956956
const index = url.indexOf( dir );
957957
if ( index === - 1 ) return './';
958-
return url.substr( 0, index );
958+
return url.slice( 0, index );
959959

960960
}
961961

examples/js/loaders/OBJLoader.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@
491491

492492
} else if ( lineFirstChar === 'f' ) {
493493

494-
const lineData = line.substr( 1 ).trim();
494+
const lineData = line.slice( 1 ).trim();
495495
const vertexData = lineData.split( /\s+/ );
496496
const faceVertices = []; // Parse the face vertex data into an easy to work with format
497497

@@ -545,7 +545,7 @@
545545

546546
} else if ( lineFirstChar === 'p' ) {
547547

548-
const lineData = line.substr( 1 ).trim();
548+
const lineData = line.slice( 1 ).trim();
549549
const pointData = lineData.split( ' ' );
550550
state.addPointGeometry( pointData );
551551

@@ -555,8 +555,8 @@
555555
// or
556556
// g group_name
557557
// WORKAROUND: https://bugs.chromium.org/p/v8/issues/detail?id=2869
558-
// let name = result[ 0 ].substr( 1 ).trim();
559-
const name = ( ' ' + result[ 0 ].substr( 1 ).trim() ).substr( 1 );
558+
// let name = result[ 0 ].slice( 1 ).trim();
559+
const name = ( ' ' + result[ 0 ].slice( 1 ).trim() ).slice( 1 );
560560
state.startObject( name );
561561

562562
} else if ( _material_use_pattern.test( line ) ) {

0 commit comments

Comments
 (0)