Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorCommanderRoot <CommanderRoot@users.noreply.github.com>2022-04-04 21:08:43 +0300
committerGitHub <noreply@github.com>2022-04-04 21:08:43 +0300
commite3da5df4152fbe547f7871547165328e1bf06262 (patch)
tree273fd46ffb39ca4499af4a5b6a8807ba2b32b382 /lib
parent44108f7be5e1e928d8aa3eda3c5c177bcd216c99 (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')
-rw-r--r--lib/commands/cache.js2
-rw-r--r--lib/commands/completion.js6
-rw-r--r--lib/commands/doctor.js4
-rw-r--r--lib/commands/help-search.js4
-rw-r--r--lib/search/format-package-stream.js6
-rw-r--r--lib/search/package-filter.js2
-rw-r--r--lib/utils/config/definition.js2
-rw-r--r--lib/utils/npm-usage.js2
-rw-r--r--lib/utils/tar.js4
9 files changed, 16 insertions, 16 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
diff --git a/lib/search/format-package-stream.js b/lib/search/format-package-stream.js
index 7ff44e9e2..acead79e1 100644
--- a/lib/search/format-package-stream.js
+++ b/lib/search/format-package-stream.js
@@ -111,7 +111,7 @@ function addColorMarker (str, arg, i) {
if (arg.charAt(0) === '/') {
return str.replace(
- new RegExp(arg.substr(1, arg.length - 2), 'gi'),
+ new RegExp(arg.slice(1, -1), 'gi'),
bit => markStart + bit + markEnd
)
}
@@ -121,9 +121,9 @@ function addColorMarker (str, arg, i) {
var p = 0
return pieces.map(function (piece) {
- piece = str.substr(p, piece.length)
+ piece = str.slice(p, p + piece.length)
var mark = markStart +
- str.substr(p + piece.length, arg.length) +
+ str.slice(p + piece.length, p + piece.length + arg.length) +
markEnd
p += piece.length + arg.length
return piece + mark
diff --git a/lib/search/package-filter.js b/lib/search/package-filter.js
index 45a67835b..bb0ae679b 100644
--- a/lib/search/package-filter.js
+++ b/lib/search/package-filter.js
@@ -36,7 +36,7 @@ function filterWords (data, include, exclude, opts) {
function match (words, pattern) {
if (pattern.charAt(0) === '/') {
pattern = pattern.replace(/\/$/, '')
- pattern = new RegExp(pattern.substr(1, pattern.length - 1))
+ pattern = new RegExp(pattern.slice(1))
return words.match(pattern)
}
return words.indexOf(pattern) !== -1
diff --git a/lib/utils/config/definition.js b/lib/utils/config/definition.js
index fc46bc3d6..f88d8334c 100644
--- a/lib/utils/config/definition.js
+++ b/lib/utils/config/definition.js
@@ -233,7 +233,7 @@ const wrapAll = s => {
return (
'* ' +
block
- .substr(1)
+ .slice(1)
.trim()
.split('\n* ')
.map(li => {
diff --git a/lib/utils/npm-usage.js b/lib/utils/npm-usage.js
index 8d31f0155..431995ecf 100644
--- a/lib/utils/npm-usage.js
+++ b/lib/utils/npm-usage.js
@@ -53,7 +53,7 @@ const wrap = (arr) => {
out[l] = c
}
}
- return out.join('\n ').substr(2)
+ return out.join('\n ').slice(2)
}
const usages = async (npm) => {
diff --git a/lib/utils/tar.js b/lib/utils/tar.js
index 2f2773c6d..0a74ce8c4 100644
--- a/lib/utils/tar.js
+++ b/lib/utils/tar.js
@@ -48,9 +48,9 @@ const logTar = (tarball, opts = {}) => {
{
name: 'integrity:',
value:
- tarball.integrity.toString().substr(0, 20) +
+ tarball.integrity.toString().slice(0, 20) +
'[...]' +
- tarball.integrity.toString().substr(80),
+ tarball.integrity.toString().slice(80),
},
tarball.bundled.length && { name: 'bundled deps:', value: tarball.bundled.length },
tarball.bundled.length && {