html-to-react
Advanced tools
Comparing version 1.1.0 to 1.1.1
'use strict'; | ||
var find = require('lodash.find'); | ||
var map = require('lodash.map'); | ||
var find = require('ramda/src/find'); | ||
var reject = require('ramda/src/reject'); | ||
var addIndex = require('ramda/src/addIndex'); | ||
var map = require('ramda/src/map'); | ||
var htmlParser = require('htmlparser2'); | ||
@@ -18,12 +20,10 @@ var ProcessingInstructions = require('./processing-instructions'); | ||
if (isValidNode(node)) { | ||
var processingInstruction = find(processingInstructions || [], | ||
function (processingInstruction) { | ||
return processingInstruction.shouldProcessNode(node); | ||
}); | ||
var processingInstruction = find(function (processingInstruction) { | ||
return processingInstruction.shouldProcessNode(node); | ||
}, processingInstructions); | ||
if (processingInstruction != null) { | ||
var children = map(node.children || [], function (child, i) { | ||
return traverseDom(child, isValidNode, processingInstructions, i); | ||
}).filter(function (x) { | ||
return x != null; | ||
}); | ||
var children = reject((x) => {return x == null;}, | ||
addIndex(map)(function (child, i) { | ||
return traverseDom(child, isValidNode, processingInstructions, i); | ||
}, node.children || [])); | ||
return processingInstruction.processNode(node, children, index); | ||
@@ -30,0 +30,0 @@ } else { |
'use strict'; | ||
var isEmpty = require('lodash.isempty'); | ||
var map = require('lodash.map'); | ||
var fromPairs = require('lodash.frompairs'); | ||
var camelCase = require('lodash.camelcase'); | ||
var includes = require('lodash.includes'); | ||
var merge = require('lodash.merge'); | ||
var isEmpty = require('ramda/src/isEmpty'); | ||
var merge = require('ramda/src/merge'); | ||
var fromPairs = require('ramda/src/fromPairs'); | ||
var map = require('ramda/src/map'); | ||
var toPairs = require('ramda/src/toPairs'); | ||
var contains = require('ramda/src/contains'); | ||
var concat = require('ramda/src/concat'); | ||
var camelize = require('underscore.string.fp/camelize'); | ||
var isBlank = require('underscore.string.fp/isBlank'); | ||
var ent = require('ent'); | ||
@@ -20,3 +23,3 @@ var camelCaseAttrMap = require('./camel-case-attribute-names'); | ||
function createStyleJsonFromString(styleString) { | ||
if (!styleString) { | ||
if (isBlank(styleString)) { | ||
return {}; | ||
@@ -28,3 +31,3 @@ } | ||
singleStyle = styles[i].split(':'); | ||
key = camelCase(singleStyle[0]); | ||
key = camelize(singleStyle[0]); | ||
value = singleStyle[1]; | ||
@@ -43,4 +46,5 @@ if (key.length > 0 && value.length > 0) { | ||
} else if (node.type === 'comment') { | ||
// FIXME: The following doesn't work as the generated HTML results in "<!-- This is a comment -->" | ||
//return '<!-- ' + node.data + ' -->'; | ||
// FIXME: The following doesn't work as the generated HTML results in | ||
// "<!-- This is a comment -->" | ||
// return '<!-- ' + node.data + ' -->'; | ||
return false; | ||
@@ -54,3 +58,5 @@ } | ||
if (!isEmpty(node.attribs)) { | ||
elementProps = merge(elementProps, fromPairs(map(node.attribs, function (value, key) { | ||
elementProps = merge(elementProps, fromPairs(map(function (keyAndValue) { | ||
var key = keyAndValue[0]; | ||
var value = keyAndValue[1]; | ||
if (key === 'style') { | ||
@@ -64,13 +70,18 @@ value = createStyleJsonFromString(node.attribs.style); | ||
return [key, value || key,]; | ||
}))); | ||
if (isBlank(value)) { | ||
// Handle boolean attributes - if their value isn't explicitly supplied, | ||
// define it as the attribute name (e.g. disabled="disabled") | ||
value = key; | ||
} | ||
return [key, value,]; | ||
}, toPairs(node.attribs)))); | ||
} | ||
if (includes(voidElementTags, node.name)) { | ||
if (contains(node.name, voidElementTags)) { | ||
return React.createElement(node.name, elementProps); | ||
} else { | ||
var allChildren = node.data != null ? [node.data,].concat(children) : children; | ||
return React.createElement.apply( | ||
this, [node.name, elementProps,].concat(allChildren) | ||
); | ||
var allChildren = node.data != null ? concat([node.data,], children) : children; | ||
return React.createElement.apply(null, concat([node.name, elementProps,], | ||
allChildren)); | ||
} | ||
@@ -77,0 +88,0 @@ } |
{ | ||
"name": "html-to-react", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "A lightweight library that converts raw HTML to a React DOM structure.", | ||
@@ -40,9 +40,4 @@ "main": "index.js", | ||
"htmlparser2": "^3.8.3", | ||
"lodash.camelcase": "^4.3.0", | ||
"lodash.find": "^4.6.0", | ||
"lodash.frompairs": "^4.0.1", | ||
"lodash.includes": "^4.3.0", | ||
"lodash.isempty": "^4.4.0", | ||
"lodash.map": "^4.6.0", | ||
"lodash.merge": "^4.6.0" | ||
"ramda": "^0.22.0", | ||
"underscore.string.fp": "^1.0.4" | ||
}, | ||
@@ -57,3 +52,2 @@ "peerDependencies": { | ||
"mocha-lcov-reporter": "^1.2.0", | ||
"ramda": "^0.22.1", | ||
"react": "^15.0", | ||
@@ -60,0 +54,0 @@ "react-dom": "^15.0" |
@@ -101,4 +101,6 @@ # html-to-react | ||
`$ npm run test` | ||
`$ npm run test-coverage` | ||
`$ npm run test-html-coverage` | ||
Test locally: `$ npm run test` | ||
Test with coverage: `$ npm run test-coverage` | ||
Test with coverage and open HTML report `$ npm run test-html-coverage` |
@@ -280,4 +280,6 @@ 'use strict'; | ||
it('should return capitalized content for all <h1> elements', function() { | ||
var htmlInput = '<div><h1>Title</h1><p>Paragraph</p><h1>Another title</h1></div>'; | ||
var htmlExpected = '<div><h1>TITLE</h1><p>Paragraph</p><h1>ANOTHER TITLE</h1></div>'; | ||
var htmlInput = '<div><h1>Title</h1><p>Paragraph</p>' + | ||
'<h1>Another title</h1></div>'; | ||
var htmlExpected = '<div><h1>TITLE</h1><p>Paragraph</p>' + | ||
'<h1>ANOTHER TITLE</h1></div>'; | ||
@@ -292,3 +294,4 @@ var isValidNode = function() { | ||
shouldProcessNode: function(node) { | ||
return node.parent && node.parent.name && node.parent.name === 'h1'; | ||
return node.parent && node.parent.name && | ||
node.parent.name === 'h1'; | ||
}, | ||
@@ -295,0 +298,0 @@ processNode: function(node, children) { |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
36666
5
6
498
106
0
+ Addedramda@^0.22.0
+ Addedunderscore.string.fp@^1.0.4
+ Addedarity-n@1.0.4(transitive)
+ Addedchickencurry@1.1.1(transitive)
+ Addedcompose-function@2.0.0(transitive)
+ Addedramda@0.22.1(transitive)
+ Addedreverse-arguments@1.0.0(transitive)
+ Addedunderscore.string@3.0.3(transitive)
+ Addedunderscore.string.fp@1.0.4(transitive)
- Removedlodash.camelcase@^4.3.0
- Removedlodash.find@^4.6.0
- Removedlodash.frompairs@^4.0.1
- Removedlodash.includes@^4.3.0
- Removedlodash.isempty@^4.4.0
- Removedlodash.map@^4.6.0
- Removedlodash.merge@^4.6.0
- Removedlodash.camelcase@4.3.0(transitive)
- Removedlodash.find@4.6.0(transitive)
- Removedlodash.frompairs@4.0.1(transitive)
- Removedlodash.includes@4.3.0(transitive)
- Removedlodash.isempty@4.4.0(transitive)
- Removedlodash.map@4.6.0(transitive)
- Removedlodash.merge@4.6.2(transitive)