fix: Replace custom repeatString
function with repeat()
(#2820)
chore: Replace custom repeatString functions with ECMAScript String.repeat()
This commit is contained in:
parent
5203b44da9
commit
72ee2d620a
@ -326,14 +326,6 @@ function isArray(arr) {
|
||||
return Object.prototype.toString.call(arr) === '[object Array]';
|
||||
}
|
||||
|
||||
function stringRepeat(char, times) {
|
||||
var s = '';
|
||||
for (var i = 0; i < times; i++) {
|
||||
s += char;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
function jsonString(input, level) {
|
||||
level = level || 0;
|
||||
if (isArray(input)) {
|
||||
@ -344,7 +336,7 @@ function jsonString(input, level) {
|
||||
i;
|
||||
if (!isArray(input[0]) && typeof input[0] === 'object' && input[0] !== null) {
|
||||
for (i = 0; i < input.length; i++) {
|
||||
items.push(stringRepeat(' ', 2 * level) + jsonString(input[i], level + 1));
|
||||
items.push(' '.repeat(2 * level) + jsonString(input[i], level + 1));
|
||||
}
|
||||
return '[\n' + items.join('\n') + '\n]';
|
||||
}
|
||||
|
@ -87,14 +87,6 @@ function parse(e) {
|
||||
}
|
||||
}
|
||||
|
||||
function stringRepeat(char, times) {
|
||||
var s = '';
|
||||
for (var i = 0; i < times; i++) {
|
||||
s += char;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
function jsonString(input, level) {
|
||||
level = level || 0;
|
||||
if (Array.isArray(input)) {
|
||||
@ -105,7 +97,7 @@ function jsonString(input, level) {
|
||||
i;
|
||||
if (!Array.isArray(input[0]) && typeof input[0] === 'object' && input[0] !== null) {
|
||||
for (i = 0; i < input.length; i++) {
|
||||
items.push(stringRepeat(' ', 2 * level) + jsonString(input[i], level + 1));
|
||||
items.push(' '.repeat(2 * level) + jsonString(input[i], level + 1));
|
||||
}
|
||||
return '[\n' + items.join('\n') + '\n]';
|
||||
}
|
||||
|
@ -372,26 +372,6 @@ function checkDeprecations(opt, callback) {
|
||||
}
|
||||
}
|
||||
|
||||
// copied from https://stackoverflow.com/a/5450113/806777
|
||||
/**
|
||||
* @param {string} pattern
|
||||
* @param {number} count
|
||||
*/
|
||||
function repeatString(pattern, count) {
|
||||
if (count < 1) {
|
||||
return '';
|
||||
}
|
||||
var result = '';
|
||||
while (count > 1) {
|
||||
if (count & 1) {
|
||||
result += pattern;
|
||||
}
|
||||
count >>= 1;
|
||||
pattern += pattern;
|
||||
}
|
||||
return result + pattern;
|
||||
}
|
||||
|
||||
function outputLink(cap, link, raw, lexer) {
|
||||
var href = link.href;
|
||||
var title = link.title ? escape(link.title) : null;
|
||||
@ -1649,14 +1629,14 @@ var Lexer = /*#__PURE__*/function () {
|
||||
if (links.length > 0) {
|
||||
while ((match = this.tokenizer.rules.inline.reflinkSearch.exec(maskedSrc)) != null) {
|
||||
if (links.includes(match[0].slice(match[0].lastIndexOf('[') + 1, -1))) {
|
||||
maskedSrc = maskedSrc.slice(0, match.index) + '[' + repeatString('a', match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex);
|
||||
maskedSrc = maskedSrc.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Mask out other blocks
|
||||
while ((match = this.tokenizer.rules.inline.blockSkip.exec(maskedSrc)) != null) {
|
||||
maskedSrc = maskedSrc.slice(0, match.index) + '[' + repeatString('a', match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
|
||||
maskedSrc = maskedSrc.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
|
||||
}
|
||||
|
||||
// Mask out escaped em & strong delimiters
|
||||
|
@ -312,26 +312,6 @@ function checkDeprecations(opt, callback) {
|
||||
}
|
||||
}
|
||||
|
||||
// copied from https://stackoverflow.com/a/5450113/806777
|
||||
/**
|
||||
* @param {string} pattern
|
||||
* @param {number} count
|
||||
*/
|
||||
function repeatString(pattern, count) {
|
||||
if (count < 1) {
|
||||
return '';
|
||||
}
|
||||
let result = '';
|
||||
while (count > 1) {
|
||||
if (count & 1) {
|
||||
result += pattern;
|
||||
}
|
||||
count >>= 1;
|
||||
pattern += pattern;
|
||||
}
|
||||
return result + pattern;
|
||||
}
|
||||
|
||||
function outputLink(cap, link, raw, lexer) {
|
||||
const href = link.href;
|
||||
const title = link.title ? escape(link.title) : null;
|
||||
@ -1761,14 +1741,14 @@ class Lexer {
|
||||
if (links.length > 0) {
|
||||
while ((match = this.tokenizer.rules.inline.reflinkSearch.exec(maskedSrc)) != null) {
|
||||
if (links.includes(match[0].slice(match[0].lastIndexOf('[') + 1, -1))) {
|
||||
maskedSrc = maskedSrc.slice(0, match.index) + '[' + repeatString('a', match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex);
|
||||
maskedSrc = maskedSrc.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Mask out other blocks
|
||||
while ((match = this.tokenizer.rules.inline.blockSkip.exec(maskedSrc)) != null) {
|
||||
maskedSrc = maskedSrc.slice(0, match.index) + '[' + repeatString('a', match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
|
||||
maskedSrc = maskedSrc.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
|
||||
}
|
||||
|
||||
// Mask out escaped em & strong delimiters
|
||||
|
@ -376,26 +376,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
// copied from https://stackoverflow.com/a/5450113/806777
|
||||
/**
|
||||
* @param {string} pattern
|
||||
* @param {number} count
|
||||
*/
|
||||
function repeatString(pattern, count) {
|
||||
if (count < 1) {
|
||||
return '';
|
||||
}
|
||||
var result = '';
|
||||
while (count > 1) {
|
||||
if (count & 1) {
|
||||
result += pattern;
|
||||
}
|
||||
count >>= 1;
|
||||
pattern += pattern;
|
||||
}
|
||||
return result + pattern;
|
||||
}
|
||||
|
||||
function outputLink(cap, link, raw, lexer) {
|
||||
var href = link.href;
|
||||
var title = link.title ? escape(link.title) : null;
|
||||
@ -1653,14 +1633,14 @@
|
||||
if (links.length > 0) {
|
||||
while ((match = this.tokenizer.rules.inline.reflinkSearch.exec(maskedSrc)) != null) {
|
||||
if (links.includes(match[0].slice(match[0].lastIndexOf('[') + 1, -1))) {
|
||||
maskedSrc = maskedSrc.slice(0, match.index) + '[' + repeatString('a', match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex);
|
||||
maskedSrc = maskedSrc.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Mask out other blocks
|
||||
while ((match = this.tokenizer.rules.inline.blockSkip.exec(maskedSrc)) != null) {
|
||||
maskedSrc = maskedSrc.slice(0, match.index) + '[' + repeatString('a', match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
|
||||
maskedSrc = maskedSrc.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
|
||||
}
|
||||
|
||||
// Mask out escaped em & strong delimiters
|
||||
|
2
marked.min.js
vendored
2
marked.min.js
vendored
File diff suppressed because one or more lines are too long
@ -1,7 +1,6 @@
|
||||
import { Tokenizer } from './Tokenizer.js';
|
||||
import { defaults } from './defaults.js';
|
||||
import { block, inline } from './rules.js';
|
||||
import { repeatString } from './helpers.js';
|
||||
|
||||
/**
|
||||
* smartypants text replacement
|
||||
@ -338,14 +337,14 @@ export class Lexer {
|
||||
if (links.length > 0) {
|
||||
while ((match = this.tokenizer.rules.inline.reflinkSearch.exec(maskedSrc)) != null) {
|
||||
if (links.includes(match[0].slice(match[0].lastIndexOf('[') + 1, -1))) {
|
||||
maskedSrc = maskedSrc.slice(0, match.index) + '[' + repeatString('a', match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex);
|
||||
maskedSrc = maskedSrc.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Mask out other blocks
|
||||
while ((match = this.tokenizer.rules.inline.blockSkip.exec(maskedSrc)) != null) {
|
||||
maskedSrc = maskedSrc.slice(0, match.index) + '[' + repeatString('a', match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
|
||||
maskedSrc = maskedSrc.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
|
||||
}
|
||||
|
||||
// Mask out escaped em & strong delimiters
|
||||
|
@ -269,23 +269,3 @@ export function checkDeprecations(opt, callback) {
|
||||
console.warn('marked(): headerIds and headerPrefix parameters enabled by default, but are deprecated since version 5.0.0, and will be removed in the future. To clear this warning, install https://www.npmjs.com/package/marked-gfm-heading-id, or disable by setting `{headerIds: false}`.');
|
||||
}
|
||||
}
|
||||
|
||||
// copied from https://stackoverflow.com/a/5450113/806777
|
||||
/**
|
||||
* @param {string} pattern
|
||||
* @param {number} count
|
||||
*/
|
||||
export function repeatString(pattern, count) {
|
||||
if (count < 1) {
|
||||
return '';
|
||||
}
|
||||
let result = '';
|
||||
while (count > 1) {
|
||||
if (count & 1) {
|
||||
result += pattern;
|
||||
}
|
||||
count >>= 1;
|
||||
pattern += pattern;
|
||||
}
|
||||
return result + pattern;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user