Skip to content

Commit d279946

Browse files
refactor: replace deprecated String.prototype.substr() (#6255)
.substr() is deprecated so we replace it with .slice() which works similarily but isn't deprecated Signed-off-by: Tobias Speicher <[email protected]> Co-authored-by: Na Li <[email protected]>
1 parent 934b8b3 commit d279946

File tree

7 files changed

+8
-8
lines changed

7 files changed

+8
-8
lines changed

scripts/release-util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ export async function updateDependency(
279279

280280
let relaxedVersionPrefix = '';
281281
if (version.startsWith('~') || version.startsWith('^')) {
282-
relaxedVersionPrefix = version.substr(0, 1);
282+
relaxedVersionPrefix = version.slice(0, 1);
283283
}
284284
const depVersionLatest = relaxedVersionPrefix + depsLatestVersion[j];
285285

@@ -337,7 +337,7 @@ export function updateTFJSDependencyVersions(
337337

338338
let relaxedVersionPrefix = '';
339339
if (version.startsWith('~') || version.startsWith('^')) {
340-
relaxedVersionPrefix = version.substr(0, 1);
340+
relaxedVersionPrefix = version.slice(0, 1);
341341
}
342342
const versionLatest = relaxedVersionPrefix + newVersion;
343343

scripts/tag-version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const fs = require('fs');
2222

2323
let dirName = process.argv[2];
2424
if (dirName.endsWith('/')) {
25-
dirName = dirName.substr(0, dirName.length - 1);
25+
dirName = dirName.slice(0, -1);
2626
}
2727
const packageJsonFile = dirName + '/package.json';
2828
if (!fs.existsSync(packageJsonFile)) {

tfjs-converter/src/operations/operation_mapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export class OperationMapper {
191191
category: mapper.category,
192192
inputNames:
193193
(node.input ||
194-
[]).map(input => input.startsWith('^') ? input.substr(1) : input),
194+
[]).map(input => input.startsWith('^') ? input.slice(1) : input),
195195
inputs: [],
196196
children: [],
197197
inputParams: {},

tfjs-data/src/sources/file_data_source.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class FileDataSource extends DataSource {
4646
if (isLocalPath(this.input) && env().get('IS_NODE')) {
4747
// tslint:disable-next-line:no-require-imports
4848
const fs = require('fs');
49-
this.input = fs.readFileSync((this.input as string).substr(7));
49+
this.input = fs.readFileSync((this.input as string).slice(7));
5050
}
5151
// TODO(kangyizhang): Add LocalFileChunkIterator to split local streaming
5252
// with file in browser.

tfjs-data/src/util/source_util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@
2020
// input.
2121
// tslint:disable-next-line:no-any
2222
export function isLocalPath(source: any): boolean {
23-
return (typeof source === 'string') && source.substr(0, 7) === 'file://';
23+
return (typeof source === 'string') && source.slice(0, 7) === 'file://';
2424
}

tfjs-layers/src/engine/topology.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,7 @@ export abstract class Layer extends serialization.Serializable {
12321232
// TODO(cais): Restore the following and use `providedWeights`, instead
12331233
// of `weights` in the error message, once the deeplearn.js bug is
12341234
// fixed: https://github.com/PAIR-code/deeplearnjs/issues/498 const
1235-
// providedWeights = JSON.stringify(weights).substr(0, 50);
1235+
// providedWeights = JSON.stringify(weights).slice(0, 50);
12361236
throw new ValueError(
12371237
`You called setWeights(weights) on layer "${this.name}" ` +
12381238
`with a weight list of length ${weights.length}, ` +

tfjs-node/scripts/deps-stage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ if (os.platform() !== 'win32') {
4040

4141
// Some windows machines contain a trailing " char:
4242
if (targetDir != undefined && targetDir.endsWith('"')) {
43-
targetDir = targetDir.substr(0, targetDir.length - 1);
43+
targetDir = targetDir.slice(0, -1);
4444
}
4545

4646
// Setup dest binary paths:

0 commit comments

Comments
 (0)