I really like user-friendly command-line tools so I put together a small snippet for my node.js scripts. The result was put into a module, so it can be easily require()d and reused. I blame the lack of compliance with CommonJS naming standards on the quick-and-dirty nature of the script.
An example use case could be the start mode parameter of a script. A daemon that accepts the startup modes “help”, “start”, “stop” or “status” as the first and only parameter could look like this:
Example code (na-sample.js)
Usage
After providing the module with a list of words that should be checked in the constructor, the expand() function can be called to get a list of words that match or start with the term that was provided.
Module code (node-abbrev.js)
The complete gist with example and module code can be found here.