Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

railroad-diagrams

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

railroad-diagrams

A small JS+SVG library for drawing railroad syntax diagrams.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is railroad-diagrams?

The railroad-diagrams npm package is a library that allows users to generate SVG diagrams that visually represent context-free grammars, typically used in documentation for programming languages, command line tools, or web APIs. These diagrams are known as 'railroad diagrams' or 'syntax diagrams' and provide a visual way to describe the grammar in a more readable format than plain text or regular expressions.

What are railroad-diagrams's main functionalities?

Creating simple diagrams

This code sample demonstrates how to create a simple railroad diagram with two nodes, 'A' and 'B', connected by an arrow. The resulting SVG is then appended to the body of the document.

var Diagram = require('railroad-diagrams');
var diagram = Diagram('A', '->', 'B');
document.body.appendChild(diagram.toSVG());

Complex diagrams with choices and sequences

This code sample shows how to create a more complex railroad diagram with a sequence of nodes, including a choice between 'B' and 'C'. The resulting SVG is appended to the body of the document.

var Diagram = require('railroad-diagrams');
var diagram = Diagram(
  Diagram.Sequence('A', Diagram.Choice(0, 'B', 'C'), 'D')
);
document.body.appendChild(diagram.toSVG());

Optional and repeated elements

This code sample illustrates how to create a railroad diagram with optional and repeated elements. 'B' is marked as optional, and 'C' can be repeated zero or more times.

var Diagram = require('railroad-diagrams');
var diagram = Diagram(
  'A',
  Diagram.Optional('B'),
  Diagram.ZeroOrMore('C'),
  'D'
);
document.body.appendChild(diagram.toSVG());

Comments and styling

This code sample demonstrates how to add comments to the diagram and apply custom styling to the SVG elements.

var Diagram = require('railroad-diagrams');
var diagram = Diagram(
  Diagram.Comment('Start'),
  'A',
  Diagram.Comment('End')
);
diagram.addTo(document.body, {stroke: '#000', 'stroke-width': 3});

Other packages similar to railroad-diagrams

Keywords

FAQs

Package last updated on 09 Mar 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc