diff --git a/README.md b/README.md index eb491b1..6f7984d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,15 @@ Library for turning strings and DOM nodes into virtual DOM nodes compatible with [Snabbdom](https://github.com/paldepind/snabbdom). -### Usage +## API + +### `virtualize(nodes, options)` +* `nodes: Element|String` - Either a DOM `Element` or a string of HTML to turn into a set of virtual DOM nodes. +* `options: Object` - A hash of options to pass into the virtualize call. Available options are currently: + * `context: Document` - An alternative DOM document to use (default is `window.document`). + * `hooks: Object` - An object specifying hooks to call during the virtualization process. See the [hooks](#hooks) section below. + +## Usage Add it to your application with @@ -34,7 +42,19 @@ let vnode = virtualize(topNode); // String -let vnode = virtualize('
Click here'); +let vnode = virtualize('
Click here
'); +``` + +#### Specifying a different document + +You can specify a different DOM document (other than the default `window.document` in a browser) by passing a `context` option into your calls to `virtualize`. This will allow for usage in a server-side setting, where there is no browser. One option is to use `jsdom` to create a DOM document that can be used: + +```javascript +const virtualize = require('snabbdom-virtualize').default; +const jsdom = require('jsdom').jsdom; +virtualizeString('
Click here
', { + context: jsdom('') +}); ``` #### Using modules à la carte @@ -61,7 +81,7 @@ let vnode = virtualize(topNode); // HTML strings. import virtualize from 'snabbdom-virtualize/strings'; -let vnode = virtualize('
Click here'); +let vnode = virtualize('
Click here
'); ```