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 2.0.0 to 2.0.1

sandbox/benchmark.js

34

lib/treeize.js

@@ -50,3 +50,3 @@ var util = require('util');

Treeize.prototype.log = function() {
if (this.options().log) {
if (this._options.log) {
console.log.apply(this, arguments);

@@ -83,3 +83,3 @@ }

var isArray = _.isArray(row);
var opt = merge(this.options(), options || {});
var opt = merge(this._options, options || {});

@@ -92,9 +92,9 @@ this.data.signature.type = isArray ? 'array' : 'object';

attr.key = typeof key === 'number' ? key : key.replace(/^[\*\-\+]|[\*\-\+]$/g,'');
attr.key = typeof key === 'number' ? key : key;//.replace(/^[\*\-\+]|[\*\-\+]$/g,'');
attr.fullPath = isArray ? value : key;
attr.split = attr.fullPath.split(opt.input.delimiter);
attr.path = _.initial(attr.split).join(opt.input.delimiter);//.replace(/^[\*\-\+]|[\*\-\+]$/g,'');
attr.parent = _.initial(attr.split, 2).join(opt.input.delimiter).replace(/^[\*\-\+]|[\*\-\+]$/g,'');
attr.path = attr.split.slice(0,attr.split.length-1).join(opt.input.delimiter);
attr.parent = attr.split.slice(0,attr.split.length-2).join(opt.input.delimiter);//.replace(/^[\*\-\+]|[\*\-\+]$/g,'');
attr.node = attr.split[attr.split.length - 2];
attr.attr = _.last(attr.split);
attr.attr = attr.split[attr.split.length - 1];

@@ -129,3 +129,3 @@ if (attr.attr.match(/\*/gi)) {

node.depth = attr.split.length - 1;
node.parent = _.initial(attr.split, 2).join(opt.input.delimiter);
node.parent = attr.split.slice(0, attr.split.length - 2).join(opt.input.delimiter);
node.attributes.push({ name: attr.attr, key: attr.key });

@@ -140,3 +140,3 @@ if (attr.pk) {

// backfill blueprint when not specifically defined
_.each(nodes, function(node) {
nodes.forEach(function(node) {
if (!node.blueprint.length) {

@@ -178,3 +178,3 @@ node.blueprint = node.attributes;

Treeize.prototype.grow = function(data, options) {
var opt = merge(this.options(), options || {});
var opt = merge(this._options, options || {});

@@ -207,3 +207,3 @@ // chain past if no data to grow

// copy data without original signature row before processing
_.each(originalData, function(row, index) {
originalData.forEach(function(row, index) {
if (index > 0) {

@@ -225,3 +225,3 @@ data.push(row);

_.each(data, function(row) {
data.forEach(function(row) {
var trails = {}; // LUT for trails (find parent of new node in trails path)

@@ -259,3 +259,3 @@ var trail = root = this.data.tree; // OPTIMIZATION: do we need to reset this trail for each row?

_.each(this.signature().nodes, function(node) {
this.signature().nodes.forEach(function(node) {
this.log('PROCESSING NODE>', node);

@@ -266,3 +266,3 @@ var blueprint = {};

// create blueprint for locating existing nodes
_.each(node.blueprint, function(attribute) {
node.blueprint.forEach(function(attribute) {
var key = (node.path ? (node.path + ':') : '') + attribute.name;

@@ -274,3 +274,3 @@ blueprint[attribute.name] = row[attribute.key];

// create full node signature for insertion/updating
_.each(node.attributes, function(attribute) {
node.attributes.forEach(function(attribute) {
var key = (node.path ? (node.path + ':') : '') + attribute.name;

@@ -352,3 +352,3 @@ var value = row[attribute.key];

//infinite loop kickout
if (segmentsStripped > 5) break;
if (segmentsStripped > 15) break;
}

@@ -384,3 +384,3 @@ this.log('path FOUND for location for "' + pathAttempt + '" after removing ' + segmentsStripped + ' segments');

this.log('object at node "' + node.name + '" exists as "' + trail[node.name] + '", skipping insertion and adding trail');
if (_.isObject(trail[node.name])) {
if (typeof trail[node.name] === 'object') {
trail[node.name] = merge(trail[node.name], blueprintExtended);

@@ -426,3 +426,3 @@ }

Treeize.prototype.getOptions = function() {
return this.options();
return this._options;
};

@@ -429,0 +429,0 @@

{
"name": "treeize",
"version": "2.0.0",
"version": "2.0.1",
"description": "Converts tabular row data (as from SQL joins, flat JSON, etc) to deep object graphs based on simple column naming conventions - without the use of an ORM or models.",

@@ -13,2 +13,4 @@ "main": "./lib/treeize.js",

"SQL",
"CSV",
"excel",
"tree",

@@ -15,0 +17,0 @@ "object",

# Treeize.js
[![Build Status via Travis CI](https://travis-ci.org/kwhitley/treeize.svg?branch=feature%2Fmulti-format)](https://travis-ci.org/kwhitley/treeize)
[![Build Status via Travis CI](https://travis-ci.org/kwhitley/treeize.svg)](https://travis-ci.org/kwhitley/treeize)

@@ -111,2 +111,3 @@ Converts row data (in JSON/associative array format or flat array format) to object/tree structure based on simple column naming conventions.

- [`options([options])`](#options) - getter/setter for options
- [`getOptions()`](#getOptions) - returns options
- [`setOptions(options)`](#setOptions) - merges new `[options]` with existing

@@ -118,2 +119,3 @@ - [`resetOptions()`](#resetOptions) - resets options to defaults

- [`signature([row], [options])`](#signature) - getter/setter for signature definitions
- [`getSignature()`](#getSignature) - returns currently defined signature
- [`setSignature(row, [options])`](#setSignature) - sets signature using a specific row of data/headers (preserves signature between data sets if uniformity option is enabled)

@@ -132,4 +134,2 @@ - [`clearSignature()`](#clearSignature) - clear signature between data sets (only needed when previously defined a uniform signature via `setSignature`)

- [`getOptions()`](#getOptions) - returns options
- [`getSignature()`](#getSignature) - returns currently defined signature
- [`getStats()`](#getStats) - returns object with growth statistics

@@ -467,3 +467,3 @@ - [`toString()`](#toString) - uses `util` to return data in visually formatted object graph

```js
var movieDump = [
var movieData = [
{

@@ -504,3 +504,3 @@ 'title': 'The Prestige',

movies.grow(movieDump);
movies.grow(movieData);

@@ -603,3 +603,3 @@ /*

actors.grow(movieDump);
actors.grow(moviesData);

@@ -660,1 +660,8 @@ /*

```
# Changelog
### 2.0.1
- minor README modifications
- performance tuning... ~400% performance boost over 2.0.0
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