Comparing version 0.0.6 to 0.0.7
@@ -1,4 +0,3 @@ | ||
var _ = require('lodash'); | ||
_.inflection = require('inflection'); | ||
_.mixin(_.inflection); | ||
var _ = require('lodash'); | ||
var inflection = require('inflection'); | ||
@@ -31,10 +30,10 @@ function Treeize(options) { | ||
// set up paths for processing | ||
_.each(row, function(value, fullPath) { | ||
var splitPath = fullPath.split(localOptions.delimiter); | ||
_.each(row, function(value, attributePath) { | ||
var splitPath = attributePath.split(localOptions.delimiter); | ||
paths.push({ | ||
splitPath: splitPath.slice(0, splitPath.length - 1), | ||
fullPath: splitPath.slice(0, splitPath.length - 1).join(localOptions.delimiter), | ||
parentPath: splitPath.slice(0, splitPath.length - 2).join(localOptions.delimiter), | ||
node: splitPath.slice(splitPath.length - 2, splitPath.length - 1).join(localOptions.delimiter), | ||
splitPath: _.initial(splitPath, 1), | ||
fullPath: _.initial(splitPath, 1).join(localOptions.delimiter), | ||
parentPath: _.initial(splitPath, 2).join(localOptions.delimiter), | ||
node: splitPath[splitPath.length - 2], | ||
attribute: _.last(splitPath), | ||
@@ -48,7 +47,3 @@ value: value, | ||
paths.sort(function(a, b) { | ||
if (a.splitPath.length !== b.splitPath.length) { | ||
return a.splitPath.length < b.splitPath.length ? -1 : 1; | ||
} | ||
return a.parentPath < a.parentPath ? -1 : 1; | ||
return a.splitPath.length < b.splitPath.length ? -1 : 1; | ||
}); | ||
@@ -72,10 +67,6 @@ | ||
trail = trails[target.parentPath]; | ||
// set up first node, everythign else should have parent path | ||
if (!trail) { | ||
trail = _.findWhere(translated, blueprint); | ||
if (!trail) { | ||
trail = blueprint; | ||
translated.push(blueprint); | ||
if (!(trail = trails[target.parentPath])) { | ||
if (!(trail = _.findWhere(translated, blueprint))) { | ||
translated.push(trail = blueprint); | ||
} | ||
@@ -86,12 +77,9 @@ trails[target.parentPath] = trail; | ||
// trail is now at parent node, standing by for current node injection | ||
if (target.node) { // should skip root because '' resolves to false | ||
var isCollection = target.node === _.pluralize(target.node); | ||
if (target.node) { // should skip root | ||
var isCollection = target.node === inflection.pluralize(target.node); | ||
var node = trail[target.node] = (trail[target.node] || (isCollection ? [blueprint] : blueprint)); | ||
if (isCollection) { | ||
node = _.findWhere(trail[target.node], blueprint); | ||
if (!node) { | ||
node = blueprint; | ||
trail[target.node].push(node); | ||
} | ||
if (isCollection && !(node = _.findWhere(trail[target.node], blueprint))) { | ||
node = blueprint; | ||
trail[target.node].push(node); | ||
} | ||
@@ -98,0 +86,0 @@ |
{ | ||
"name": "treeize", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "Converts tabular row data (as from SQL joins, flat JSON, etc) to deep tree graphs based on simple column naming conventions.", | ||
@@ -5,0 +5,0 @@ "main": "./lib/treeize.js", |
@@ -20,3 +20,3 @@ treeize | ||
- The column/attribute order is not important. All attributes are sorted by depth and then alphabetically before mapping. | ||
- The column/attribute order is not important. All attributes are sorted by depth before mapping. This ensures parent nodes exist before children nodes are created within. | ||
- Each attribute name of the flat data must consist of the full path to its node & attribute, seperated by the delimiter. `id` suggests an `id` attribute on a root element, whereas `name+first` implies a `first` attribute on a `name` object within a root element. | ||
@@ -23,0 +23,0 @@ - To imply a collection in the path/attribute-name, use a plural name (e.g. "subjects" instead of "subject"). Otherwise, use a singular name for a singular object. |
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
11234
209