Skip to content

Commit

Permalink
Merge pull request #336 from CommanderRoot/rm-deprecated-substr
Browse files Browse the repository at this point in the history
chore: replace deprecated String.prototype.substr()
  • Loading branch information
TheLarkInn committed May 9, 2023
2 parents 35af1c4 + 7bd9c33 commit b967209
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/AliasPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module.exports = class AliasPlugin {
? innerRequest.startsWith(`${item.name}/`)
: isSubPath(innerRequest, item.name)))
) {
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 @@ -126,7 +126,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 @@ -182,14 +182,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 @@ -215,14 +215,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 @@ -477,7 +477,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 @@ -141,7 +141,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

0 comments on commit b967209

Please sign in to comment.