Refactor: Replace deprecated String#substr() (#541)

This commit is contained in:
CommanderRoot 2022-03-27 20:11:02 +02:00 committed by GitHub
parent bccde97f8a
commit d28690e66b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -9,7 +9,7 @@ export function stringReplaceAll(string, substring, replacer) {
let endIndex = 0; let endIndex = 0;
let returnValue = ''; let returnValue = '';
do { do {
returnValue += string.substr(endIndex, index - endIndex) + substring + replacer; returnValue += string.slice(endIndex, index) + substring + replacer;
endIndex = index + substringLength; endIndex = index + substringLength;
index = string.indexOf(substring, endIndex); index = string.indexOf(substring, endIndex);
} while (index !== -1); } while (index !== -1);
@ -23,7 +23,7 @@ export function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
let returnValue = ''; let returnValue = '';
do { do {
const gotCR = string[index - 1] === '\r'; const gotCR = string[index - 1] === '\r';
returnValue += string.substr(endIndex, (gotCR ? index - 1 : index) - endIndex) + prefix + (gotCR ? '\r\n' : '\n') + postfix; returnValue += string.slice(endIndex, (gotCR ? index - 1 : index)) + prefix + (gotCR ? '\r\n' : '\n') + postfix;
endIndex = index + 1; endIndex = index + 1;
index = string.indexOf('\n', endIndex); index = string.indexOf('\n', endIndex);
} while (index !== -1); } while (index !== -1);