Split into a library and a main.js for the CLI