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

String.prototype.substr() is deprecated (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr) so we replace it with slice() which works similarily but isn't deprecated

Signed-off-by: Tobias Speicher <rootcommander@gmail.com>
This commit is contained in:
CommanderRoot 2022-04-13 09:00:38 +02:00 committed by GitHub
parent 4cd69fe4d8
commit a778a98016
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 23 additions and 23 deletions

View File

@ -387,7 +387,7 @@ Cypress.Commands.add(
element: true,
},
($element, text) => {
const subString = text.substr(0, text.length - 1);
const subString = text.slice(0, -1);
const lastChar = text.slice(-1);
cy.get(commonlocators.entityExplorersearch)

View File

@ -166,7 +166,7 @@ exports.handler = async (event, context, callback) => {
if (page.markdown) {
const size = JSON.stringify(page).length;
if (size > 10000) {
page.markdown = page.markdown.substr(0, page.markdown.length - (JSON.stringify(page).length - 9900));
page.markdown = page.markdown.slice(0, -(size - 9900));
}
if (orderMap[page.path]) {
page.isDefault = true;

View File

@ -12,7 +12,7 @@ export const getIndexOfRegex = (
regex: RegExp,
start = 0,
): number => {
const pos = str.substr(start).search(regex);
const pos = str.slice(start).search(regex);
return pos > -1 ? pos + start : pos;
};
@ -44,7 +44,7 @@ export const getKeyPositionInString = (
let positions: Position[] = [];
if (str.includes("\n")) {
for (const index of indices) {
const substr = str.substr(0, index);
const substr = str.slice(0, index);
const substrLines = substr.split("\n");
const ch = last(substrLines)?.length || 0;
const line = substrLines.length - 1;
@ -103,7 +103,7 @@ export const getLintAnnotations = (
bindingLocation.line !== currentLine ? ch : bindingLocation.ch + ch;
// Jshint counts \t as two characters and codemirror counts it as 1.
// So we need to subtract number of tabs to get accurate position
const tabs = lineContent.substr(0, currentCh).match(/\t/g)?.length || 0;
const tabs = lineContent.slice(0, currentCh).match(/\t/g)?.length || 0;
const from = {
line: currentLine,

View File

@ -255,7 +255,7 @@ export const actionPathFromName = (
const ActionConfigStarts = "actionConfiguration.";
let path = name;
if (path.startsWith(ActionConfigStarts)) {
path = "config." + path.substr(ActionConfigStarts.length);
path = "config." + path.slice(ActionConfigStarts.length);
}
return `${actionName}.${path}`;
};

View File

@ -74,7 +74,7 @@ function WidgetsEditor() {
window.location.hash.length > 0 &&
!guidedTourEnabled
) {
const widgetIdFromURLHash = window.location.hash.substr(1);
const widgetIdFromURLHash = window.location.hash.slice(1);
flashElementsById(widgetIdFromURLHash);
if (document.getElementById(widgetIdFromURLHash))
selectWidget(widgetIdFromURLHash);

View File

@ -106,7 +106,7 @@ export default function Settings() {
let newUrl = "";
if (hasSlash) {
newUrl = `${location.pathname.substr(0, settingsEndIndex)}/${
newUrl = `${location.pathname.slice(0, settingsEndIndex)}/${
tabArr[index].key
}`;
} else {

View File

@ -26,7 +26,7 @@ export function parseUrlForQueryParams(url: string) {
const matchGroup = url.match(queryParamsRegEx) || [];
const parsedUrlWithQueryParams = matchGroup[2] || "";
if (parsedUrlWithQueryParams.indexOf("?") > -1) {
const paramsString = parsedUrlWithQueryParams.substr(
const paramsString = parsedUrlWithQueryParams.slice(
parsedUrlWithQueryParams.indexOf("?") + 1,
);
params = paramsString.split("&").map((p) => {

View File

@ -49,7 +49,7 @@ export const limitDecimalValue = (decimals = 0, value = "") => {
return (
decimalValueArray[0] +
decimalSeperator +
decimalValueArray[1].substr(0, decimals)
decimalValueArray[1].slice(0, decimals)
);
default:
return value;

View File

@ -23,7 +23,7 @@ const ErrorWrapper = styled.div`
const checkUrlExtension = (docUrl: string) => {
// Remove everything to the last slash in URL
let url = docUrl.substr(1 + docUrl.lastIndexOf("/"));
let url = docUrl.slice(1 + docUrl.lastIndexOf("/"));
// Break URL at ? and take first part (file name, extension)
url = url.split("?")[0];
// Sometimes URL doesn't have ? but #, so we should aslo do the same for #

View File

@ -68,7 +68,7 @@ export const limitDecimalValue = (
value =
decimalValueArray[0] +
decimalSeparator +
decimalValueArray[1].substr(0, decimalsInCurrency);
decimalValueArray[1].slice(0, decimalsInCurrency);
}
return value;
} else {

View File

@ -20,7 +20,7 @@ export const getPositionInEvaluationScript = (
const script = EvaluationScripts[type];
const index = script.indexOf(ScriptTemplate);
const substr = script.substr(0, index);
const substr = script.slice(0, index !== -1 ? index : 0);
const lines = substr.split("\n");
const lastLine = last(lines) || "";

View File

@ -332,7 +332,7 @@ async function watchMongoDB(io) {
}
// set the type from _class attribute
notification.type = notification._class.substr(notification._class.lastIndexOf(".") + 1);
notification.type = notification._class.slice(notification._class.lastIndexOf(".") + 1);
delete notification._class;
const eventName = event.operationType + ":" + event.ns.coll;