From 24f1b73e7ed695f6078b1b7ab15a6e24835528a0 Mon Sep 17 00:00:00 2001 From: Tobias Speicher Date: Fri, 18 Mar 2022 01:47:03 +0100 Subject: [PATCH] chore: replace deprecated String.prototype.substr() .substr() is deprecated so we replace it with .slice() which works similarily but isn't deprecated Signed-off-by: Tobias Speicher --- lib/getHashDigest.js | 4 ++-- lib/interpolateName.js | 6 +++--- test/interpolateName.test.js | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/getHashDigest.js b/lib/getHashDigest.js index 600b86e..e7ad74f 100644 --- a/lib/getHashDigest.js +++ b/lib/getHashDigest.js @@ -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); } } diff --git a/lib/interpolateName.js b/lib/interpolateName.js index 71999c2..b244606 100644 --- a/lib/interpolateName.js +++ b/lib/interpolateName.js @@ -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) { @@ -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"); } @@ -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); } } diff --git a/test/interpolateName.test.js b/test/interpolateName.test.js index d84bf8e..0cc766c 100644 --- a/test/interpolateName.test.js +++ b/test/interpolateName.test.js @@ -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]; }