Comparing version 0.3.0 to 0.4.0
@@ -0,1 +1,3 @@ | ||
import Graph from "graphology-types"; | ||
export type NetToImgOptions = { | ||
@@ -11,3 +13,3 @@ width: number; | ||
export interface NetToImgParams { | ||
export interface NetToImgParamsFromPaths { | ||
sourcePath: string; | ||
@@ -18,2 +20,10 @@ destPath: string; | ||
export interface NetToImgParamsFromGraph { | ||
graph: Graph; | ||
destPath: string; | ||
options?: NetToImgOptions; | ||
} | ||
export type NetToImgParams = NetToImgParamsFromPaths | NetToImgParamsFromGraph; | ||
export default function netToImg( | ||
@@ -20,0 +30,0 @@ params: NetToImgParams, |
28
index.js
// Deps imports: | ||
const seedrandom = require("seedrandom"); | ||
const isGraph = require("graphology-utils/is-graph"); | ||
@@ -14,4 +15,9 @@ // Local imports: | ||
function validateParams(params) { | ||
if (!params.sourcePath) | ||
throw new Error("net-to-img: expecting a `sourcePath`!"); | ||
if (params.graph) { | ||
if (!isGraph(params.graph)) | ||
throw new Error("net-to-img: expecting a valid graphology instance!"); | ||
} else { | ||
if (!params.sourcePath) | ||
throw new Error("net-to-img: expecting a `sourcePath`!"); | ||
} | ||
@@ -39,6 +45,3 @@ if (!params.destPath) throw new Error("net-to-img: expecting a `destPath`!"); | ||
// Actual program: | ||
loadGraphFn({ sourcePath }, function (err, graph) { | ||
if (err) throw new Error(err); | ||
function processGraph(graph) { | ||
// Randomness and seeds: | ||
@@ -84,3 +87,14 @@ if (seed) { | ||
); | ||
}); | ||
} | ||
// Actual program: | ||
if (params.graph) { | ||
processGraph(params.graph); | ||
} else { | ||
loadGraphFn({ sourcePath }, function (err, graph) { | ||
if (err) throw new Error(err); | ||
processGraph(graph); | ||
}); | ||
} | ||
}; |
{ | ||
"name": "net-to-img", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "A CLI tool and library to quickly render a network's topology as an image", | ||
@@ -30,2 +30,4 @@ "main": "index.js", | ||
"graphology-svg": "^0.1.0", | ||
"graphology-types": "^0.16.0", | ||
"graphology-utils": "^1.7.0", | ||
"iwanthue": "^1.4.0", | ||
@@ -36,4 +38,5 @@ "seedrandom": "^3.0.5", | ||
"devDependencies": { | ||
"graphology-generators": "^0.10.1", | ||
"prettier": "^2.0.2" | ||
} | ||
} |
@@ -30,14 +30,30 @@ # net-to-img | ||
```js | ||
const netToImg = require('net-to-img'); | ||
const netToImg = require("net-to-img"); | ||
netToImg({ | ||
sourcePath: 'path/to/graph/file', | ||
destPath: 'path/to/output/image', | ||
options: { | ||
layout: false | ||
netToImg( | ||
{ | ||
sourcePath: "path/to/graph/file", | ||
destPath: "path/to/output/image", | ||
options: { | ||
layout: false, | ||
}, | ||
}, | ||
(err) => { | ||
if (!err) console.log("Everything went well!"); | ||
} | ||
}, err => { | ||
if (!err) | ||
console.log('Everything went well!'); | ||
}); | ||
); | ||
// To directly pass a graph instance | ||
netToImg( | ||
{ | ||
graph: myGraph, | ||
destPath: "path/to/output/image", | ||
options: { | ||
layout: false, | ||
}, | ||
}, | ||
(err) => { | ||
if (!err) console.log("Everything went well!"); | ||
} | ||
); | ||
``` | ||
@@ -59,2 +75,6 @@ | ||
### v0.4.0 | ||
- Adding possibility to directly pass a `graphology` instance | ||
### v0.3.0 | ||
@@ -61,0 +81,0 @@ |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
98
17955
14
2
14
437
+ Addedgraphology-types@^0.16.0
+ Addedgraphology-utils@^1.7.0