diff options
author | CommanderRoot <CommanderRoot@users.noreply.github.com> | 2022-04-04 21:08:43 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-04 21:08:43 +0300 |
commit | e3da5df4152fbe547f7871547165328e1bf06262 (patch) | |
tree | 273fd46ffb39ca4499af4a5b6a8807ba2b32b382 /lib/commands | |
parent | 44108f7be5e1e928d8aa3eda3c5c177bcd216c99 (diff) |
fix: replace deprecated String.prototype.substr() (#4667)
.substr() is deprecated so we replace it with .slice() which works similarily but isn't deprecated
Signed-off-by: Tobias Speicher <rootcommander@gmail.com>
Diffstat (limited to 'lib/commands')
-rw-r--r-- | lib/commands/cache.js | 2 | ||||
-rw-r--r-- | lib/commands/completion.js | 6 | ||||
-rw-r--r-- | lib/commands/doctor.js | 4 | ||||
-rw-r--r-- | lib/commands/help-search.js | 4 |
4 files changed, 8 insertions, 8 deletions
diff --git a/lib/commands/cache.js b/lib/commands/cache.js index b8f84abc1..634c8dbb4 100644 --- a/lib/commands/cache.js +++ b/lib/commands/cache.js @@ -177,7 +177,7 @@ class Cache extends BaseCommand { async verify () { const cache = path.join(this.npm.cache, '_cacache') const prefix = cache.indexOf(process.env.HOME) === 0 - ? `~${cache.substr(process.env.HOME.length)}` + ? `~${cache.slice(process.env.HOME.length)}` : cache const stats = await cacache.verify(cache) this.npm.output(`Cache verified and compressed (${prefix})`) diff --git a/lib/commands/completion.js b/lib/commands/completion.js index d0c68af6c..5b7e0d355 100644 --- a/lib/commands/completion.js +++ b/lib/commands/completion.js @@ -97,17 +97,17 @@ class Completion extends BaseCommand { const word = words[w] const line = COMP_LINE const point = +COMP_POINT - const partialLine = line.substr(0, point) + const partialLine = line.slice(0, point) const partialWords = words.slice(0, w) // figure out where in that last word the point is. const partialWordRaw = args[w] let i = partialWordRaw.length - while (partialWordRaw.substr(0, i) !== partialLine.substr(-1 * i) && i > 0) { + while (partialWordRaw.slice(0, i) !== partialLine.slice(-1 * i) && i > 0) { i-- } - const partialWord = unescape(partialWordRaw.substr(0, i)) + const partialWord = unescape(partialWordRaw.slice(0, i)) partialWords.push(partialWord) const opts = { diff --git a/lib/commands/doctor.js b/lib/commands/doctor.js index 22a25477e..ca0438f1a 100644 --- a/lib/commands/doctor.js +++ b/lib/commands/doctor.js @@ -145,7 +145,7 @@ class Doctor extends BaseCommand { return '' } catch (er) { if (/^E\d{3}$/.test(er.code || '')) { - throw er.code.substr(1) + ' ' + er.message + throw er.code.slice(1) + ' ' + er.message } else { throw er.message } @@ -211,7 +211,7 @@ class Doctor extends BaseCommand { const gid = process.getgid() const files = new Set([root]) for (const f of files) { - tracker.silly('checkFilesPermission', f.substr(root.length + 1)) + tracker.silly('checkFilesPermission', f.slice(root.length + 1)) const st = await lstat(f).catch(er => { // if it can't be missing, or if it can and the error wasn't that it was missing if (!missingOk || er.code !== 'ENOENT') { diff --git a/lib/commands/help-search.js b/lib/commands/help-search.js index 9422b8356..3387ac8eb 100644 --- a/lib/commands/help-search.js +++ b/lib/commands/help-search.js @@ -171,8 +171,8 @@ class HelpSearch extends BaseCommand { const finder = line.toLowerCase().split(arg.toLowerCase()) let p = 0 for (const f of finder) { - hilitLine.push(line.substr(p, f.length)) - const word = line.substr(p + f.length, arg.length) + hilitLine.push(line.slice(p, p + f.length)) + const word = line.slice(p + f.length, p + f.length + arg.length) const hilit = color.bgBlack(color.red(word)) hilitLine.push(hilit) p += f.length + arg.length |