micro-mdx-parser
Version:
A tiny parser to convert markdown or html into JSON
32 lines (26 loc) • 835 B
JavaScript
const OPEN_BRACKET = '◖'
const OPEN_BRACKET_PATTERN = /◖/g
const CLOSE_BRACKET = '◗'
const CLOSE_BRACKET_PATTERN = /◗/g
const ARROW_FN_REGEX = /([{ ])(?:async\s+)?\s?\(.*\)\s?=>\s?\{(?:(?:[^}{]+|\{(?:[^}{]+|\{[^}{]*\})*\})*\}(?:\s?\(.*\)\s?\)\s?)?)?(?:\;)?/gim
function findArrowFns(block) {
let matches
const fns = []
while ((matches = ARROW_FN_REGEX.exec(block)) !== null) {
if (matches.index === ARROW_FN_REGEX.lastIndex) {
ARROW_FN_REGEX.lastIndex++ // avoid infinite loops with zero-width matches
}
// console.log('matches', matches)
const [ _match, openChar ] = matches
fns.push(_match.replace((openChar || ''), ''))
}
// console.log(fns.length)
return fns
}
module.exports = {
findArrowFns,
OPEN_BRACKET,
OPEN_BRACKET_PATTERN,
CLOSE_BRACKET,
CLOSE_BRACKET_PATTERN,
}