Skip to content

Commit fa5e00a

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 06fcc0a commit fa5e00a

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
@@ -125,12 +125,12 @@ function getHashDigest(buffer, algorithm, digestType, maxLength) {
125125
) {
126126
return encodeBufferToBase(
127127
hash.digest(),
128-
digestType === "base64safe" ? 64 : digestType.substr(4),
128+
digestType === "base64safe" ? 64 : digestType.slice(4),
129129
maxLength
130130
);
131131
}
132132

133-
return hash.digest(digestType || "hex").substr(0, maxLength);
133+
return hash.digest(digestType || "hex").slice(0, maxLength);
134134
}
135135

136136
module.exports = getHashDigest;

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
}
@@ -65,7 +65,7 @@ function interpolateName(loaderContext, name, options = {}) {
6565
const hashIdx = query.indexOf("#");
6666

6767
if (hashIdx >= 0) {
68-
query = query.substr(0, hashIdx);
68+
query = query.slice(0, hashIdx);
6969
}
7070
}
7171

test/interpolateName.test.js

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

221221
if (queryIdx >= 0) {
222-
resourcePath = test[0].substr(0, queryIdx);
223-
resourceQuery = test[0].substr(queryIdx);
222+
resourcePath = test[0].slice(0, queryIdx);
223+
resourceQuery = test[0].slice(queryIdx);
224224
} else {
225225
resourcePath = test[0];
226226
}

0 commit comments

Comments
 (0)