0.0.5 • Published 10 years ago

untreeize v0.0.5

Weekly downloads
1
License
MIT
Repository
-
Last release
10 years ago

untreeize

Flattens hierarchical data, e.g. reverses treeize. (see kwhitley/treeize)

npm version Travis

Installation

npm install untreeize

Usage

Non-curried version, untreeize.

var untreeize = require('untreeize').untreeize;

var tree = {
	a: 1,
	cs: [
		{
			x: 2,
			zs: [
				{r: 3, s:4, t:5},
				{r: 6, s:7, t:8}
			]
		},
		{
			x: 9,
			zs: [
				{r: 10, s:11, t:12},
				{r: 13, s:14, t:15}
			]
		}
	]
};

var flattened = untreeize(tree);

// flatten is equal to the following
flattened == [
	{
		a: 1,
		'cs:x': 2,
		'cs:zs:r': 3,
		'cs:zs:s': 4,
		'cs:zs:t': 5
	},
	{
		a: 1,
		'cs:x': 2,
		'cs:zs:r': 6,
		'cs:zs:s': 7,
		'cs:zs:t': 8
	},
	{
		a: 1,
		'cs:x': 9,
		'cs:zs:r': 10,
		'cs:zs:s': 11,
		'cs:zs:t': 12
	},
	{
		a: 1,
		'cs:x': 9,
		'cs:zs:r': 13,
		'cs:zs:s': 14,
		'cs:zs:t': 15
	}
];

Curried version, untreeizeCurried (curried via Ramda).

var untreeize = require('untreeize').untreeizeCurried;
var flattenUsingDotDelimiter = untreeize({delimiter: '.'})
var flattened = flattenUsingDotDelimiter(tree);

// flatten is equal to the following
flattened == [
	{
		a: 1,
		'cs.x': 2,
		'cs.zs.r': 3,
		'cs.zs.s': 4,
		'cs.zs.t': 5
	},
	{
		a: 1,
		'cs.x': 2,
		'cs.zs.r': 6,
		'cs.zs.s': 7,
		'cs.zs.t': 8
	},
	{
		a: 1,
		'cs.x': 9,
		'cs.zs.r': 10,
		'cs.zs.s': 11,
		'cs.zs.t': 12
	},
	{
		a: 1,
		'cs.x': 9,
		'cs.zs.r': 13,
		'cs.zs.s': 14,
		'cs.zs.t': 15
	}
];

API


untreeize ( tree , options )

This will flatten hierarchical data.

Arguments

  • tree - a hierarchical data structure, e.g. the output of treeize grow function.
  • options - options object optionally containing the following keys + delimiter - define delimiter between keys (defaults to ':' )

untreeizeCurried ( options, tree )

Same as untreeize but Curried and with tree as the last parameter.

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago