robbestad / Rantjs

Procedurally generate text with JavaScript
220 stars 10 forks source link

any plans for node? #2

Closed mattdesl closed 9 years ago

mattdesl commented 9 years ago

This project looks great!

Any plans for node support? Using modules (ES6 / CommonJS) would probably clean up your build step quite a lot as well.

robbestad commented 9 years ago

Hmm... I'm definitely considering making it more modular. I've relied on prototypal inheritance because my original aim was to use the end product in ImpactJS, and there's no easy way to use CommonJS or require in that framework (it's got its own module system).

But.. I love node, so I made it so that rantjs is exportable and there's a version on npm right now: https://www.npmjs.com/package/rantjs. If you got any specific tips on how to make it more node-friendly, I'm more than happy to oblige. :)

mattdesl commented 9 years ago

You could author your library in CommonJS, and then bundle it with browserify into something that ImpactJS supports. We've done the same on CocoonJS projects, and even in Adobe ExtendScript, so I don't see why it wouldn't work in ImpactJS.

This is also a good approach for general browser dev. You can use tape or prova for unit testing in both node and the browser.

This means anyone consuming the module (with Browserify, Webpack, or NodeJS) would consume your "raw" source. You could provide a downloadable UMD build for other formats (like ImpactJS, AMD, or <script> tag).

And because you're using modules, you could also take advantage of things on the npm ecosystem. They may or may not be what you need: to-title-case, lex, etc.

While on the subject of refactor, you might want to consider a simpler end-user API, like exporting the common use case as a default method. The current setup is cumbersome IMHO.

var sentence = require('rantjs')('.. pattern here ...')
robbestad commented 9 years ago

Thanks for your comments. This is very helpful. Your example at the end makes it clear how rantjs could be easier to use and I like the idea. I'll put new features on hold and implement this before moving on :+1:

robbestad commented 9 years ago

Done