2.1.1 • Published 3 years ago
@tangle/test v2.1.1
@tangle/test
Example Usage
To build a graph of nodes like:
A
/ \
B C
\ /
Dassuming direction is top->bottom
const { buildNodes, buildGraph } = require('@tangle/test')
const nodes = buildNodes(`
A-->B[{ name: felix }]
A-->C
B-->D
C-->D
`)
// => {
// A: {
// key: 'A',
// data: {},
// previous: null,
// history: []
// },
// B: {
// key: 'B',
// data: { name: felix },
// previous: ['A'],
// history: ['A']
// },
// C: {
// key: 'C',
// data: {},
// previous: ['A'],
// history: ['A']
// },
// D: {
// key: 'D',
// data: {},
// previous: ['B', 'C'],
// history: ['B','A','C']
// }
// }
```js
const graph = buildGraph(`
A-->B[{ name: felix }]
A-->C
B-->D
C-->D
`)
// => @tangle/graph instance
graph.getBacklinks('B')
// => ['A']API
buildNodes(mermaid, opts) => nodes
where:
mermaidString - a mermaid-js like graph stringoptsObject - optionalopts.dataFieldString optionally nest the data input under anode.data[dataField]
nodesObject - the nodes described in your mermaid diagram, format{ nodeId: node }
buildGraph(mermaid, opts) => graph
where:
mermaidString - a mermaid-js like graph stringoptsObject - optionalopts.dataFieldString optionally nest the data input under anode.data[dataField]
graph- a@tangle/graphinstance
Features
Draw arrows however
A-->BA --> BA -> BA > B
Chain arrows
A-->B-->Cthis is the same as
A-->B
B-->CCombining this with indenting can make it a lot easier to visualise branching graphs:
A-->B-->C------>Z
B-->X-->Y-->ZJSON5 values
we parse values with json5, so you can do things like
A[null] --> B[{ set: 'dog' }] --> C[100]and you'll get the value your would expect (not just strings).
NOTE:
json5means you don't need to wrap everything in ""- Strings will still come back as strings
- this feature might have spicy unresolved edge cases!