Skip to content

Commit 1b6ded5

Browse files
CommanderRootJonathan Ginsburg
authored andcommitted
refactor: replace .substring() with .slice()
.slice() is shorter and generally faster Signed-off-by: Tobias Speicher <[email protected]>
1 parent d6359a7 commit 1b6ded5

4 files changed

Lines changed: 6 additions & 6 deletions

File tree

lib/file.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class File {
3636
* @returns {string} detected file type or empty string
3737
*/
3838
detectType () {
39-
return path.extname(this.path).substring(1)
39+
return path.extname(this.path).slice(1)
4040
}
4141

4242
toString () {

lib/helper.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ const parser = (pattern, out) => {
3030
t = 'optional'
3131
}
3232
out[t]++
33-
return parser(pattern.substring(1), out)
33+
return parser(pattern.slice(1), out)
3434
}
3535
if (matches[2] !== undefined) {
3636
out.ext_glob++
3737
parser(matches[2], out)
38-
return parser(pattern.substring(matches[0].length), out)
38+
return parser(pattern.slice(matches[0].length), out)
3939
}
4040
out.range++
41-
return parser(pattern.substring(matches[0].length), out)
41+
return parser(pattern.slice(matches[0].length), out)
4242
}
4343

4444
const gsParser = (pattern, out) => {

lib/launchers/process.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function ProcessLauncher (spawn, tempDir, timer, processKillTimeout) {
4444
// Normalize the command, remove quotes (spawn does not like them).
4545
this._normalizeCommand = function (cmd) {
4646
if (cmd.charAt(0) === cmd.charAt(cmd.length - 1) && '\'`"'.includes(cmd.charAt(0))) {
47-
cmd = cmd.substring(1, cmd.length - 1)
47+
cmd = cmd.slice(1, -1)
4848
log.warn(`The path should not be quoted.\n Normalized the path to ${cmd}`)
4949
}
5050

lib/url.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Url {
1919
* @returns {string} detected file type or empty string
2020
*/
2121
detectType () {
22-
return path.extname(new URL(this.path).pathname).substring(1)
22+
return path.extname(new URL(this.path).pathname).slice(1)
2323
}
2424

2525
toString () {

0 commit comments

Comments
 (0)