Skip to content

Commit e3da5df

Browse files
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 <[email protected]>
1 parent 44108f7 commit e3da5df

File tree

17 files changed

+28
-28
lines changed

17 files changed

+28
-28
lines changed

lib/commands/cache.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class Cache extends BaseCommand {
177177
async verify () {
178178
const cache = path.join(this.npm.cache, '_cacache')
179179
const prefix = cache.indexOf(process.env.HOME) === 0
180-
? `~${cache.substr(process.env.HOME.length)}`
180+
? `~${cache.slice(process.env.HOME.length)}`
181181
: cache
182182
const stats = await cacache.verify(cache)
183183
this.npm.output(`Cache verified and compressed (${prefix})`)

lib/commands/completion.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,17 @@ class Completion extends BaseCommand {
9797
const word = words[w]
9898
const line = COMP_LINE
9999
const point = +COMP_POINT
100-
const partialLine = line.substr(0, point)
100+
const partialLine = line.slice(0, point)
101101
const partialWords = words.slice(0, w)
102102

103103
// figure out where in that last word the point is.
104104
const partialWordRaw = args[w]
105105
let i = partialWordRaw.length
106-
while (partialWordRaw.substr(0, i) !== partialLine.substr(-1 * i) && i > 0) {
106+
while (partialWordRaw.slice(0, i) !== partialLine.slice(-1 * i) && i > 0) {
107107
i--
108108
}
109109

110-
const partialWord = unescape(partialWordRaw.substr(0, i))
110+
const partialWord = unescape(partialWordRaw.slice(0, i))
111111
partialWords.push(partialWord)
112112

113113
const opts = {

lib/commands/doctor.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class Doctor extends BaseCommand {
145145
return ''
146146
} catch (er) {
147147
if (/^E\d{3}$/.test(er.code || '')) {
148-
throw er.code.substr(1) + ' ' + er.message
148+
throw er.code.slice(1) + ' ' + er.message
149149
} else {
150150
throw er.message
151151
}
@@ -211,7 +211,7 @@ class Doctor extends BaseCommand {
211211
const gid = process.getgid()
212212
const files = new Set([root])
213213
for (const f of files) {
214-
tracker.silly('checkFilesPermission', f.substr(root.length + 1))
214+
tracker.silly('checkFilesPermission', f.slice(root.length + 1))
215215
const st = await lstat(f).catch(er => {
216216
// if it can't be missing, or if it can and the error wasn't that it was missing
217217
if (!missingOk || er.code !== 'ENOENT') {

lib/commands/help-search.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ class HelpSearch extends BaseCommand {
171171
const finder = line.toLowerCase().split(arg.toLowerCase())
172172
let p = 0
173173
for (const f of finder) {
174-
hilitLine.push(line.substr(p, f.length))
175-
const word = line.substr(p + f.length, arg.length)
174+
hilitLine.push(line.slice(p, p + f.length))
175+
const word = line.slice(p + f.length, p + f.length + arg.length)
176176
const hilit = color.bgBlack(color.red(word))
177177
hilitLine.push(hilit)
178178
p += f.length + arg.length

lib/search/format-package-stream.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function addColorMarker (str, arg, i) {
111111

112112
if (arg.charAt(0) === '/') {
113113
return str.replace(
114-
new RegExp(arg.substr(1, arg.length - 2), 'gi'),
114+
new RegExp(arg.slice(1, -1), 'gi'),
115115
bit => markStart + bit + markEnd
116116
)
117117
}
@@ -121,9 +121,9 @@ function addColorMarker (str, arg, i) {
121121
var p = 0
122122

123123
return pieces.map(function (piece) {
124-
piece = str.substr(p, piece.length)
124+
piece = str.slice(p, p + piece.length)
125125
var mark = markStart +
126-
str.substr(p + piece.length, arg.length) +
126+
str.slice(p + piece.length, p + piece.length + arg.length) +
127127
markEnd
128128
p += piece.length + arg.length
129129
return piece + mark

lib/search/package-filter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function filterWords (data, include, exclude, opts) {
3636
function match (words, pattern) {
3737
if (pattern.charAt(0) === '/') {
3838
pattern = pattern.replace(/\/$/, '')
39-
pattern = new RegExp(pattern.substr(1, pattern.length - 1))
39+
pattern = new RegExp(pattern.slice(1))
4040
return words.match(pattern)
4141
}
4242
return words.indexOf(pattern) !== -1

lib/utils/config/definition.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ const wrapAll = s => {
233233
return (
234234
'* ' +
235235
block
236-
.substr(1)
236+
.slice(1)
237237
.trim()
238238
.split('\n* ')
239239
.map(li => {

lib/utils/npm-usage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const wrap = (arr) => {
5353
out[l] = c
5454
}
5555
}
56-
return out.join('\n ').substr(2)
56+
return out.join('\n ').slice(2)
5757
}
5858

5959
const usages = async (npm) => {

lib/utils/tar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ const logTar = (tarball, opts = {}) => {
4848
{
4949
name: 'integrity:',
5050
value:
51-
tarball.integrity.toString().substr(0, 20) +
51+
tarball.integrity.toString().slice(0, 20) +
5252
'[...]' +
53-
tarball.integrity.toString().substr(80),
53+
tarball.integrity.toString().slice(80),
5454
},
5555
tarball.bundled.length && { name: 'bundled deps:', value: tarball.bundled.length },
5656
tarball.bundled.length && {

workspaces/arborist/lib/retire-path.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const pathSafeHash = s =>
77
.update(s)
88
.digest('base64')
99
.replace(/[^a-zA-Z0-9]+/g, '')
10-
.substr(0, 8)
10+
.slice(0, 8)
1111

1212
const retirePath = from => {
1313
const d = dirname(from)

0 commit comments

Comments
 (0)