diff --git a/lib/parser.js b/lib/parser.js index 3fc66cd..bed57a7 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -1,6 +1,8 @@ 'use strict'; -var _ = require('lodash'); +var compact = require('lodash.compact'); +var find = require('lodash.find'); +var map = require('lodash.map'); var htmlParser = require('htmlparser2'); var ProcessingInstructions = require('./processing-instructions'); var IsValidNodeDefinitions = require('./is-valid-node-definitions'); @@ -15,12 +17,12 @@ var Html2React = function(React, options) { var traverseDom = function(node, isValidNode, processingInstructions, index) { if (isValidNode(node)) { - var processingInstruction = _.find(processingInstructions || [], + var processingInstruction = find(processingInstructions || [], function (processingInstruction) { return processingInstruction.shouldProcessNode(node); }); if (processingInstruction != null) { - var children = _.compact(_.map(node.children, function (child, i) { + var children = compact(map(node.children, function (child, i) { return traverseDom(child, isValidNode, processingInstructions, i); })); return processingInstruction.processNode(node, children, index); diff --git a/lib/process-node-definitions.js b/lib/process-node-definitions.js index 5aac867..df2df0b 100644 --- a/lib/process-node-definitions.js +++ b/lib/process-node-definitions.js @@ -1,6 +1,8 @@ 'use strict'; -var _ = require('lodash'); +var camelCase = require('lodash.camelcase'); +var forEach = require('lodash.foreach'); +var includes = require('lodash.includes'); var ent = require('ent'); // https://github.com/facebook/react/blob/0.14-stable/src/renderers/dom/shared/ReactDOMComponent.js#L457 @@ -10,14 +12,14 @@ var voidElementTags = [ ]; function createStyleJsonFromString(styleString) { - if (_.isNull(styleString) || _.isUndefined(styleString) || styleString === '') { + if (!styleString) { return {}; } var styles = styleString.split(';'); var singleStyle, key, value, jsonStyles = {}; for (var i = 0; i < styles.length; i++) { singleStyle = styles[i].split(':'); - key = _.camelCase(singleStyle[0]); + key = camelCase(singleStyle[0]); value = singleStyle[1]; if (key.length > 0 && value.length > 0) { jsonStyles[key] = value; @@ -41,7 +43,7 @@ var ProcessNodeDefinitions = function(React) { }; // Process attributes if (node.attribs) { - _.each(node.attribs, function(value, key) { + forEach(node.attribs, function(value, key) { switch (key || '') { case 'style': elementProps.style = createStyleJsonFromString(node.attribs.style); @@ -56,11 +58,11 @@ var ProcessNodeDefinitions = function(React) { }); } - if (_.contains(voidElementTags, node.name)) { + if (includes(voidElementTags, node.name)) { return React.createElement(node.name, elementProps) } else { - return React.createElement(node.name, elementProps, node.data, children); - } + return React.createElement(node.name, elementProps, node.data, children); + } } diff --git a/package.json b/package.json index f04e593..caa8df9 100644 --- a/package.json +++ b/package.json @@ -36,11 +36,17 @@ "dependencies": { "ent": "^2.2.0", "htmlparser2": "^3.8.3", - "lodash": "^3.9.3" + "lodash.camelcase": "^4.1.0", + "lodash.compact": "^3.0.1", + "lodash.find": "^4.3.0", + "lodash.foreach": "^4.2.0", + "lodash.includes": "^4.1.2", + "lodash.map": "^4.3.0" }, "devDependencies": { "coveralls": "2.11.9", "istanbul": "0.4.3", + "lodash": "^4.11.1", "mocha": "2.4.5", "mocha-lcov-reporter": "1.2.0", "react": "^0.14.7",