Skip to content

Commit

Permalink
fix: replace deprecated String.prototype.substr() (#314)
Browse files Browse the repository at this point in the history
.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>
  • Loading branch information
CommanderRoot and lukekarrys committed Oct 27, 2022
1 parent d9edb34 commit b003c64
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/create.js
Expand Up @@ -70,7 +70,7 @@ const addFilesSync = (p, files) => {
files.forEach(file => {
if (file.charAt(0) === '@') {
t({
file: path.resolve(p.cwd, file.substr(1)),
file: path.resolve(p.cwd, file.slice(1)),
sync: true,
noResume: true,
onentry: entry => p.add(entry),
Expand All @@ -87,7 +87,7 @@ const addFilesAsync = (p, files) => {
const file = files.shift()
if (file.charAt(0) === '@') {
return t({
file: path.resolve(p.cwd, file.substr(1)),
file: path.resolve(p.cwd, file.slice(1)),
noResume: true,
onentry: entry => p.add(entry),
}).then(_ => addFilesAsync(p, files))
Expand Down
6 changes: 3 additions & 3 deletions lib/header.js
Expand Up @@ -68,7 +68,7 @@ class Header {
if (this[TYPE] === '') {
this[TYPE] = '0'
}
if (this[TYPE] === '0' && this.path.substr(-1) === '/') {
if (this[TYPE] === '0' && this.path.slice(-1) === '/') {
this[TYPE] = '5'
}

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

// at this point, found no resolution, just truncate
if (!ret) {
ret = [p.substr(0, pathSize - 1), '', true]
ret = [p.slice(0, pathSize - 1), '', true]
}
}
return ret
Expand Down
2 changes: 1 addition & 1 deletion lib/pax.js
Expand Up @@ -132,7 +132,7 @@ const parseKVLine = (set, line) => {
return set
}

line = line.substr((n + ' ').length)
line = line.slice((n + ' ').length)
const kv = line.split('=')
const k = kv.shift().replace(/^SCHILY\.(dev|ino|nlink)/, '$1')
if (!k) {
Expand Down
4 changes: 2 additions & 2 deletions lib/replace.js
Expand Up @@ -217,7 +217,7 @@ const addFilesSync = (p, files) => {
files.forEach(file => {
if (file.charAt(0) === '@') {
t({
file: path.resolve(p.cwd, file.substr(1)),
file: path.resolve(p.cwd, file.slice(1)),
sync: true,
noResume: true,
onentry: entry => p.add(entry),
Expand All @@ -234,7 +234,7 @@ const addFilesAsync = (p, files) => {
const file = files.shift()
if (file.charAt(0) === '@') {
return t({
file: path.resolve(p.cwd, file.substr(1)),
file: path.resolve(p.cwd, file.slice(1)),
noResume: true,
onentry: entry => p.add(entry),
}).then(_ => addFilesAsync(p, files))
Expand Down
2 changes: 1 addition & 1 deletion lib/strip-absolute-path.js
Expand Up @@ -16,7 +16,7 @@ module.exports = path => {
// but strip the //?/C:/ off of //?/C:/path
const root = path.charAt(0) === '/' && path.slice(0, 4) !== '//?/' ? '/'
: parsed.root
path = path.substr(root.length)
path = path.slice(root.length)
r += root
parsed = parse(path)
}
Expand Down
4 changes: 2 additions & 2 deletions lib/unpack.js
Expand Up @@ -311,9 +311,9 @@ class Unpack extends Parser {
// only encode : chars that aren't drive letter indicators
if (this.win32) {
const { root: aRoot } = path.win32.parse(entry.absolute)
entry.absolute = aRoot + wc.encode(entry.absolute.substr(aRoot.length))
entry.absolute = aRoot + wc.encode(entry.absolute.slice(aRoot.length))
const { root: pRoot } = path.win32.parse(entry.path)
entry.path = pRoot + wc.encode(entry.path.substr(pRoot.length))
entry.path = pRoot + wc.encode(entry.path.slice(pRoot.length))
}

return true
Expand Down
2 changes: 1 addition & 1 deletion lib/write-entry.js
Expand Up @@ -205,7 +205,7 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
}

[DIRECTORY] () {
if (this.path.substr(-1) !== '/') {
if (this.path.slice(-1) !== '/') {
this.path += '/'
}
this.stat.size = 0
Expand Down
2 changes: 1 addition & 1 deletion test/unpack.js
Expand Up @@ -800,7 +800,7 @@ t.test('absolute paths', t => {
t.ok(path.isAbsolute(extraAbsolute))
t.ok(path.isAbsolute(absolute))
const parsed = path.parse(absolute)
const relative = absolute.substr(parsed.root.length)
const relative = absolute.slice(parsed.root.length)
t.notOk(path.isAbsolute(relative))

const data = makeTar([
Expand Down
2 changes: 1 addition & 1 deletion test/write-entry.js
Expand Up @@ -691,7 +691,7 @@ t.test('win32 <|>? in paths', {
wc.on('data', c => out.push(c))
wc.on('end', _ => {
const data = Buffer.concat(out).toString()
t.equal(data.substr(0, 4), '<|>?')
t.equal(data.slice(0, 4), '<|>?')
t.end()
})

Expand Down

0 comments on commit b003c64

Please sign in to comment.