@statelyai/graph 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/{adjacency-list-A4_Eiwj3.mjs → adjacency-list-ITO40kmn.mjs} +33 -0
  2. package/dist/{algorithms-DBU7nmIV.mjs → algorithms-NWSB2RWj.mjs} +672 -19
  3. package/dist/algorithms.d.mts +479 -10
  4. package/dist/algorithms.mjs +1 -1
  5. package/dist/converter-CchokMDg.mjs +67 -0
  6. package/dist/{edge-list-DuHMz8hf.mjs → edge-list-CgX6bBIF.mjs} +32 -0
  7. package/dist/formats/adjacency-list/index.d.mts +35 -1
  8. package/dist/formats/adjacency-list/index.mjs +1 -1
  9. package/dist/formats/converter/index.d.mts +37 -3
  10. package/dist/formats/converter/index.mjs +1 -1
  11. package/dist/formats/cytoscape/index.d.mts +50 -2
  12. package/dist/formats/cytoscape/index.mjs +50 -2
  13. package/dist/formats/d3/index.d.mts +48 -2
  14. package/dist/formats/d3/index.mjs +48 -2
  15. package/dist/formats/dot/index.d.mts +56 -2
  16. package/dist/formats/dot/index.mjs +55 -2
  17. package/dist/formats/edge-list/index.d.mts +34 -1
  18. package/dist/formats/edge-list/index.mjs +1 -1
  19. package/dist/formats/gexf/index.d.mts +1 -1
  20. package/dist/formats/gexf/index.mjs +1 -1
  21. package/dist/formats/gml/index.d.mts +58 -2
  22. package/dist/formats/gml/index.mjs +57 -2
  23. package/dist/formats/graphml/index.d.mts +1 -1
  24. package/dist/formats/graphml/index.mjs +1 -1
  25. package/dist/formats/jgf/index.d.mts +51 -2
  26. package/dist/formats/jgf/index.mjs +51 -2
  27. package/dist/formats/mermaid/index.d.mts +201 -8
  28. package/dist/formats/mermaid/index.mjs +361 -22
  29. package/dist/formats/tgf/index.d.mts +47 -2
  30. package/dist/formats/tgf/index.mjs +46 -2
  31. package/dist/index.d.mts +320 -14
  32. package/dist/index.mjs +115 -7
  33. package/dist/{indexing-BFFVMnjF.mjs → indexing-eNDrXdDA.mjs} +31 -2
  34. package/dist/queries.d.mts +353 -8
  35. package/dist/queries.mjs +352 -8
  36. package/dist/{types-B6Tpeerk.d.mts → types-BDXC1O5b.d.mts} +1 -1
  37. package/package.json +1 -1
  38. package/dist/converter-DnbeyE_p.mjs +0 -33
@@ -1,4 +1,20 @@
1
1
  //#region src/formats/adjacency-list/index.ts
2
+ /**
3
+ * Converts a graph to an adjacency list representation.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * import { createGraph, toAdjacencyList } from '@statelyai/graph';
8
+ *
9
+ * const graph = createGraph({
10
+ * nodes: { a: {}, b: {}, c: {} },
11
+ * edges: [{ source: 'a', target: 'b' }, { source: 'a', target: 'c' }],
12
+ * });
13
+ *
14
+ * toAdjacencyList(graph);
15
+ * // { a: ['b', 'c'], b: [], c: [] }
16
+ * ```
17
+ */
2
18
  function toAdjacencyList(graph) {
3
19
  const adj = {};
4
20
  for (const node of graph.nodes) adj[node.id] = [];
@@ -8,6 +24,23 @@ function toAdjacencyList(graph) {
8
24
  }
9
25
  return adj;
10
26
  }
27
+ /**
28
+ * Parses an adjacency list into a graph.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * import { fromAdjacencyList } from '@statelyai/graph';
33
+ *
34
+ * const graph = fromAdjacencyList({
35
+ * a: ['b', 'c'],
36
+ * b: ['c'],
37
+ * c: [],
38
+ * });
39
+ *
40
+ * graph.nodes; // [{id: 'a', ...}, {id: 'b', ...}, {id: 'c', ...}]
41
+ * graph.edges; // [{sourceId: 'a', targetId: 'b', ...}, ...]
42
+ * ```
43
+ */
11
44
  function fromAdjacencyList(adj, options) {
12
45
  const directed = options?.directed ?? true;
13
46
  const seen = /* @__PURE__ */ new Set();