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

object-treeify

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-treeify - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

16

lib/index.js

@@ -7,3 +7,3 @@ const assert = require('assert');

spacerNoNeighbour: ' ',
spacerNeighbour: '| ',
spacerNeighbour: '│ ',
keyNoNeighbour: '└─ ',

@@ -20,2 +20,4 @@ keyNeighbour: '├─ '

const sortFn = (a, b) => b.localeCompare(a);
module.exports = (tree, opts = {}) => {

@@ -25,14 +27,14 @@ const ctx = buildCtx(opts);

const neighbours = [];
const keys = Object.keys(tree).sort().map(k => [k]);
const keys = Object.keys(tree).sort(sortFn).map(k => [k]);
const lookup = [tree];
while (keys.length !== 0) {
const key = keys.shift();
const key = keys.pop();
const node = lookup[key.length - 1][key[key.length - 1]];
lookup[key.length] = node;
neighbours[key.length - 1] = keys.length !== 0 && keys[0].length === key.length;
neighbours[key.length - 1] = keys.length !== 0 && keys[keys.length - 1].length === key.length;
result.push([neighbours.slice(0, key.length - 1).map(n => n ? ctx.spacerNeighbour : ctx.spacerNoNeighbour).join(''), neighbours[key.length - 1] ? ctx.keyNeighbour : ctx.keyNoNeighbour, key[key.length - 1], ['boolean', 'string', 'number'].includes(typeof node) ? `: ${node}` : ''].join(''));
if (node instanceof Object && !Array.isArray(node)) {
keys.unshift(...Object.keys(node).sort().map(k => key.concat(k)));
keys.push(...Object.keys(node).sort(sortFn).map(k => key.concat(k)));
lookup[key.length] = node;
}

@@ -43,2 +45,2 @@ }

};
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9pbmRleC5qcyJdLCJuYW1lcyI6WyJhc3NlcnQiLCJyZXF1aXJlIiwiYnVpbGRDdHgiLCJvcHRzIiwiY3R4IiwiT2JqZ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uZ3RoIC0gMV0gPyBjdHgua2V5TmVpZ2hib3VyIDogY3R4LmtleU5vTmVpZ2hib3VyLFxuICAgICAga2V5W2tleS5sZW5ndGggLSAxXSxcbiAgICAgIFsnYm9vbGVhbicsICdzdHJpbmcnLCAnbnVtYmVyJ10uaW5jbHVkZXModHlwZW9mIG5vZGUpID8gYDogJHtub2RlfWAgOiAnJ1xuICAgIF0uam9pbignJykpO1xuXG4gICAgaWYgKG5vZGUgaW5zdGFuY2VvZiBPYmplY3QgJiYgIUFycmF5LmlzQXJyYXkobm9kZSkpIHtcbiAgICAgIGtleXMucHVzaCguLi5PYmplY3Qua2V5cyhub2RlKS5zb3J0KHNvcnRGbikubWFwKGsgPT4ga2V5LmNvbmNhdChrKSkpO1xuICAgICAgbG9va3VwW2tleS5sZW5ndGhdID0gbm9kZTtcbiAgICB9XG4gIH1cblxuICByZXR1cm4gY3R4LmpvaW5lZCA9PT0gdHJ1ZSA/IHJlc3VsdC5qb2luKCdcXG4nKSA6IHJlc3VsdDtcbn07XG4iXX0=
{
"name": "object-treeify",
"version": "1.0.1",
"version": "1.0.2",
"description": "Stringify Object as tree structure",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -30,8 +30,11 @@ # object-treeify

Project was inspired by [treeify](https://github.com/notatestuser/treeify) and works almost identical. However
the algorithm is much shorter and faster, works without recursion and is very memory efficient.
the algorithm is much shorter and faster, works without recursion and is very memory efficient. Furthermore
the output is sorted alphabetically as one would expect.
## Getting Started
## Install
$ npm install --save object-treeify
## Usage
<!-- eslint-disable import/no-unresolved -->

@@ -56,4 +59,4 @@ ```js

// ├─ apples,
// | ├─ gala,
// | └─ pink lady,
// │ ├─ gala,
// │ └─ pink lady,
// └─ oranges,

@@ -65,2 +68,10 @@ // └─ mandarin,

### Features
- Output is sorted alphabetically as one would expect
- Very fast and memory efficient implementation
- Input traversed exactly once
- Dependency free and small in size
- Tests to verify correctness
## Options

@@ -85,3 +96,3 @@

Type: `string`<br>
Default: `| `
Default: `│ `

@@ -88,0 +99,0 @@ Prefix for depth level when a further neighbour is present.

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