src/pattern-matcher.js
function replaceF(matcher, str, replace) {
    const chunks = []
    let index = 0

    for (const match of matcher.execAll(str)) {
        chunks.push(str.slice(index, match.index))
        chunks.push(String(replace(...match, match.index, match.input)))
        index = match.index + match[0].length
    }
    chunks.push(str.slice(index))

    return chunks.join("")
}
function replaceF(matcher, str, replace) {
    const chunks = []
    let index = 0

    for (const match of matcher.execAll(str)) {
        chunks.push(str.slice(index, match.index))
        chunks.push(String(replace(...match, match.index, match.input)))
        index = match.index + match[0].length
    }
    chunks.push(str.slice(index))

    return chunks.join("")
}
eslint-disable-next-line valid-jsdoc 
Replace a given string by a given matcher.
@param {PatternMatcher} matcher The pattern matcher.
@param {string} str The string to be replaced.
@param {(...strs[])=>string} replace The function to replace each matched part.
@returns {string} The replaced string.