DEV: Replace deprecated String.prototype.substr() (#16233)

String.prototype.substr() is deprecated so we replace it with String.prototype.slice() which works similarily but isn't deprecated.

Signed-off-by: Tobias Speicher <rootcommander@gmail.com>
Co-authored-by: Jarek Radosz <jradosz@gmail.com>
This commit is contained in:
CommanderRoot
2022-04-01 17:35:17 +02:00
committed by GitHub
parent e30f13d850
commit 86a783b3ad
30 changed files with 52 additions and 51 deletions

View File

@@ -426,12 +426,12 @@ export function extractDataAttribute(str) {
return null;
}
const key = `data-${str.substr(0, sep)}`.toLowerCase();
const key = `data-${str.slice(0, sep)}`.toLowerCase();
if (!/^[A-Za-z]+[\w\-\:\.]*$/.test(key)) {
return null;
}
const value = str.substr(sep + 1);
const value = str.slice(sep + 1);
return [key, value];
}

View File

@@ -90,7 +90,7 @@ function getEmojiName(content, pos, state, inlineEmoji) {
if (content.charCodeAt(pos + length) === 58) {
// check for t2-t6
if (content.substr(pos + length + 1, 3).match(/t[2-6]:/)) {
if (content.slice(pos + length + 1, pos + length + 4).match(/t[2-6]:/)) {
length += 3;
}
break;
@@ -105,7 +105,7 @@ function getEmojiName(content, pos, state, inlineEmoji) {
return;
}
return content.substr(pos, length);
return content.slice(pos, pos + length);
}
// straight forward :smile: to emoji image

View File

@@ -38,13 +38,13 @@ export function textReplace(state, callback, skipAllLinks) {
if (token.type === "link_open" || token.type === "link_close") {
linkLevel -= token.nesting;
} else if (token.type === "html_inline") {
const openLink = token.content.substr(0, 2).toLowerCase();
const openLink = token.content.slice(0, 2).toLowerCase();
if (openLink === "<a") {
if (token.content.match(/^<a(\s.*)?>/i)) {
linkLevel++;
}
} else if (token.content.substr(0, 4).toLowerCase() === "</a>") {
} else if (token.content.slice(0, 4).toLowerCase() === "</a>") {
linkLevel--;
}
}

View File

@@ -23,12 +23,12 @@ const rule = {
let i;
for (i = 1; i < split.length; i++) {
if (split[i].indexOf("post:") === 0) {
postNumber = parseInt(split[i].substr(5), 10);
postNumber = parseInt(split[i].slice(5), 10);
continue;
}
if (split[i].indexOf("topic:") === 0) {
topicId = parseInt(split[i].substr(6), 10);
topicId = parseInt(split[i].slice(6), 10);
continue;
}