Move JavaScript to separate file

Mostly so it can be linted and tested.
Change from JSHint to JSLint directives
Add file-level JSDoc comment
Pull parameter parsing into a function
Add function JSDoc comments