5.0.0 • Published 5 years ago

data-net v5.0.0

Weekly downloads
6
License
MIT
Repository
github
Last release
5 years ago

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"
      }
    ]
  }
5.0.0

5 years ago

4.0.4

6 years ago

4.0.3

6 years ago

4.0.2

6 years ago

4.0.1

6 years ago

4.0.0

6 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.1.2

6 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.5

7 years ago

2.0.4

7 years ago

2.0.3

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.0

7 years ago