Skip to content

Commit 7bd9c33

Browse files
committed
chore: replace deprecated String.prototype.substr()
.substr() is deprecated so we replace it with .slice() or substring() Both work similarily but aren't deprecated Signed-off-by: Tobias Speicher <rootcommander@gmail.com>
1 parent c960801 commit 7bd9c33

7 files changed

+15
-15
lines changed

Diff for: lib/AliasPlugin.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module.exports = class AliasPlugin {
4848
: resolver.join(item.name, "_").slice(0, -1)
4949
))
5050
) {
51-
const remainingRequest = innerRequest.substr(item.name.length);
51+
const remainingRequest = innerRequest.slice(item.name.length);
5252
const resolveWithAlias = (alias, callback) => {
5353
if (alias === false) {
5454
/** @type {ResolveRequest} */

Diff for: lib/DescriptionFilePlugin.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ module.exports = class DescriptionFilePlugin {
6363
return callback();
6464
}
6565
const relativePath =
66-
"." + path.substr(result.directory.length).replace(/\\/g, "/");
66+
"." + path.slice(result.directory.length).replace(/\\/g, "/");
6767
const obj = {
6868
...request,
6969
descriptionFilePath: result.path,

Diff for: lib/DescriptionFileUtils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ function cdUp(directory) {
162162
j = directory.lastIndexOf("\\");
163163
const p = i < 0 ? j : j < 0 ? i : i < j ? j : i;
164164
if (p < 0) return null;
165-
return directory.substr(0, p || 1);
165+
return directory.slice(0, p || 1);
166166
}
167167

168168
exports.loadDescriptionFile = loadDescriptionFile;

Diff for: lib/Resolver.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ const {
114114
* @returns {string} in camel case
115115
*/
116116
function toCamelCase(str) {
117-
return str.replace(/-([a-z])/g, str => str.substr(1).toUpperCase());
117+
return str.replace(/-([a-z])/g, str => str.slice(1).toUpperCase());
118118
}
119119

120120
class Resolver {
@@ -170,14 +170,14 @@ class Resolver {
170170
name = toCamelCase(name);
171171
if (/^before/.test(name)) {
172172
return /** @type {ResolveStepHook} */ (this.ensureHook(
173-
name[6].toLowerCase() + name.substr(7)
173+
name[6].toLowerCase() + name.slice(7)
174174
).withOptions({
175175
stage: -10
176176
}));
177177
}
178178
if (/^after/.test(name)) {
179179
return /** @type {ResolveStepHook} */ (this.ensureHook(
180-
name[5].toLowerCase() + name.substr(6)
180+
name[5].toLowerCase() + name.slice(6)
181181
).withOptions({
182182
stage: 10
183183
}));
@@ -203,14 +203,14 @@ class Resolver {
203203
name = toCamelCase(name);
204204
if (/^before/.test(name)) {
205205
return /** @type {ResolveStepHook} */ (this.getHook(
206-
name[6].toLowerCase() + name.substr(7)
206+
name[6].toLowerCase() + name.slice(7)
207207
).withOptions({
208208
stage: -10
209209
}));
210210
}
211211
if (/^after/.test(name)) {
212212
return /** @type {ResolveStepHook} */ (this.getHook(
213-
name[5].toLowerCase() + name.substr(6)
213+
name[5].toLowerCase() + name.slice(6)
214214
).withOptions({
215215
stage: 10
216216
}));
@@ -465,7 +465,7 @@ class Resolver {
465465
part.module = this.isModule(part.request);
466466
part.directory = this.isDirectory(part.request);
467467
if (part.directory) {
468-
part.request = part.request.substr(0, part.request.length - 1);
468+
part.request = part.request.slice(0, -1);
469469
}
470470
}
471471

Diff for: lib/ResolverFactory.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ function normalizeAlias(alias) {
136136

137137
if (/\$$/.test(key)) {
138138
obj.onlyModule = true;
139-
obj.name = key.substr(0, key.length - 1);
139+
obj.name = key.slice(0, -1);
140140
}
141141

142142
return obj;

Diff for: lib/getPaths.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ module.exports = function getPaths(path) {
1111
const paths = [path];
1212
const segments = [parts[parts.length - 1]];
1313
let part = parts[parts.length - 1];
14-
path = path.substr(0, path.length - part.length - 1);
14+
path = path.substring(0, path.length - part.length - 1);
1515
for (let i = parts.length - 2; i > 2; i -= 2) {
1616
paths.push(path);
1717
part = parts[i];
18-
path = path.substr(0, path.length - part.length) || "/";
19-
segments.push(part.substr(0, part.length - 1));
18+
path = path.substring(0, path.length - part.length) || "/";
19+
segments.push(part.slice(0, -1));
2020
}
2121
part = parts[1];
2222
segments.push(part);
@@ -32,6 +32,6 @@ module.exports.basename = function basename(path) {
3232
j = path.lastIndexOf("\\");
3333
const p = i < 0 ? j : j < 0 ? i : i < j ? j : i;
3434
if (p < 0) return null;
35-
const s = path.substr(p + 1);
35+
const s = path.slice(p + 1);
3636
return s;
3737
};

Diff for: tooling/format-file-header.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ for (const filePath of allFiles) {
149149
const update = current.update(...match);
150150
if (update !== match[0]) {
151151
newContent =
152-
newContent.substr(0, pos) +
152+
newContent.slice(0, pos) +
153153
update +
154154
newContent.slice(pos + match[0].length);
155155
pos += update.length;

0 commit comments

Comments
 (0)