Skip to content

Commit

Permalink
chore: replace deprecated String.prototype.substr()
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>
  • Loading branch information
CommanderRoot committed Mar 18, 2022
1 parent 9fe2381 commit 24f1b73
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/getHashDigest.js
Expand Up @@ -122,9 +122,9 @@ function getHashDigest(buffer, algorithm, digestType, maxLength) {
digestType === "base58" ||
digestType === "base62"
) {
return encodeBufferToBase(hash.digest(), digestType.substr(4), maxLength);
return encodeBufferToBase(hash.digest(), digestType.slice(4), maxLength);
} else {
return hash.digest(digestType || "hex").substr(0, maxLength);
return hash.digest(digestType || "hex").slice(0, maxLength);
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/interpolateName.js
Expand Up @@ -33,7 +33,7 @@ function interpolateName(loaderContext, name, options = {}) {
let resourcePath = loaderContext.resourcePath;

if (parsed.ext) {
ext = parsed.ext.substr(1);
ext = parsed.ext.slice(1);
}

if (parsed.dir) {
Expand All @@ -46,7 +46,7 @@ function interpolateName(loaderContext, name, options = {}) {
.relative(context, resourcePath + "_")
.replace(/\\/g, "/")
.replace(/\.\.(\/)?/g, "_$1");
directory = directory.substr(0, directory.length - 1);
directory = directory.slice(0, -1);
} else {
directory = resourcePath.replace(/\\/g, "/").replace(/\.\.(\/)?/g, "_$1");
}
Expand All @@ -64,7 +64,7 @@ function interpolateName(loaderContext, name, options = {}) {
const hashIdx = query.indexOf("#");

if (hashIdx >= 0) {
query = query.substr(0, hashIdx);
query = query.slice(0, hashIdx);
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/interpolateName.test.js
Expand Up @@ -213,8 +213,8 @@ describe("interpolateName()", () => {
const queryIdx = test[0].indexOf("?");

if (queryIdx >= 0) {
resourcePath = test[0].substr(0, queryIdx);
resourceQuery = test[0].substr(queryIdx);
resourcePath = test[0].slice(0, queryIdx);
resourceQuery = test[0].slice(queryIdx);
} else {
resourcePath = test[0];
}
Expand Down

0 comments on commit 24f1b73

Please sign in to comment.