Skip to content

Commit

Permalink
refactor: replace .substring() with .slice()
Browse files Browse the repository at this point in the history
.slice() is shorter and generally faster

Signed-off-by: Tobias Speicher <rootcommander@gmail.com>
  • Loading branch information
CommanderRoot authored and Jonathan Ginsburg committed Mar 27, 2022
1 parent d6359a7 commit 1b6ded5
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class File {
* @returns {string} detected file type or empty string
*/
detectType () {
return path.extname(this.path).substring(1)
return path.extname(this.path).slice(1)
}

toString () {
Expand Down
6 changes: 3 additions & 3 deletions lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ const parser = (pattern, out) => {
t = 'optional'
}
out[t]++
return parser(pattern.substring(1), out)
return parser(pattern.slice(1), out)
}
if (matches[2] !== undefined) {
out.ext_glob++
parser(matches[2], out)
return parser(pattern.substring(matches[0].length), out)
return parser(pattern.slice(matches[0].length), out)
}
out.range++
return parser(pattern.substring(matches[0].length), out)
return parser(pattern.slice(matches[0].length), out)
}

const gsParser = (pattern, out) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/launchers/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function ProcessLauncher (spawn, tempDir, timer, processKillTimeout) {
// Normalize the command, remove quotes (spawn does not like them).
this._normalizeCommand = function (cmd) {
if (cmd.charAt(0) === cmd.charAt(cmd.length - 1) && '\'`"'.includes(cmd.charAt(0))) {
cmd = cmd.substring(1, cmd.length - 1)
cmd = cmd.slice(1, -1)
log.warn(`The path should not be quoted.\n Normalized the path to ${cmd}`)
}

Expand Down
2 changes: 1 addition & 1 deletion lib/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Url {
* @returns {string} detected file type or empty string
*/
detectType () {
return path.extname(new URL(this.path).pathname).substring(1)
return path.extname(new URL(this.path).pathname).slice(1)
}

toString () {
Expand Down

0 comments on commit 1b6ded5

Please sign in to comment.