graphology-utils
Advanced tools
Comparing version 2.1.2 to 2.2.0
@@ -36,3 +36,3 @@ import Graph, {Attributes} from 'graphology-types'; | ||
target: unknown, | ||
attributes?: EdgeAttributes | ||
updater?: (attributes: EdgeAttributes | {}) => EdgeAttributes | ||
): void; |
@@ -8,19 +8,29 @@ /** | ||
*/ | ||
exports.addEdge = function addEdge(graph, undirected, key, source, target, attributes) { | ||
exports.addEdge = function addEdge( | ||
graph, | ||
undirected, | ||
key, | ||
source, | ||
target, | ||
attributes | ||
) { | ||
if (undirected) { | ||
if (key === null || key === undefined) | ||
graph.addUndirectedEdge(source, target, attributes); | ||
else | ||
graph.addUndirectedEdgeWithKey(key, source, target, attributes); | ||
} | ||
else { | ||
else graph.addUndirectedEdgeWithKey(key, source, target, attributes); | ||
} else { | ||
if (key === null || key === undefined) | ||
graph.addDirectedEdge(source, target, attributes); | ||
else | ||
graph.addDirectedEdgeWithKey(key, source, target, attributes); | ||
else graph.addDirectedEdgeWithKey(key, source, target, attributes); | ||
} | ||
}; | ||
exports.copyEdge = function copyEdge(graph, undirected, key, source, target, attributes) { | ||
exports.copyEdge = function copyEdge( | ||
graph, | ||
undirected, | ||
key, | ||
source, | ||
target, | ||
attributes | ||
) { | ||
attributes = Object.assign({}, attributes); | ||
@@ -31,41 +41,46 @@ | ||
graph.addUndirectedEdge(source, target, attributes); | ||
else | ||
graph.addUndirectedEdgeWithKey(key, source, target, attributes); | ||
} | ||
else { | ||
else graph.addUndirectedEdgeWithKey(key, source, target, attributes); | ||
} else { | ||
if (key === null || key === undefined) | ||
graph.addDirectedEdge(source, target, attributes); | ||
else | ||
graph.addDirectedEdgeWithKey(key, source, target, attributes); | ||
else graph.addDirectedEdgeWithKey(key, source, target, attributes); | ||
} | ||
}; | ||
exports.mergeEdge = function mergeEdge(graph, undirected, key, source, target, attributes) { | ||
exports.mergeEdge = function mergeEdge( | ||
graph, | ||
undirected, | ||
key, | ||
source, | ||
target, | ||
attributes | ||
) { | ||
if (undirected) { | ||
if (key === null || key === undefined) | ||
graph.mergeUndirectedEdge(source, target, attributes); | ||
else | ||
graph.mergeUndirectedEdgeWithKey(key, source, target, attributes); | ||
} | ||
else { | ||
else graph.mergeUndirectedEdgeWithKey(key, source, target, attributes); | ||
} else { | ||
if (key === null || key === undefined) | ||
graph.mergeDirectedEdge(source, target, attributes); | ||
else | ||
graph.mergeDirectedEdgeWithKey(key, source, target, attributes); | ||
else graph.mergeDirectedEdgeWithKey(key, source, target, attributes); | ||
} | ||
}; | ||
exports.updateEdge = function updateEdge(graph, undirected, key, source, target, attributes) { | ||
exports.updateEdge = function updateEdge( | ||
graph, | ||
undirected, | ||
key, | ||
source, | ||
target, | ||
updater | ||
) { | ||
if (undirected) { | ||
if (key === null || key === undefined) | ||
graph.updateUndirectedEdge(source, target, attributes); | ||
else | ||
graph.updateUndirectedEdgeWithKey(key, source, target, attributes); | ||
} | ||
else { | ||
graph.updateUndirectedEdge(source, target, updater); | ||
else graph.updateUndirectedEdgeWithKey(key, source, target, updater); | ||
} else { | ||
if (key === null || key === undefined) | ||
graph.updateDirectedEdge(source, target, attributes); | ||
else | ||
graph.updateDirectedEdgeWithKey(key, source, target, attributes); | ||
graph.updateDirectedEdge(source, target, updater); | ||
else graph.updateDirectedEdgeWithKey(key, source, target, updater); | ||
} | ||
}; |
@@ -8,5 +8,5 @@ /** | ||
*/ | ||
exports.copyNode = function(graph, key, attributes) { | ||
exports.copyNode = function (graph, key, attributes) { | ||
attributes = Object.assign({}, attributes); | ||
graph.addNode(key, attributes); | ||
}; |
@@ -13,1 +13,2 @@ export * from './add-edge'; | ||
export {default as memoizedForEach} from './memoized-for-each'; | ||
export {createWeightGetter} from './weight-getter'; |
@@ -25,1 +25,2 @@ /** | ||
exports.memoizedForEach = require('./memoized-for-each.js'); | ||
exports.createWeightedGetter = require('./weight-getter.js').createWeightGetter; |
@@ -18,8 +18,9 @@ /** | ||
if (!isGraph(graph)) | ||
throw new Error('graphology-utils/infer-type: expecting a valid graphology instance.'); | ||
throw new Error( | ||
'graphology-utils/infer-type: expecting a valid graphology instance.' | ||
); | ||
var declaredType = graph.type; | ||
if (declaredType !== 'mixed') | ||
return declaredType; | ||
if (declaredType !== 'mixed') return declaredType; | ||
@@ -32,6 +33,5 @@ if ( | ||
if (graph.directedSize > 0) | ||
return 'directed'; | ||
if (graph.directedSize > 0) return 'directed'; | ||
return 'undirected'; | ||
}; |
@@ -17,5 +17,4 @@ import Graph, {Attributes} from 'graphology-types'; | ||
edgeAttributes: EdgeAttributes, | ||
undirected: boolean, | ||
generatedKey: boolean | ||
undirected: boolean | ||
) => void | ||
): void; |
@@ -20,7 +20,9 @@ /** | ||
if (!isGraph(graph)) | ||
throw new Error('graphology-utils/memoized-for-each: expecting a valid graphology instance.'); | ||
throw new Error( | ||
'graphology-utils/memoized-for-each: expecting a valid graphology instance.' | ||
); | ||
var currentSource, cache; | ||
graph.forEach(function(s, t, sa, ta, e, ea, u, g) { | ||
graph.forEach(function (s, t, sa, ta, e, ea, u) { | ||
if (currentSource !== s) { | ||
@@ -31,4 +33,4 @@ currentSource = s; | ||
callback(cache, s, t, sa, ta, e, ea, u, g); | ||
callback(cache, s, t, sa, ta, e, ea, u); | ||
}); | ||
}; |
@@ -15,10 +15,5 @@ /** | ||
module.exports = function mergeClique(graph, nodes) { | ||
if (nodes.length === 0) | ||
return; | ||
if (nodes.length === 0) return; | ||
var source, | ||
target, | ||
i, | ||
j, | ||
l; | ||
var source, target, i, j, l; | ||
@@ -25,0 +20,0 @@ for (i = 0, l = nodes.length; i < l; i++) { |
@@ -15,4 +15,3 @@ /** | ||
module.exports = function mergeCycle(graph, nodes) { | ||
if (nodes.length === 0) | ||
return; | ||
if (nodes.length === 0) return; | ||
@@ -23,4 +22,3 @@ var previousNode, node, i, l; | ||
if (nodes.length === 1) | ||
return; | ||
if (nodes.length === 1) return; | ||
@@ -27,0 +25,0 @@ for (i = 1, l = nodes.length; i < l; i++) { |
@@ -15,4 +15,3 @@ /** | ||
module.exports = function mergePath(graph, nodes) { | ||
if (nodes.length === 0) | ||
return; | ||
if (nodes.length === 0) return; | ||
@@ -19,0 +18,0 @@ var previousNode, node, i, l; |
@@ -15,4 +15,3 @@ /** | ||
module.exports = function mergeStar(graph, nodes) { | ||
if (nodes.length === 0) | ||
return; | ||
if (nodes.length === 0) return; | ||
@@ -19,0 +18,0 @@ var node, i, l; |
{ | ||
"name": "graphology-utils", | ||
"version": "2.1.2", | ||
"version": "2.2.0", | ||
"description": "Miscellaneous utils for graphology.", | ||
@@ -20,8 +20,8 @@ "main": "index.js", | ||
"rename-graph-keys.js", | ||
"update-graph-keys.js" | ||
"update-graph-keys.js", | ||
"weight-getter.js" | ||
], | ||
"types": "./index.d.ts", | ||
"scripts": { | ||
"prepublishOnly": "npm run lint && npm test", | ||
"lint": "eslint '**/*.js'", | ||
"prepublishOnly": "npm test", | ||
"test": "mocha test.js" | ||
@@ -31,3 +31,3 @@ }, | ||
"type": "git", | ||
"url": "git+https://github.com/graphology/graphology-utils.git" | ||
"url": "git+https://github.com/graphology/graphology.git" | ||
}, | ||
@@ -51,11 +51,8 @@ "keywords": [ | ||
"bugs": { | ||
"url": "https://github.com/graphology/graphology-utils/issues" | ||
"url": "https://github.com/graphology/graphology/issues" | ||
}, | ||
"homepage": "https://github.com/graphology/graphology-utils#readme", | ||
"homepage": "https://github.com/graphology/graphology#readme", | ||
"peerDependencies": { | ||
"graphology-types": ">=0.20.0" | ||
}, | ||
"eslintConfig": { | ||
"extends": "@yomguithereal/eslint-config" | ||
} | ||
} |
@@ -20,7 +20,6 @@ /** | ||
// Renaming nodes | ||
graph.forEachNode(function(key, attr) { | ||
graph.forEachNode(function (key, attr) { | ||
var renamedKey = nodeKeyMapping[key]; | ||
if (typeof renamedKey === 'undefined') | ||
renamedKey = key; | ||
if (typeof renamedKey === 'undefined') renamedKey = key; | ||
@@ -33,4 +32,3 @@ renamed.addNode(renamedKey, attr); | ||
graph.forEach(function(source, target, _sa, _ta, key, attr, undirected) { | ||
graph.forEach(function (source, target, _sa, _ta, key, attr, undirected) { | ||
// Leveraging the ordered adjacency to save lookups | ||
@@ -47,9 +45,7 @@ if (source !== currentSource) { | ||
if (typeof targetRenamed === 'undefined') | ||
targetRenamed = target; | ||
if (typeof targetRenamed === 'undefined') targetRenamed = target; | ||
var renamedKey = edgeKeyMapping[key]; | ||
if (typeof renamedKey === 'undefined') | ||
renamedKey = key; | ||
if (typeof renamedKey === 'undefined') renamedKey = key; | ||
@@ -56,0 +52,0 @@ copyEdge( |
@@ -16,5 +16,4 @@ import Graph, {Attributes} from 'graphology-types'; | ||
targetAttributes: NodeAttributes, | ||
undirected: boolean, | ||
generatedKey: boolean | ||
undirected: boolean | ||
) => unknown | ||
): Graph; |
@@ -7,3 +7,3 @@ /** | ||
*/ | ||
var copyEdge = require('./add-edge.js').copyEdge; | ||
var copyEdge = require('./add-edge.js').copyEdge; | ||
@@ -18,3 +18,3 @@ module.exports = function updateGraphKeys( | ||
// Renaming nodes | ||
graph.forEachNode(function(key, attr) { | ||
graph.forEachNode(function (key, attr) { | ||
var renamedKey = nodeKeyUpdater ? nodeKeyUpdater(key, attr) : key; | ||
@@ -27,22 +27,34 @@ renamed.addNode(renamedKey, attr); | ||
graph.forEach(function(source, target, sourceAttr, targetAttr, key, attr, undirected, generatedKey) { | ||
graph.forEach(function ( | ||
source, | ||
target, | ||
sourceAttr, | ||
targetAttr, | ||
key, | ||
attr, | ||
undirected | ||
) { | ||
// Leveraging the ordered adjacency to save calls | ||
if (source !== currentSource) { | ||
currentSource = source; | ||
currentSourceRenamed = nodeKeyUpdater ? nodeKeyUpdater(source, sourceAttr) : source; | ||
currentSourceRenamed = nodeKeyUpdater | ||
? nodeKeyUpdater(source, sourceAttr) | ||
: source; | ||
} | ||
var targetRenamed = nodeKeyUpdater ? nodeKeyUpdater(target, targetAttr) : target; | ||
var targetRenamed = nodeKeyUpdater | ||
? nodeKeyUpdater(target, targetAttr) | ||
: target; | ||
var renamedKey = edgeKeyUpdater ? edgeKeyUpdater( | ||
key, | ||
attr, | ||
source, | ||
target, | ||
sourceAttr, | ||
targetAttr, | ||
undirected, | ||
generatedKey | ||
) : key; | ||
var renamedKey = edgeKeyUpdater | ||
? edgeKeyUpdater( | ||
key, | ||
attr, | ||
source, | ||
target, | ||
sourceAttr, | ||
targetAttr, | ||
undirected | ||
) | ||
: key; | ||
@@ -49,0 +61,0 @@ copyEdge( |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
24602
31
542
0
0