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

graph-selector

v0.10.0

Published

Parse indented text (flowchart.fun syntax) into a graph

Downloads

159

Readme

Graph Selector

Version Coverage License Build

Graph Selector is a language for describing graphs (nodes and edges) and storing arbitrary data on those nodes and edges in plaintext.

💫 Check out the Demos

Visit the demo page at graph-selector-syntax.tone-row.com to see how it works.

Introduction

Graph Selector is a syntax for defining graphs and the data associated with them. Graphs are defined in plain-text and can be parsed into a programmable JavaScript object. This makes it easier for developers to work with graphs when building applications like web applications, database applications, and process-visualization systems.

Graph Selector uses indentation and context-free grammars to create edges between nodes and store data. It also has features like matchers and models to make modeling complex graphs easier and faster.

Usage

You can use Graph Selector in your projects by installing it using npm:

npm install graph-selector

You can then use Graph Selector in your code to parse Graph Selector strings:

import { parse } from "graph-selector";

const graph = parse(`
Node A
  goes to: Node B
`);

const { nodes, edges } = graph;

// do something with nodes and edges...

Language Overview

Graph Selector has a few rules that make it easy to understand and use:

Indentation is used to create edges between nodes.

Node A
  Node B

This creates an edge from Node A to Node B.

Edge info is stored before a colon (:) and is separated from the node info by a space.

Node A
  goes to: Node B

This creates an edge from Node A to Node B with the label goes to.

Data can be stored on the nodes and edges using CSS Selector syntax. For example, #id.class1.class2[n=4][m] would be parsed into:

{
  "id": "id",
  "classes": ".class1.class2",
  "n": 4,
  "m": true
}

Parentheses can be used to reference nodes that have already been declared.

a
b  #id
c .class
d
  (a)
  (#id)
  (.class)

This creates a graph with 4 nodes and 3 edges.

Monaco Editor

Graph Selector has an export named highlight which contains a lot of the tools for using this language with the Monaco Editor. Check out this for a complete example of using this language in a Monaco editor in React, with syntax highlighting and error reporting: https://stackblitz-starters-me6lmw.stackblitz.io

Errors

In order to capture and display parsing errors in the editor, errors conform to the type ParsingError in graph-selector/src/ParseError.ts. Because in most application we imagine parsing will occur outside of the editor, displaying errors must also happen outside the error. Refer to the monaco example for what this looks like.

Context

If you would like to find out more about the development and thought process behind this language, A blog post has been published.

Contributing

Constructive feedback on the syntax and how it can be improved is the primary contribution sought by this project. You can contribute by having a discussion via Github discissions or opening an issue. Additionally, pull requests will be welcomed to help make the project more robust and flexible for developers.

You can also contribute examples that show how Graph Selector can be used to render various types of graphs with a variety of libraries, including D3, Cytoscape JS, and Recharts.

Developing

Clone the repo, then install dependencies with pnpm install. You can then start both the parser and the examples website with pnpm dev.

Goals

The goal of this project is to become stable enough to migrate the Flowchart Fun website to this syntax and use it as the basis for a new version.

Next Steps

  • ~~Add syntax highlighter packages that can be used with Monaco & CodeMirror.~~
  • Add benchmarks