babel-plugin-melody
v0.19.0
Published
<p align="center"> <img alt="Melody Logo" height="250px" src="https://user-images.githubusercontent.com/14347895/159069181-53bce5b3-a831-43f1-8c14-af6c6ed7b92b.svg"> </p>
Maintainers
Readme
A babel plugin that converts string literals and template strings containing Melody syntax to regular expression syntax.
To mark a string for the plugin, add /*melody*/ before it.
Install
npm install --save-dev babel-plugin-melodyor
yarn add -D babel-plugin-melodyUsage
// .babelrc
{
"plugins": ["babel-plugin-melody"]
}Example
Input
const regex = new RegExp(/*melody*/ `2 to 3 of "na";`);
const otherRegex = new RegExp(/*melody*/ '5 to 9 of "other";');
const rawRegex = /*melody*/ `
<start>;
"other";
<end>;
`;
const thirdRegex = new RegExp(rawRegex);Output
const regex = new RegExp('(?:na){2,3}');
const otherRegex = new RegExp('(?:other){5,9}');
const rawRegex = '^other$';
const thirdRegex = new RegExp(rawRegex);Known issues
- Interpolation within template strings is not currently supported
