Skip to content

Commit d9ed56f

Browse files
refactor: replace deprecated String.prototype.substr() (#1227)
1 parent 19dc401 commit d9ed56f

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/utils/getFilenameFromUrl.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function getFilenameFromUrl(context, url) {
8686

8787
// Strip the `pathname` property from the `publicPath` option from the start of requested url
8888
// `/complex/foo.js` => `foo.js`
89-
const pathname = urlObject.pathname.substr(
89+
const pathname = urlObject.pathname.slice(
9090
publicPathObject.pathname.length
9191
);
9292

src/utils/setupWriteToDisk.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function setupWriteToDisk(context) {
5353
const queryStringIdx = targetFile.indexOf("?");
5454

5555
if (queryStringIdx >= 0) {
56-
targetFile = targetFile.substr(0, queryStringIdx);
56+
targetFile = targetFile.slice(0, queryStringIdx);
5757
}
5858

5959
let { outputPath } = compiler;

test/middleware.test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ describe.each([
281281
expect(response.headers["content-type"]).toEqual(
282282
"application/javascript; charset=utf-8"
283283
);
284-
expect(response.text).toBe(codeContent.substr(3000, 501));
284+
expect(response.text).toBe(codeContent.slice(3000, 3501));
285285
expect(response.text.length).toBe(501);
286286
});
287287

@@ -314,7 +314,7 @@ describe.each([
314314
expect(response.headers["content-type"]).toEqual(
315315
"application/javascript; charset=utf-8"
316316
);
317-
expect(response.text).toBe(codeContent.substr(3000, 501));
317+
expect(response.text).toBe(codeContent.slice(3000, 3501));
318318
expect(response.text.length).toBe(501);
319319
});
320320

@@ -331,7 +331,7 @@ describe.each([
331331
expect(response.headers["content-type"]).toEqual(
332332
"application/javascript; charset=utf-8"
333333
);
334-
expect(response.text).toBe(codeContent.substr(3000, 501));
334+
expect(response.text).toBe(codeContent.slice(3000, 3501));
335335
expect(response.text.length).toBe(501);
336336
});
337337

@@ -348,7 +348,7 @@ describe.each([
348348
expect(response.headers["content-type"]).toEqual(
349349
"application/javascript; charset=utf-8"
350350
);
351-
expect(response.text).toBe(codeContent.substr(0, 3501));
351+
expect(response.text).toBe(codeContent.slice(0, 3501));
352352
expect(response.text.length).toBe(3501);
353353
});
354354

@@ -365,7 +365,7 @@ describe.each([
365365
expect(response.headers["content-type"]).toEqual(
366366
"application/javascript; charset=utf-8"
367367
);
368-
expect(response.text).toBe(codeContent.substr(0, 801));
368+
expect(response.text).toBe(codeContent.slice(0, 801));
369369
expect(response.text.length).toBe(801);
370370
});
371371

0 commit comments

Comments
 (0)