A powerful, small tool for building regular expressions.
- It maintains its readability even with complex regular expressions.
- It build a RegExp object by combining functions.
- It provides a package of ES modules.
import C from "carol-js";
const hex = C.token(/[0-9a-f][0-9a-f]/);
const uuid = C.seq([
hex.many({ length: 4 }),
C.token(/-/),
hex.many({ length: 2 }),
C.token(/-/),
hex.many({ length: 2 }),
C.token(/-/),
hex.many({ length: 2 }),
C.token(/-/),
hex.many({ length: 6 }),
]);
const regex = uuid.toRegex({ flags: "i", exact: true });
assert.strictEqual(
regex.source,
"^(?:[0-9a-f][0-9a-f]){4}-(?:[0-9a-f][0-9a-f]){2}-(?:[0-9a-f][0-9a-f]){2}-(?:[0-9a-f][0-9a-f]){2}-(?:[0-9a-f][0-9a-f]){6}$"
);
assert.strictEqual(regex.flags, "i");
-
Install package of carol-js to your project.
npm i carol-js
-
Import the package to your TypeScript or JavaScript(ES modules) source files.
import C from 'carol-js';
-
Enjoy carol-js!
git clone https://github.com/marihachi/carol-js.git
cd carol-js
npm i
npm run build
npm test
MIT