replace-enumerator
v0.0.1
Published
The format string library that detects the string and the column number of the replacing value
Downloads
1
Maintainers
Readme
Basic Usage
import ReplaceEnumerator from "replace-enumerator"
const expr = "{{greet}}, {{ name }} my name is {{ name2 }}."
const enumerator = new ReplaceEnumerator(/{{([\s\S]+?)}}/g)
const cases = enumerator.parse(expr)
for (const item of cases){
item.replace(match => {
console.log("before replacing")
console.dir(match)
switch(match.expression){
case "greet": return "Hi!"
case "name": return "Bob"
case "name2": return "Sam"
default: throw new Error(`${match} isn't expected`)
}
console.log("after replaced")
console.dir(match)
})
}
const result = enumerator.toString()
expect(result).toEqual("Hi!, Bob my name is Sam.")