npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-graph

v0.0.1

Published

Simple library for graph manipulations

Downloads

96

Readme

#graph

Simple library for graph manipulations.

I need some graph-related operations for other project, so I decided to move them to separate module.

It is not intended to be full-featured graph manupulation (at least for now) but pull requests are welcome.

It will develop as my requirements will get more sophisticated.

Don't use it for large graphs — it uses array's .filter() methods to scan for nodes and edges, so it could be slow on large structures.

Installation

npm install node-graph

Usage

###new Graph(structure)

Returns graph instance.

var Graph = require('node-graph');

var structure = {
    nodes: [
        {
            name: 'A'
        },
        {
            name: 'B',
            youCanPutArbitraryDataOnYourNodes: { ... }
        }
    ],
    edges: [
        {
            name: 'A->B',
            from: 'A',
            to: 'B',
            youCanPutArbitraryDataOnYourEdgesToo: { ... }
        }
    ]
}

var gr = new Graph(structure);

Constructor checks that argument conforms to graph JSON schema (locates in schema/graph.json).

tl;dr It requires name field for nodes and name, from, to fields for edges. Also it checks for name uniqueness amongst edges and nodes respectively. Then is checks that every edge points to existing nodes (from and to fields containing valid node names).

###outboundEdges(node)

Returns array of edges that came out of specified node:

// You can pick outbound edges by node name
var outboundEdges = gr.outboundEdges('B');

// Or providing node object
var node = gr.getNode('B');
var outboundEdges2 = gr.outboundEdges(node);

Result example:

[{"name":"BD","from":"B","to":"D"}]

###inboundEdges(node)

Returns array of edges that came in to specified node:

// You can pick outbound edges by node name
var inboundEdges = gr.inboundEdges('D');

// Or providing node object
var node = gr.getNode('D');
var inboundEdges2 = gr.inboundEdges(node);

Result example:

[
    {"name":"BD","from":"B","to":"D"},
    {"name":"CD","from":"C","to":"D"}
]

###isTerminalNode(node)

If there are no outbound edges from specified node, returns true, false otherwise.

    // using node object
    var node = gr.getNode('D');
    gr.isTerminalNode(node);
    
    // using node name
    gr.isTerminalNode('D');

##getNode(name)

Returns node object by its name.

##getEdge(name)

Returns edge object by its name.

##License

MIT