Skip to content

v3.3.0

Choose a tag to compare

@azu azu released this 11 Feb 12:14
· 7 commits to master since this release
59ba571

What's Changed

Features

  • feat: add replacer option by @azu in #18

options.replacer is a function that takes a node and commands like maskValue or emptyValue.
If you want to modify the value of the node, return command function calls.

// "This is a `code`."
const source = new StringSource(paragraphNode, {
    replacer({ node, maskValue }) {
        if (node.type === "Code") {
            return maskValue("_"); // code => ____
        }
    }
});
console.log(source.toString()); // => "This is a ____."
  • maskValue(character: string): mask the value of the node with the given character.
  • emptyValue(): replace the value of the node with an empty string.
const AST = parse("This is `TEST`.");
const source = new StringSource(AST, {
    replacer({ node, emptyValue }) {
        if (node.type === "Code") {
            return emptyValue();
        }
    }
});
assert.strictEqual(source.toString(), "This is .");

Examples:

Full Changelog: v3.2.0...v3.3.0