snabbdom-virtualize
Advanced tools
Comparing version 0.6.0 to 0.7.0
@@ -108,3 +108,5 @@ 'use strict'; | ||
className.split(' ').forEach(function (className) { | ||
classes[className] = true; | ||
if (className.trim().length) { | ||
classes[className.trim()] = true; | ||
} | ||
}); | ||
@@ -111,0 +113,0 @@ } |
@@ -31,3 +31,3 @@ 'use strict'; | ||
// Regex for matching HTML entities. | ||
var entityRegex = new RegExp('&[a-z0-9]+;', 'gi'); | ||
var entityRegex = new RegExp('&[a-z0-9#]+;', 'gi'); | ||
// Element for setting innerHTML for transforming entities. | ||
@@ -34,0 +34,0 @@ var el = null; |
{ | ||
"name": "snabbdom-virtualize", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "Library for turning strings and DOM nodes into virtual DOM nodes compatible with snabbdom.", | ||
@@ -19,3 +19,3 @@ "author": { | ||
"watch": "npm run build -- --watch", | ||
"test": "npm run build && karma start test/karma.conf.js && mocha test/nodejs_tests.js" | ||
"test": "npm run build && mocha test/nodejs_tests.js && karma start test/karma.conf.js" | ||
}, | ||
@@ -42,3 +42,3 @@ "main": "lib/index.js", | ||
"sinon-chai": "^2.8.0", | ||
"snabbdom": "~0", | ||
"snabbdom": "~0.6.6", | ||
"socket.io": "1.4.6", | ||
@@ -48,7 +48,7 @@ "webpack": "^1.12.12" | ||
"peerDependencies": { | ||
"snabbdom": "~0" | ||
"snabbdom": "~0.6.6" | ||
}, | ||
"dependencies": { | ||
"html-parse-stringify2": "^1.2.1" | ||
"html-parse-stringify2": "^2" | ||
} | ||
} |
@@ -5,4 +5,12 @@ # snabbdom-virtualize [![Build Status](https://travis-ci.org/appcues/snabbdom-virtualize.svg?branch=master)](https://travis-ci.org/appcues/snabbdom-virtualize) | ||
### 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 | ||
@@ -38,5 +46,17 @@ | ||
// String | ||
let vnode = virtualize('<div>Click <a href="http://example.com">here</a>'); | ||
let vnode = virtualize('<div>Click <a href="http://example.com">here</a></div>'); | ||
``` | ||
#### 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('<div>Click <a href="http://example.com">here</a></div>', { | ||
context: jsdom('<html></html>') | ||
}); | ||
``` | ||
#### Using modules à la carte | ||
@@ -66,3 +86,3 @@ | ||
let vnode = virtualize('<div>Click <a href="http://example.com">here</a>'); | ||
let vnode = virtualize('<div>Click <a href="http://example.com">here</a></div>'); | ||
@@ -69,0 +89,0 @@ ``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17438
277
118
+ Addedhtml-parse-stringify2@2.0.1(transitive)
+ Addedsnabbdom@0.6.9(transitive)
+ Addedvoid-elements@2.0.1(transitive)
- Removedhtml-parse-stringify2@1.2.1(transitive)
- Removedsnabbdom@0.7.4(transitive)
- Removedvoid-elements@1.0.0(transitive)
Updatedhtml-parse-stringify2@^2