refactor: replace deprecated String.prototype.substr()

.substr() is deprecated 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:
Tobias Speicher 2022-03-27 17:43:57 +02:00
parent bccde97f8a
commit d27905cb9a
No known key found for this signature in database
GPG key ID: 2CF824BD810C3BDB

View file

@ -9,7 +9,7 @@ export function stringReplaceAll(string, substring, replacer) {
let endIndex = 0;
let returnValue = '';
do {
returnValue += string.substr(endIndex, index - endIndex) + substring + replacer;
returnValue += string.slice(endIndex, index) + substring + replacer;
endIndex = index + substringLength;
index = string.indexOf(substring, endIndex);
} while (index !== -1);
@ -23,7 +23,7 @@ export function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
let returnValue = '';
do {
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;
index = string.indexOf('\n', endIndex);
} while (index !== -1);