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

@ -165,8 +165,8 @@ exports.handler = async (event, context, callback) => {
.forEach(page => {
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));
if (size > 10000) {
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

@ -11,10 +11,10 @@ export const countryToFlag = (isoCode: string) => {
};
/*
Returns formatted value with maximum number of decimals based on decimalsInCurrency value
Returns formatted value with maximum number of decimals based on decimalsInCurrency value
and add commas based on user's locale
for eg:
a) (2, 1235.456) will return 1,235.45
a) (2, 1235.456) will return 1,235.45
b) (1, 1234.456) will return 1,234.4
*/
export const formatCurrencyNumber = (decimalsInCurrency = 0, value: string) => {
@ -34,7 +34,7 @@ export const formatCurrencyNumber = (decimalsInCurrency = 0, value: string) => {
/*
Returns value in string format with maximum number of decimals based on decimalsInCurrency value
for eg:
a) (2, 1235.456) will return 1235.45
a) (2, 1235.456) will return 1235.45
b) (1, 1234.456) will return 1234.4
*/
export const limitDecimalValue = (decimals = 0, value = "") => {
@ -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

@ -9,10 +9,10 @@ export const countryToFlag = (isoCode: string) => {
};
/*
Returns formatted value with maximum number of decimals based on decimalsInCurrency value
Returns formatted value with maximum number of decimals based on decimalsInCurrency value
and add commas based on user's local browser
for eg:
a) (2, 1235.456) will return 1,234.56
a) (2, 1235.456) will return 1,234.56
b) (1, 1234.456) will return 1,234.5
*/
export const formatCurrencyNumber = (
@ -48,7 +48,7 @@ export const formatCurrencyNumber = (
/*
Returns number in string format with maximum number of decimals based on decimalsInCurrency value
for eg:
a) (2, 1235.456) will return 1234.56
a) (2, 1235.456) will return 1234.56
b) (1, 1234.456) will return 1234.5
*/
export const limitDecimalValue = (
@ -68,7 +68,7 @@ export const limitDecimalValue = (
value =
decimalValueArray[0] +
decimalSeparator +
decimalValueArray[1].substr(0, decimalsInCurrency);
decimalValueArray[1].slice(0, decimalsInCurrency);
}
return value;
} else {
@ -78,7 +78,7 @@ export const limitDecimalValue = (
/*
Return the type of decimal separator for decimal digit numbers
eg:
eg:
getDecimalSeparator("en-US") will return "."
getDecimalSeparator("fr-FR") will return ","
*/
@ -94,7 +94,7 @@ export const getDecimalSeparator = (locale: string) => {
/*
Return the type of decimal separator for decimal digit numbers
eg:
eg:
getGroupSeparator("en-US") will return ","
getGroupSeparator("fr-FR") will return " "
*/

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;