🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

data-net

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

data-net

Serializable (JSON.stringifiable) graph data structure (nodes connected by edges)

5.0.0
latest
Source
npm
Version published
Maintainers
1
Created
Source

data-net

Serializable (JSON.stringifiable) graph (nodes connected by edges). Multiple connections between the same nodes are possible.

Graph is a set of Nodes connected by Edges:

  Graph                Node              Edge
  .nodes[]             .data             .from
  .get edges[]         .edges[]          .to

  .node()              .remove()         .remove()
  .edge()

  .toJSON()            .toJSON()         .toJSON()
  .create(json)

  .fromJSON(json)      .id               .id
                       .graph            .graph

Examples

Graph serialization/deserialization

This example creates a "triangular" graph (3 nodes, 3 edges).

  const { Graph } = require('data-net')

  let g = Graph.create()
  let n1 = g.node('node1 data')
  let n2 = g.node({name: 'John', age: 24})
  let e1 = g.edge(n1, n2)
  let n3 = g.node(666)
  let e2 = g.edge(n2, n3, 'edge data')
  let e3 = g.edge(n3, n1)

  let sg = JSON.stringify(g)
  console.log(sg)

  let g2 = Graph.create(sg)

console output:

  {
    "nodes": [
      {
        "id": "7470b312c0465758",
        "data": "node1 data"
      },
      {
        "id": "4ba1066d42a36faf",
        "data": {
          "name": "John",
          "age": 24
        }
      },
      {
        "id": "1fa26f86bb0bdbf1",
        "data": 666
      }
    ],
    "edges": [
      {
        "id": "528fe27a0bd4908c",
        "from": "7470b312c0465758",
        "to": "4ba1066d42a36faf"
      },
      {
        "id": "0e5a3c3d2d87f181",
        "from": "4ba1066d42a36faf",
        "to": "1fa26f86bb0bdbf1",
        "data": "edge data"
      },
      {
        "id": "43a07d31be3f2ca5",
        "from": "1fa26f86bb0bdbf1",
        "to": "7470b312c0465758"
      }
    ]
  }

Keywords

net

FAQs

Package last updated on 13 Jan 2019

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