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

rhumbl-dao

v0.5.8

Published

JavaScript library for semantic graph traversal over POJOs. Dao is a collection of pure functions -- mix and match as you please.

Downloads

29

Readme

dao

JavaScript library for semantic graph traversal over POJOs. Dao is a collection of pure functions -- mix and match as you please.

Getting dao

npm install --save rhumbl-dao

Using dao

With ES6 imports:

import dao from 'dao'

dao.getEntityById(...);

With CommonJS

var dao = require('dao');

dao.getPathway(...);

As an SFX bundle:

<script src="dist/dao.js"></script>

Then anywhere in your JavaScript, you can call the globally-available dao object:

dao.getIncomingEntities(...)

Why dao?

When working with graph-like structures, we often need to query things like nodes, links and certain pathways. Dao makes it easy to search and select from your data through convenience methods.

Required dao data structure

Dao requires that you have a data object that represents a graph. This is nothing more than a POJO (plain-old JavaScript object and looks like this:

var graphData = {
  entities: [
    {id: 'Leonard Nimroy'},
    {id: 'Zachary Quinto'},
    {id: 'Gene Roddenberry'},
    {id: 'Star Trek'},
    {id: 'Heroes'}
    ...
  ],
  relationships: [
    {sourceId: '4', targetId: '8', type: 'IS_FRIENDS_WITH'},
    {sourceId: '4', targetId: '8', type: 'STARRED_IN'},
    {sourceId: '4', targetId: '8', type: 'DIRECTED'},
    ...
  ]
}

Entities must contain a required id attribute, and relationships have the 3 required attributes of type, sourceId and targetId. You can attach anything else you want to these objects.

API Reference

dao.getEntityById(entityId, entities)

Simple wrapper on top of lodash's _.find

Arguments

  1. entityId (Number): The entity's id you're trying to get
  2. entities (Array): The array of entities to search through

dao.getIncomingEntities(entityId, relationshipTypes, data)

Given entity A, get the entities B, C...,Z that have edges going towards entity A.

Example

var entities = dao.getIncomingEntities('Star Trek', ['STARRED_IN'], graphData);
// [{id: 'Leonard Nimroy'}, {id: 'Zachary Quinto'}]

Arguments

  1. entityId (Number): The id of the entity for which you
  2. relationshipTypes (Array): The relationship types that are admissible
  3. data (Object): The required data structure to search through (see required dao data structure above)

dao.getIncomingEntitiesAll(entityId, relationshipTypes, data)

Given entity A, get the entities B, C...,Z that have edges going towards entity A, and all the entities that are connected to those entities.

Arguments

  1. entityId (Number): The id of the entity for which you
  2. relationshipTypes (Array): The relationship types that are admissible
  3. data (Object): The required data structure to search through (see required dao data structure above)

dao.getOutgoingEntities(entityId, relationshipTypes, data)

Given entity A, get the entities B, C...,Z that have edges going from entity A to those entities

Example

var entities = dao.getOutgoingEntities('Zachary Quinto', ['STARRED_IN'], graphData);
// [{id: 'Star Trek'}, {id: 'Heroes'}]

Arguments

  1. entityId (Number): The id of the entity for which you
  2. relationshipTypes (Array): The relationship types that are admissible
  3. data (Object): The required data structure to search through (see required dao data structure above)

dao.getOutgoingEntitiesAll(entityId, relationshipTypes, data)

Given entity A, get the entities B, C...,Z that have edges going from entity A to those entities, and all the entities that are connected to those entities.

Arguments

  1. entityId (Number): The id of the entity for which you
  2. relationshipTypes (Array): The relationship types that are admissible
  3. data (Object): The required data structure to search through (see required dao data structure above)

dao.getPathway(entityId, relationshipTypes, algorithmName, data)

Given entity A, get the entities B, C...,Z that have edges going from entity A to those entities, and the edges comprising those pathways. The algorithmName lets you specify whether you want the immediately-connected nodes or if you want to traverse the entire pathway.

Arguments

  1. entityId (Number): The id of the entity for which you
  2. relationshipTypes (Array): The relationship types that are admissible
  3. algorithmName (String): INCOMING | INCOMING_ALL | OUTGOING | OUTGOING_ALL
  4. data (Object): The required data structure to search through (see required dao data structure above)

dao.rankDAG(dag, iterateeFn, maxIterations)

Given a collection of nodes and entities, compute the ranking of the graph.

Arguments

  1. dag (Object): Must be an object of nodes. It looks like:
var dag = {
  nodes: [
    {id: 'my node'}
    ...
  ],
}
  1. iterateeFn (function): For each node, computes the ranking for the node
  2. maxIterations = 10 (number): Optional integer setting the threshold for when the function will trigger a warning. It is assumed that your iteratee function yields an acyclic graph, so this gives you a warning when you reach the specified depth threshold

dao.getEdgeSet(entityIds, relationshipTypes, data)

Given a set of entity ids, returns the collection of edges that connect the entities

Arguments

  1. entityIds (Array): Array of entity ids
  2. relationshipTypes (function): The relationship types that are admissible
  3. data (Object): The required data structure to search through (see required dao data structure above)

About

Built by Rhumbl, the graph visualization engine for non-developers.

License

This content is released under the (http://opensource.org/licenses/MIT) MIT License.