html-to-vdom
Advanced tools
Comparing version 0.5.1 to 0.5.2
@@ -17,2 +17,11 @@ var decode = require('ent').decode; | ||
// Transform a data attribute name to a valid dataset key name | ||
// (See https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement.dataset) | ||
var dataAttributeToDatasetKey = function dataAttributeToDatasetKey (name) { | ||
var unprefixed = name.slice(prefixLength); | ||
return unprefixed.replace(/\-([a-z])/g, function (m, charAfterHyphen) { | ||
return charAfterHyphen.toUpperCase(); | ||
}); | ||
}; | ||
var getDataset = function getDataset (tag) { | ||
@@ -32,4 +41,3 @@ var attributes = tag.attribs; | ||
} | ||
var unprefixed = name.slice(prefixLength); | ||
dataset[unprefixed] = value; | ||
dataset[dataAttributeToDatasetKey(name)] = value; | ||
}); | ||
@@ -36,0 +44,0 @@ |
{ | ||
"name": "html-to-vdom", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"description": "Converts html into a vtree", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -74,1 +74,2 @@ html-to-vdom [![Build Status](https://travis-ci.org/TimBeyer/html-to-vdom.svg?branch=master)](https://travis-ci.org/TimBeyer/html-to-vdom) | ||
* [@jsyang](https://github.com/jsyang) for removing the `lodash` dependency for a leaner build and [improved performance](http://jsperf.com/html-to-vdom-lodash-vs-native) | ||
* [@bregenspan](https://github.com/bregenspan) for making the dataset conversion standards-compliant |
@@ -135,2 +135,16 @@ var VNode = require('virtual-dom/vnode/vnode'); | ||
it('converts a single hyphenated data attribute correctly', function () { | ||
var html = '<div data-test-data="foobar"></div>'; | ||
var converted = convertHTML(html); | ||
should.exist(converted.properties.dataset.testData); | ||
converted.properties.dataset.testData.should.eql('foobar'); | ||
should.exist(converted.properties['data-test-data']); | ||
converted.properties['data-test-data'].should.eql('foobar'); | ||
}); | ||
it('converts multiple data attributes correctly', function () { | ||
@@ -137,0 +151,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
22400
350
75