From 299584d12fa70c66fb9d5413a1503722b3a7e969 Mon Sep 17 00:00:00 2001 From: CommanderRoot Date: Mon, 29 Aug 2022 23:26:39 +0200 Subject: [PATCH] refactor: replace deprecated String.prototype.substr() (#3590) .substr() is deprecated so we replace it with .slice() which works similarily but isn't deprecated Signed-off-by: Tobias Speicher Signed-off-by: Tobias Speicher Co-authored-by: ylemkimon --- src/Parser.js | 2 +- src/buildCommon.js | 2 +- src/buildMathML.js | 4 ++-- src/environments/array.js | 2 +- src/functions/enclose.js | 2 +- src/functions/mclass.js | 2 +- src/functions/op.js | 2 +- src/macros.js | 2 +- src/stretchy.js | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Parser.js b/src/Parser.js index 43de4f92fc..288b2cfcf3 100644 --- a/src/Parser.js +++ b/src/Parser.js @@ -922,7 +922,7 @@ export default class Parser { `Accented Unicode text character "${text[0]}" used in ` + `math mode`, nucleus); } - text = unicodeSymbols[text[0]] + text.substr(1); + text = unicodeSymbols[text[0]] + text.slice(1); } // Strip off any combining characters const match = combiningDiacriticalMarksEndRegex.exec(text); diff --git a/src/buildCommon.js b/src/buildCommon.js index 07e694c859..5f0bbae61e 100644 --- a/src/buildCommon.js +++ b/src/buildCommon.js @@ -190,7 +190,7 @@ const makeOrd = function( return makeSymbol(text, fontName, mode, options, classes.concat(fontClasses)); } else if (ligatures.hasOwnProperty(text) && - fontName.substr(0, 10) === "Typewriter") { + fontName.slice(0, 10) === "Typewriter") { // Deconstruct ligatures in monospace fonts (\texttt, \tt). const parts = []; for (let i = 0; i < text.length; i++) { diff --git a/src/buildMathML.js b/src/buildMathML.js index 01ebc15767..849be0cd2e 100644 --- a/src/buildMathML.js +++ b/src/buildMathML.js @@ -32,8 +32,8 @@ export const makeText = function( if (symbols[mode][text] && symbols[mode][text].replace && text.charCodeAt(0) !== 0xD835 && !(ligatures.hasOwnProperty(text) && options && - ((options.fontFamily && options.fontFamily.substr(4, 2) === "tt") || - (options.font && options.font.substr(4, 2) === "tt")))) { + ((options.fontFamily && options.fontFamily.slice(4, 6) === "tt") || + (options.font && options.font.slice(4, 6) === "tt")))) { text = symbols[mode][text].replace; } diff --git a/src/environments/array.js b/src/environments/array.js index c6cdc0643b..f39a7352c8 100644 --- a/src/environments/array.js +++ b/src/environments/array.js @@ -256,7 +256,7 @@ function parseArray( // Decides on a style for cells in an array according to whether the given // environment name starts with the letter 'd'. function dCellStyle(envName): StyleStr { - if (envName.substr(0, 1) === "d") { + if (envName.slice(0, 1) === "d") { return "display"; } else { return "text"; diff --git a/src/functions/enclose.js b/src/functions/enclose.js index 67141448f9..eb586f86eb 100644 --- a/src/functions/enclose.js +++ b/src/functions/enclose.js @@ -20,7 +20,7 @@ const htmlBuilder = (group, options) => { const inner = buildCommon.wrapFragment( html.buildGroup(group.body, options), options); - const label = group.label.substr(1); + const label = group.label.slice(1); let scale = options.sizeMultiplier; let img; let imgShift = 0; diff --git a/src/functions/mclass.js b/src/functions/mclass.js index e598ba58d1..96cdb37d7a 100644 --- a/src/functions/mclass.js +++ b/src/functions/mclass.js @@ -75,7 +75,7 @@ defineFunction({ return { type: "mclass", mode: parser.mode, - mclass: "m" + funcName.substr(5), // TODO(kevinb): don't prefix with 'm' + mclass: "m" + funcName.slice(5), // TODO(kevinb): don't prefix with 'm' body: ordargument(body), isCharacterBox: utils.isCharacterBox(body), }; diff --git a/src/functions/op.js b/src/functions/op.js index 72fe3a9098..9dcf94eea2 100644 --- a/src/functions/op.js +++ b/src/functions/op.js @@ -61,7 +61,7 @@ export const htmlBuilder: HtmlBuilderSupSub<"op"> = (grp, options) => { if (group.name === "\\oiint" || group.name === "\\oiiint") { // No font glyphs yet, so use a glyph w/o the oval. // TODO: When font glyphs are available, delete this code. - stash = group.name.substr(1); + stash = group.name.slice(1); group.name = stash === "oiint" ? "\\iint" : "\\iiint"; } diff --git a/src/macros.js b/src/macros.js index f7a8803ab6..1fe36b0aff 100644 --- a/src/macros.js +++ b/src/macros.js @@ -447,7 +447,7 @@ defineMacro("\\dots", function(context) { const next = context.expandAfterFuture().text; if (next in dotsByToken) { thedots = dotsByToken[next]; - } else if (next.substr(0, 4) === '\\not') { + } else if (next.slice(0, 4) === '\\not') { thedots = '\\dotsb'; } else if (next in symbols.math) { if (utils.contains(['bin', 'rel'], symbols.math[next].group)) { diff --git a/src/stretchy.js b/src/stretchy.js index 380a8447e6..69d81ab594 100644 --- a/src/stretchy.js +++ b/src/stretchy.js @@ -191,7 +191,7 @@ const svgSpan = function( height: number, } { let viewBoxWidth = 400000; // default - const label = group.label.substr(1); + const label = group.label.slice(1); if (utils.contains(["widehat", "widecheck", "widetilde", "utilde"], label)) { // Each type in the `if` statement corresponds to one of the ParseNode