Skip to content

Commit

Permalink
refactor: replace deprecated String.prototype.substr() (#3590)
Browse files Browse the repository at this point in the history
.substr() is deprecated so we replace it with .slice() which works similarily but isn't deprecated

Signed-off-by: Tobias Speicher <rootcommander@gmail.com>

Signed-off-by: Tobias Speicher <rootcommander@gmail.com>
Co-authored-by: ylemkimon <y@ylem.kim>
  • Loading branch information
CommanderRoot and ylemkimon committed Aug 29, 2022
1 parent 48b15e4 commit 299584d
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Parser.js
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/buildCommon.js
Expand Up @@ -190,7 +190,7 @@ const makeOrd = function<NODETYPE: "spacing" | "mathord" | "textord">(
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++) {
Expand Down
4 changes: 2 additions & 2 deletions src/buildMathML.js
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/environments/array.js
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/functions/enclose.js
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/functions/mclass.js
Expand Up @@ -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),
};
Expand Down
2 changes: 1 addition & 1 deletion src/functions/op.js
Expand Up @@ -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";
}

Expand Down
2 changes: 1 addition & 1 deletion src/macros.js
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion src/stretchy.js
Expand Up @@ -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
Expand Down

0 comments on commit 299584d

Please sign in to comment.