
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
High performance conversion of flat data (like SQL result rows) into nested objects.
treem converts flat data (like SQL rows) into an object tree. The tree structure is determined by the columns' names.
Flat data :
const movies = [{
name: 'Rogue one',
'+actors.firstName': 'Felicity',
'+actors.lastName': 'Jones'
}, {
name: 'Rogue one',
'+actors.firstName': 'Diego',
'+actors.lastName': 'Luna'
}, {
name: 'Star Wars: The Force Awakens',
'+actors.firstName': 'Harrison',
'+actors.lastName': 'Ford'
}, {
name: 'Star Wars: The Force Awakens',
'+actors.firstName': 'Daisy',
'+actors.lastName': 'Ridley'
}];
Result :
[ { name: 'Rogue one',
actors:
[ { firstName: 'Felicity', lastName: 'Jones' },
{ firstName: 'Diego', lastName: 'Luna' } ] },
{ name: 'Star Wars: The Force Awakens',
actors:
[ { firstName: 'Harrison', lastName: 'Ford' },
{ firstName: 'Daisy', lastName: 'Ridley' } ] } ]
npm install treem
import Treem from 'treem';
// ES5: var Treem = require('treem').default;
const rows = [{
name: 'Rogue one',
'+actors.firstName': 'Felicity'
...
}];
const treem = new Treem();
treem.fill(rows);
treem.data === [{
name: 'Rogue one',
actors: [{
firstName: 'Felicity'
...
]];
treem takes flat data to produce an object tree. Flat data can be :
Orthogonally, flat data can be :
The structure of the tree is determined by a convention on the columns' naming. The convention defines, by default, 3 symbols :
. : defines childrenbook.author.name+ : defines an array instead of a single object.+movies.+actors# : defines keys of the object. If no key is provided, all properties of the object are considered as a key. Defining a key improves performances and allows object reuse (see the reuseObject option).actor.#idThe result produced by treem can be :
There are 2 functions to provide data to a treem instance :
const treem = new Treem({
symbols: {
key: '#',
collection: '+',
separator: '.'
},
root: 'collection',
prune: true,
reuseObject : true,
overwriteObject : false,
headers: {
id: 'id',
name: 'name',
petName: 'pet.name'
},
wrap: {
single: node => new Model(),
collection: node => new ModelCollection()
},
detect: {
key: node => { return {
check: node === 'id',
name : 'id'
}},
collection: node => { return {
check: node.startsWith('*'),
name : node.substring(1)
}},
}
});
symbolsaccepted values: object with collection, key, and separator properties
Redefines the symbols used by treem to detect collection, key, and children. Example:
new Treem({
symbols: {
key: '#',
collection: '+',
separator: '.'
}
});
pruneaccepted values: true (default), false or a callback
Removes null or undefined elements. prune can also accept a callback. Example :
new Treem({
prune: element => element === undefined || element === null
});
rootaccepted values: 'collection' (default) or 'single'
Defines treem.data as either an array or an object.
reuseObjectaccepted values: 'key' (default), true or false
Reuses an object if multiple instances of it are detected. Example :
const movies = [{
name: 'Rogue one',
'+actors.#id': 1,
'+actors.firstName': 'Felicity',
'+actors.lastName': 'Jones'
}, {
name: 'Rogue one',
'+actors.#id': 2,
'+actors.firstName': 'Anthony',
'+actors.lastName': 'Daniels'
}, {
name: 'Star Wars: The Force Awakens',
'+actors.#id': 3,
'+actors.firstName': 'Harrison',
'+actors.lastName': 'Ford'
}, {
name: 'Star Wars: The Force Awakens',
'+actors.#id': 2,
'+actors.firstName': 'Anthony',
'+actors.lastName': 'Daniels'
}];
Here the actor 'Anthony Daniels' appear in both movies. treem will use the same object instead of duplicate it.
ReuseObject can have 3 values :
overwriteObjectaccepted values: false (default) or true
Overwrites single objects if values are different on subsequent rows.
headersaccepted values: object
Defines the columns headers and aliases. Useful if you can't change the columns' names. If this option is not defined, headers are taken from the first row of the flat data. Example:
const movies = [{
name: 'Rogue one',
id: 1,
firstName: 'Felicity',
lastName: 'Jones'
...
}];
new Treem({ headers: { name: 'name', id: '+actors.#id', firstName: '+actors.firstName', lastName: '+actors.lastName', } });
wrapaccepted values: {single: function, collection: function}
Wraps custom classes about single elements and collection elements. The function to be provided takes the current node as a parameter and returns an instance of the custom class. The custom class for single elements shall let its properties be set and gotten. The custom class for collection elements shall have a push function.
See the wiki for an example.
detectaccepted values: {key: function, collection: function}
Defines a custom way to detect keys and collections by providing a callback. The callback takes the current node as a parameter and returns an object with 2 properties :
See the wiki for an example with pluralization.
FAQs
High performance conversion of flat data (like SQL result rows) into nested objects.
The npm package treem receives a total of 950 weekly downloads. As such, treem popularity was classified as not popular.
We found that treem demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.