index: update JSDoc comments
index: allow an explicit `document` object to be passed in

Allows for easier testing, etc. (i.e. in Node.js with jsdom or
maybe even cheerio).