Socket
Socket
Sign inDemoInstall

ngraph.tojson

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

ngraph.tojson

Library to store graph into simple json format


Version published
Maintainers
1
Install size
7.92 kB
Created

Readme

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

FAQs

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc