Graph generation and handling utils, built with pure functions.
This project is no longer being maintained.
npm install pure-graph-utils
To get a better grasp of each function's behavior, please check the tests file.
Returns an object with an 'id' and a 'value' properties.
createNode('nodeId', 'nodeValue')
// Output
{
id: 'nodeId',
value: 'nodeValue'
}
Returns a new node with newNode.id === newId
.
changeNodeId(
'newId',
createNode('nodeId', 'nodeValue')
)
// Output
{
id: 'newId',
value: 'nodeValue'
}
Returns a new node with newNode[propKey] === propValue
.
addNodeProperty(
'extraProperty',
'extraPropertyValue',
createNode('nodeId', 'nodeValue')
)
// Output
{
extraProperty: 'extraPropertyValue',
id: 'nodeId',
value: 'nodeValue'
}
Returns a new node with newNode[propKey] === propNewValue
.
editNodeProperty(
'value',
'newValue',
createNode('nodeId', 'nodeValue')
)
// Output
{
id: 'nodeId',
value: 'newValue'
}
Returns a new node without propKey.
removeNodeProperty(
'value',
createNode('nodeId', 'nodeValue')
)
// Output
{
id: 'nodeId',
}
Returns an object with node.
createGraph(createNode('nodeId', 'nodeValue'))
// Output
{
nodeId: {
connections: [],
id: 'nodeId',
value: 'nodeValue'
}
}
Returns a new graph with graph[nodeId]
adapted to newGraph[nodeNewId]
.
changeGraphNodeId(
'nodeId',
'nodeNewId',
createGraph(createNode('nodeId', 'nodeValue'))
)
// Output
{
nodeNewId: {
connections: [],
id: 'nodeNewId',
value: 'nodeValue'
}
}
Returns a new graph with node.
addNode(
createNode('id2', 'value2'),
createGraph(createNode('id1', 'value1'))
)
// Output
{
id1: {
connections: [],
id: 'id1',
value: 'value1'
},
id2: {
connections: [],
id: 'id2',
value: 'value2'
}
}
Returns a new graph with newGraph[nodeId][propKey] === propValue
.
addGraphNodeProperty(
'nodeId',
'extraProperty',
'extraPropertyValue',
createGraph(createNode('nodeId', 'nodeValue'))
)
// Output
{
nodeId: {
connections: [],
extraProperty: 'extraPropertyValue',
id: 'nodeId',
value: 'nodeValue'
}
}
Returns a new graph with newGraph[nodeId][propKey] === propNewValue
.
editGraphNodeProperty(
'nodeId',
'value',
'newValue',
createGraph(createNode('nodeId', 'nodeValue'))
)
// Output
{
nodeId: {
connections: [],
id: 'nodeId',
value: 'newValue'
}
}
Returns a new graph without graph[nodeId]
's propKey.
removeGraphNodeProperty(
'nodeId',
'value',
createGraph(createNode('nodeId', 'nodeValue'))
)
// Output
{
nodeId: {
connections: [],
id: 'nodeId'
}
}
Returns a new graph with nodeA and nodeB connected.
addConnection(
'id1',
'id2',
addNode(
createNode('id2', 'value2'),
createGraph(createNode('id1', 'value1'))
)
)
// Output
{
id1: {
connections: ['id2'],
id: 'id1',
value: 'value1'
},
id2: {
connections: ['id1'],
id: 'id2',
value: 'value2'
}
}
Returns a new graph with nodeA and nodeB disconnected.
removeConnection(
'id1',
'id2',
addConnection(
'id1',
'id2',
addNode(
createNode('id2', 'value2'),
createGraph(createNode('id1', 'value1'))
)
)
)
// Output
{
id1: {
connections: [],
id: 'id1',
value: 'value1'
},
id2: {
connections: [],
id: 'id2',
value: 'value2'
}
}
Returns a new graph with graph[nodeId]
disconnected from other nodes.
removeAllConnections(
'id1',
addConnection(
'id2',
'id3',
addConnection(
'id1',
'id3',
addConnection(
'id1',
'id2',
addNode(
createNode('id3', 'value3'),
addNode(
createNode('id2', 'value2'),
createGraph(createNode('id1', 'value1'))
)
)
)
)
)
)
// Output
{
id1: {
connections: [],
id: 'id1',
value: 'value1'
},
id2: {
connections: ['id3'],
id: 'id2',
value: 'value2'
},
id3: {
connections: ['id2'],
id: 'id3',
value: 'value3'
}
}
Returns a new graph without graph[nodeId]
.
removeNode(
'id1',
addNode(
createNode('id2', 'value2'),
createGraph(createNode('id1', 'value1'))
)
)
// Output
{
id2: {
connections: [],
id: 'id2',
value: 'value2'
}
}
npm run test
npm run test:watch
npm run build