Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

treeize

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

treeize - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

34

lib/treeize.js

@@ -5,21 +5,25 @@ var _ = require('lodash');

function expand(results) {
if (!results || !results.length) { return results; }
function options = {
delimiter: '+'
};
var translated = [];
function expand(flatData, config) {
var localOptions = _.extend(config || {}, options);
var translated = [];
_.each(results, function(row, index) {
var translatedItem = {};
var paths = [];
var trails = {};
if (!flatData || !flatData.length) { return flatData; }
_.each(flatData, function(row, index) {
var paths = [];
var trails = {};
// set up paths for processing
_.each(row, function(value, fullPath) {
var splitPath = fullPath.split('+');
var splitPath = fullPath.split(localOptions.delimiter);
paths.push({
splitPath: splitPath.slice(0, splitPath.length - 1),
fullPath: splitPath.slice(0, splitPath.length - 1).join('+'),
parentPath: splitPath.slice(0, splitPath.length - 2).join('+'),
node: splitPath.slice(splitPath.length - 2, splitPath.length - 1).join('+'),
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),
attribute: _.last(splitPath),

@@ -90,3 +94,7 @@ value: value,

exports.grow = function(rows, config) {
return expand(rows);
}
return expand(rows, config);
};
exports.set = function(config) {
_.extend(options, config);
};
{
"name": "treeize",
"version": "0.0.3",
"version": "0.0.4",
"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",

treeize
=======
_v0.0.3_
_v0.0.4_

@@ -14,8 +14,21 @@ Converts row data (in JSON/associative array format) to object/tree structure based on column naming conventions.

Treeize currently has a single function, `grow`, that takes your results/rows of flat associative data and returns a full object graph;
- `treeize.grow(flatData, options)` - takes your results/rows of flat associative data and returns a full object graph.
- `treeize.set(options)` - sets global options for the lib. For example, to use a path delimiter of '>' instead of '+', call `treeize.set({ delimiter: '>' })`
- The column/attribute order is not important. All attributes are sorted by depth before mapping.
- To imply a collection, use a plural name (e.g. "subjects" instead of "subject"). Otherwise, use a singular name.
- Use a `+` to seperate path nodes (e.g. "toys+name" implies a "toys" collection on a root level item. Each toy item would have [at least] a "name" attribute)
### Notes
- The column/attribute order is not important. All attributes are sorted by depth and then alphabetically before mapping.
- 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.
- 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.
- Use a `+` delimiter (default) to seperate path nodes. To change this, use the `treeize.set([options])` function.
### Assumptions
This library has several assumptions that make it possible.
1. That each row represents a singular child item, that may contain many repeated ancestor columns.
2. That each element in a collection node (including the root) will have a unique identifying signature (necessary to prevent duplication). This can be any one attribute, or the combination of any/all attributes.
### Example
```

@@ -22,0 +35,0 @@ var treeize = require('treeize');

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc