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

dgraph-store

v1.0.3

Published

有向图数据模型

Downloads

24

Readme

dgraph-store

构建有向图数据模型

install & import & useage

npm install --save dgraph-store

import { createStore, DGraphStore } from 'dgraph-store'

import  { createStore, DGraphStore } from 'dgraph-store'
const data = {
    nodes: [{
        id: 'A'
    },{
        id: 'B'
    }],
    edges: [
        {sourceId: 'A', 'targetId': 'B'}
    ]
}

const store = new DGraphStore(data);

Node

type Node = {
    id: String | Number
}

Edge

type Edge = {
    sourceId: String | Number,
    targetId: String | Number
}

DGraphStore

options

默认值:

{
     nodeProcessor: node => node,
     edgeProcessor: edge => edge,
     //缓存部分api计算结果
     cache: true
}

可被缓存的 api 列表:

  • isDAG
  • findCycle
  • findAllCycle
  • hasCycle
  • findAllPath

API

常用 API

constructor(data[, options]) 构造函数

isRoot(id) 判断指定节点是否无依赖节点

isLeaf(id) 判断指定节点是否无子节点

getNodeList() 获取所有节点 Array<Node>

getEdgeList() 获取所有节点连线列表 Array<Edge>

getNodeMap() 获取节点 Map<key,Node>对象

hasNode(id) 当前节点是否存在

getNode(id) 获取指定节点

getChildren(id) 获取节点下的子节点 返回:Array<Node>

getChildrenIds(id) 作用参考getChildren 返回:Array<String>

getAllChildren(id) 获取节点下的所有子节点 返回:Array<Node>

深度遍历获取所有“子节点”

getAllChildrenIds(id) 作用参考getAllChildren 返回:Array<String>

getParents(id) 获取指定节点的所依赖的节点(父节点) 返回:Array<Node>

getDependentNodes(id) 作用同getParents

getParentIds(id) 作用参考getParents 返回:Array<String>

getDependentIds(id) 作用同getParentIds

getAllParents(id) 获取指定节点的所有依赖的节点(父节点) 返回:Array<Node>

深度遍历获取所有“父节点”

getAllDependentNodes(id) 作用同getAllParents

getAllParentIds(id) 作用参考getAllParents 返回:Array<String>

getAllDependentIds(id) 作用同getAllParentIds

getInDegree(id) 获取指定节点的入度数(父节点数)返回:Number

getOutDegree(id) 获取指定节点的出度数(子节点数)返回:Number

isDAG() 判断当前图是否有向无环图 返回:Boolean

true: 无环图 false:有环图

findCycle(String | Array) 获取指定节点的所有环路 返回:Array<String>

findAllCycle() 获取当前模型下所有环路列表

findAllPath(from: String, to: String) 获取指定开始节点到目标节点的所有可达路径 返回: Array<Array<String>>

hasCycle(id) 判断指定起始顶点下是否存在闭环

hasEdge(sourceId, targetId) 判断指定两节点是否有连线

模型管理 API

addNode(node: Array<Node> | Node) 给指定 pid 节点添加子节点

addEdge(edge: Array<Edge> | Edge)

removeNode(id)

removeEdge(sourceId, targetId)

removeAllNode()

模型数据转换 API

toData() 返回模型数据

{
    nodes: Array<Node>,
    edges: Array<Edge>
}

其他

clone() 返回一个新的模型实例

createStore(data, options)

作用同new DGraphStore(...)