Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: replace deprecated String.prototype.substr() #336

Merged
merged 1 commit into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/AliasPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = class AliasPlugin {
: resolver.join(item.name, "_").slice(0, -1)
))
) {
const remainingRequest = innerRequest.substr(item.name.length);
const remainingRequest = innerRequest.slice(item.name.length);
const resolveWithAlias = (alias, callback) => {
if (alias === false) {
/** @type {ResolveRequest} */
Expand Down
2 changes: 1 addition & 1 deletion lib/DescriptionFilePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module.exports = class DescriptionFilePlugin {
return callback();
}
const relativePath =
"." + path.substr(result.directory.length).replace(/\\/g, "/");
"." + path.slice(result.directory.length).replace(/\\/g, "/");
const obj = {
...request,
descriptionFilePath: result.path,
Expand Down
2 changes: 1 addition & 1 deletion lib/DescriptionFileUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function cdUp(directory) {
j = directory.lastIndexOf("\\");
const p = i < 0 ? j : j < 0 ? i : i < j ? j : i;
if (p < 0) return null;
return directory.substr(0, p || 1);
return directory.slice(0, p || 1);
}

exports.loadDescriptionFile = loadDescriptionFile;
Expand Down
12 changes: 6 additions & 6 deletions lib/Resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const {
* @returns {string} in camel case
*/
function toCamelCase(str) {
return str.replace(/-([a-z])/g, str => str.substr(1).toUpperCase());
return str.replace(/-([a-z])/g, str => str.slice(1).toUpperCase());
}

class Resolver {
Expand Down Expand Up @@ -170,14 +170,14 @@ class Resolver {
name = toCamelCase(name);
if (/^before/.test(name)) {
return /** @type {ResolveStepHook} */ (this.ensureHook(
name[6].toLowerCase() + name.substr(7)
name[6].toLowerCase() + name.slice(7)
).withOptions({
stage: -10
}));
}
if (/^after/.test(name)) {
return /** @type {ResolveStepHook} */ (this.ensureHook(
name[5].toLowerCase() + name.substr(6)
name[5].toLowerCase() + name.slice(6)
).withOptions({
stage: 10
}));
Expand All @@ -203,14 +203,14 @@ class Resolver {
name = toCamelCase(name);
if (/^before/.test(name)) {
return /** @type {ResolveStepHook} */ (this.getHook(
name[6].toLowerCase() + name.substr(7)
name[6].toLowerCase() + name.slice(7)
).withOptions({
stage: -10
}));
}
if (/^after/.test(name)) {
return /** @type {ResolveStepHook} */ (this.getHook(
name[5].toLowerCase() + name.substr(6)
name[5].toLowerCase() + name.slice(6)
).withOptions({
stage: 10
}));
Expand Down Expand Up @@ -465,7 +465,7 @@ class Resolver {
part.module = this.isModule(part.request);
part.directory = this.isDirectory(part.request);
if (part.directory) {
part.request = part.request.substr(0, part.request.length - 1);
part.request = part.request.slice(0, -1);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/ResolverFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function normalizeAlias(alias) {

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

return obj;
Expand Down
8 changes: 4 additions & 4 deletions lib/getPaths.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ module.exports = function getPaths(path) {
const paths = [path];
const segments = [parts[parts.length - 1]];
let part = parts[parts.length - 1];
path = path.substr(0, path.length - part.length - 1);
path = path.substring(0, path.length - part.length - 1);
for (let i = parts.length - 2; i > 2; i -= 2) {
paths.push(path);
part = parts[i];
path = path.substr(0, path.length - part.length) || "/";
segments.push(part.substr(0, part.length - 1));
path = path.substring(0, path.length - part.length) || "/";
segments.push(part.slice(0, -1));
}
part = parts[1];
segments.push(part);
Expand All @@ -32,6 +32,6 @@ module.exports.basename = function basename(path) {
j = path.lastIndexOf("\\");
const p = i < 0 ? j : j < 0 ? i : i < j ? j : i;
if (p < 0) return null;
const s = path.substr(p + 1);
const s = path.slice(p + 1);
return s;
};
2 changes: 1 addition & 1 deletion tooling/format-file-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ for (const filePath of allFiles) {
const update = current.update(...match);
if (update !== match[0]) {
newContent =
newContent.substr(0, pos) +
newContent.slice(0, pos) +
update +
newContent.slice(pos + match[0].length);
pos += update.length;
Expand Down