Replace trimLeft/trimRight polyfills with helper methods.

This commit is contained in:
David Anson 2017-12-13 21:41:28 -08:00
parent 39d39db961
commit 1184281c87
5 changed files with 21 additions and 36 deletions

View file

@ -33,7 +33,7 @@ function escapeForRegExp(str) {
// Returns the indent for a token
function indentFor(token) {
var line = token.line.replace(/^[\s>]*(> |>)/, "");
return line.length - line.trimLeft().length;
return line.length - shared.trimLeft(line).length;
}
// Returns the heading style for a heading token
@ -49,7 +49,7 @@ function headingStyleFor(token) {
// Returns the unordered list style for a list item token
function unorderedListStyleFor(token) {
switch (token.line.trimLeft().substr(0, 1)) {
switch (shared.trimLeft(token.line).substr(0, 1)) {
case "-":
return "dash";
case "+":
@ -368,7 +368,7 @@ module.exports = [
(listItemLineNumbers.indexOf(lineNumber) === -1)) {
var expected = (brSpaces < 2) ? 0 : brSpaces;
errors.addDetailIf(lineNumber,
expected, line.length - line.trimRight().length);
expected, line.length - shared.trimRight(line).length);
}
});
}
@ -1036,8 +1036,8 @@ module.exports = [
linkText = "";
} else if (child.type === "link_close") {
inLink = false;
var left = linkText.trimLeft().length !== linkText.length;
var right = linkText.trimRight().length !== linkText.length;
var left = shared.trimLeft(linkText).length !== linkText.length;
var right = shared.trimRight(linkText).length !== linkText.length;
if (left || right) {
errors.addContext(
token.lineNumber, "[" + linkText + "]", left, right);