Skip to content

Commit b003c64

Browse files
CommanderRootlukekarrys
andauthoredOct 27, 2022
fix: replace deprecated String.prototype.substr() (#314)
.substr() is deprecated so we replace it with .slice() which works similarily but isn't deprecated Signed-off-by: Tobias Speicher <rootcommander@gmail.com> Co-authored-by: Luke Karrys <luke@lukekarrys.com>
1 parent d9edb34 commit b003c64

9 files changed

+14
-14
lines changed
 

‎lib/create.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const addFilesSync = (p, files) => {
7070
files.forEach(file => {
7171
if (file.charAt(0) === '@') {
7272
t({
73-
file: path.resolve(p.cwd, file.substr(1)),
73+
file: path.resolve(p.cwd, file.slice(1)),
7474
sync: true,
7575
noResume: true,
7676
onentry: entry => p.add(entry),
@@ -87,7 +87,7 @@ const addFilesAsync = (p, files) => {
8787
const file = files.shift()
8888
if (file.charAt(0) === '@') {
8989
return t({
90-
file: path.resolve(p.cwd, file.substr(1)),
90+
file: path.resolve(p.cwd, file.slice(1)),
9191
noResume: true,
9292
onentry: entry => p.add(entry),
9393
}).then(_ => addFilesAsync(p, files))

‎lib/header.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class Header {
6868
if (this[TYPE] === '') {
6969
this[TYPE] = '0'
7070
}
71-
if (this[TYPE] === '0' && this.path.substr(-1) === '/') {
71+
if (this[TYPE] === '0' && this.path.slice(-1) === '/') {
7272
this[TYPE] = '5'
7373
}
7474

@@ -232,7 +232,7 @@ const splitPrefix = (p, prefixSize) => {
232232
} else if (Buffer.byteLength(pp) > pathSize &&
233233
Buffer.byteLength(prefix) <= prefixSize) {
234234
// prefix fits in prefix, but path doesn't fit in path
235-
ret = [pp.substr(0, pathSize - 1), prefix, true]
235+
ret = [pp.slice(0, pathSize - 1), prefix, true]
236236
} else {
237237
// make path take a bit from prefix
238238
pp = pathModule.join(pathModule.basename(prefix), pp)
@@ -242,7 +242,7 @@ const splitPrefix = (p, prefixSize) => {
242242

243243
// at this point, found no resolution, just truncate
244244
if (!ret) {
245-
ret = [p.substr(0, pathSize - 1), '', true]
245+
ret = [p.slice(0, pathSize - 1), '', true]
246246
}
247247
}
248248
return ret

‎lib/pax.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ const parseKVLine = (set, line) => {
132132
return set
133133
}
134134

135-
line = line.substr((n + ' ').length)
135+
line = line.slice((n + ' ').length)
136136
const kv = line.split('=')
137137
const k = kv.shift().replace(/^SCHILY\.(dev|ino|nlink)/, '$1')
138138
if (!k) {

‎lib/replace.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ const addFilesSync = (p, files) => {
217217
files.forEach(file => {
218218
if (file.charAt(0) === '@') {
219219
t({
220-
file: path.resolve(p.cwd, file.substr(1)),
220+
file: path.resolve(p.cwd, file.slice(1)),
221221
sync: true,
222222
noResume: true,
223223
onentry: entry => p.add(entry),
@@ -234,7 +234,7 @@ const addFilesAsync = (p, files) => {
234234
const file = files.shift()
235235
if (file.charAt(0) === '@') {
236236
return t({
237-
file: path.resolve(p.cwd, file.substr(1)),
237+
file: path.resolve(p.cwd, file.slice(1)),
238238
noResume: true,
239239
onentry: entry => p.add(entry),
240240
}).then(_ => addFilesAsync(p, files))

‎lib/strip-absolute-path.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = path => {
1616
// but strip the //?/C:/ off of //?/C:/path
1717
const root = path.charAt(0) === '/' && path.slice(0, 4) !== '//?/' ? '/'
1818
: parsed.root
19-
path = path.substr(root.length)
19+
path = path.slice(root.length)
2020
r += root
2121
parsed = parse(path)
2222
}

‎lib/unpack.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,9 @@ class Unpack extends Parser {
311311
// only encode : chars that aren't drive letter indicators
312312
if (this.win32) {
313313
const { root: aRoot } = path.win32.parse(entry.absolute)
314-
entry.absolute = aRoot + wc.encode(entry.absolute.substr(aRoot.length))
314+
entry.absolute = aRoot + wc.encode(entry.absolute.slice(aRoot.length))
315315
const { root: pRoot } = path.win32.parse(entry.path)
316-
entry.path = pRoot + wc.encode(entry.path.substr(pRoot.length))
316+
entry.path = pRoot + wc.encode(entry.path.slice(pRoot.length))
317317
}
318318

319319
return true

‎lib/write-entry.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
205205
}
206206

207207
[DIRECTORY] () {
208-
if (this.path.substr(-1) !== '/') {
208+
if (this.path.slice(-1) !== '/') {
209209
this.path += '/'
210210
}
211211
this.stat.size = 0

‎test/unpack.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ t.test('absolute paths', t => {
800800
t.ok(path.isAbsolute(extraAbsolute))
801801
t.ok(path.isAbsolute(absolute))
802802
const parsed = path.parse(absolute)
803-
const relative = absolute.substr(parsed.root.length)
803+
const relative = absolute.slice(parsed.root.length)
804804
t.notOk(path.isAbsolute(relative))
805805

806806
const data = makeTar([

‎test/write-entry.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ t.test('win32 <|>? in paths', {
691691
wc.on('data', c => out.push(c))
692692
wc.on('end', _ => {
693693
const data = Buffer.concat(out).toString()
694-
t.equal(data.substr(0, 4), '<|>?')
694+
t.equal(data.slice(0, 4), '<|>?')
695695
t.end()
696696
})
697697

0 commit comments

Comments
 (0)
Please sign in to comment.