🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

ngraph.tojson

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ngraph.tojson

Library to store graph into simple json format

1.2.0
latest
Source
npm
Version published
Weekly downloads
1.2K
-21.42%
Maintainers
1
Weekly downloads
 
Created
Source

ngraph.tojson

Library to store graph into simple json format

build status

usage

var graph = require('ngraph.graph')();
graph.addLink('hello', 'world');

var toJSON = require('ngraph.tojson');
console.log(toJSON(graph));

// Produces output:
// {"nodes":[{"id":"hello"},{"id":"world"}],"links":[{"fromId":"hello","toId":"world"}]}

You can also provide a custom transform function to transform nodes/edges before they are pushed to the output:

var g = require('ngraph.graph')();
g.addNode(1, { name: 'John' });
g.addNode(2, { name: 'Jim' });

graph.addLink(1, 2, 'Father');

var json = toJSON(g,
  function nodeTransform(node) {
    return [node.id, node.data];
  },
  function linkTransform(link) {
    return [link.fromId, link.toId, link.data];
  });

console.log(json);
// This will produce array of arrays for nodes:
// {
//   "nodes": [
//             [1, {"name": "John"}],
//             [2, {"name": "Jim"}]
//            ],
//   "links": [[1, 2, "Father"]]
// }

install

With npm do:

npm install ngraph.tojson

license

MIT

Keywords

ngraph

FAQs

Package last updated on 05 Jan 2022

Did you know?

Socket

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.

Install

Related posts