Skip to content

Commit 24f1b73

Browse files
committed
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 <[email protected]>
1 parent 9fe2381 commit 24f1b73

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

lib/getHashDigest.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ function getHashDigest(buffer, algorithm, digestType, maxLength) {
122122
digestType === "base58" ||
123123
digestType === "base62"
124124
) {
125-
return encodeBufferToBase(hash.digest(), digestType.substr(4), maxLength);
125+
return encodeBufferToBase(hash.digest(), digestType.slice(4), maxLength);
126126
} else {
127-
return hash.digest(digestType || "hex").substr(0, maxLength);
127+
return hash.digest(digestType || "hex").slice(0, maxLength);
128128
}
129129
}
130130

lib/interpolateName.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function interpolateName(loaderContext, name, options = {}) {
3333
let resourcePath = loaderContext.resourcePath;
3434

3535
if (parsed.ext) {
36-
ext = parsed.ext.substr(1);
36+
ext = parsed.ext.slice(1);
3737
}
3838

3939
if (parsed.dir) {
@@ -46,7 +46,7 @@ function interpolateName(loaderContext, name, options = {}) {
4646
.relative(context, resourcePath + "_")
4747
.replace(/\\/g, "/")
4848
.replace(/\.\.(\/)?/g, "_$1");
49-
directory = directory.substr(0, directory.length - 1);
49+
directory = directory.slice(0, -1);
5050
} else {
5151
directory = resourcePath.replace(/\\/g, "/").replace(/\.\.(\/)?/g, "_$1");
5252
}
@@ -64,7 +64,7 @@ function interpolateName(loaderContext, name, options = {}) {
6464
const hashIdx = query.indexOf("#");
6565

6666
if (hashIdx >= 0) {
67-
query = query.substr(0, hashIdx);
67+
query = query.slice(0, hashIdx);
6868
}
6969
}
7070

test/interpolateName.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ describe("interpolateName()", () => {
213213
const queryIdx = test[0].indexOf("?");
214214

215215
if (queryIdx >= 0) {
216-
resourcePath = test[0].substr(0, queryIdx);
217-
resourceQuery = test[0].substr(queryIdx);
216+
resourcePath = test[0].slice(0, queryIdx);
217+
resourceQuery = test[0].slice(queryIdx);
218218
} else {
219219
resourcePath = test[0];
220220
}

0 commit comments

Comments
 (0)