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

mscgenjs

v7.0.2

Published

Sequence chart rendering library

Downloads

4,709

Readme

mscgen_js - core package

Implementation of MscGen and two derived languages in JavaScript.

This is the JavaScript library that takes care of parsing and rendering MscGen into sequence diagrams. You might be looking for one of these in stead:

Features

  • Parses and renders MscGen
    • Accepts all valid MscGen programs and render them correctly to sequence diagrams.
    • All valid MscGen programs accepted by mscgen_js are also accepted and rendered correctly by the original mscgen command.
    • If you find proof to the contrary: tell us.
  • Parses and renders
    Xù is a strict superset of MscGen. It adds things like alt and loop.
  • Parses and renders MsGenny
    Same as Xù, but with a simpler syntax.
  • Translates between these three languages
  • Spits out svg, GraphViz dot, doxygen and JSON.
  • runs in all modern browsers (and in Node.js).

I'm still here. How can I use this?

Prerequisites

mscgenjs works in anything with an implementation of the document object model (DOM). This includes web-browsers, client-side application shells like electron and even headless browsers like chrome headless and phantomjs. It does _not include nodejs (although it is possible to get it sorta to work even there with jsdom or with a headless browser).

Get it

npm install mscgenjs

Import it

You'll have to import the mscgenjs module somehow. There's a commonjs, an es2015 and a requirejs variant, all distributed in the mscgenjs npm module (repo: mscgenjs/mscgenjs-core).

// commonjs
const mscgenjs = require("mscgenjs");
// commonjs, but with lazy loading. Useful when you're using it in
// e.g. an electron shell without a minifier.
const mscgenjs = require("mscgenjs/dist/cjs/index-lazy");
// requirejs - assuming the module is in your root and you're loading from
//             node_modules.
define(["./node_modules/mscgenjs/dist/bundle/index.min"], function (mscgenjs) {
  // your code here
});

// ... or using the alternative notation
define(function (require) {
  var mscgenjs = require("./node_modules/mscgenjs/dist/bundle/index.min");
  // your code here
});
// es2015 modules
// if you're using webpack or rollup, it'll default to the es2015
// modules distributed in dist/es2015
import { renderMsc } from "mscgenjs";

Previously, as a workaround for webpack issue webpack/webpack#5316 you needed to include webpack-issue-5316-workaround from the dist folder. That's not necessary anymore; using require('mscgenjs') or import {renderMsc} from 'mcgenjs' works fine.

Use it

  • use the root module directly => recommended
    e.g. atom-mscgen-preview takes that approach. See the samples below
  • individually do calls to the parse and render steps => do this when you have special needs.
    This is the approach the mscgen_js and mscgenjs-inpage script take. The main reason these aren't using the root module directly is that it did not exist at the time they were written (JUN 2013 and APR 2014 respectively). Link to where this happens in mscgen_js and one where it happens in mscgenjs-inpage.

Here's some some samples for using the root module directly:

// renders the given script in the (already existing) element with id=yourCoolId
mscgenjs.renderMsc (
  'msc { a,b; a=>>b[label="render this"; }',
  {
    elementId: "yourCoolId"
  }
);

If you want to do error handling, or act on the created svg: provide a callback:

mscgenjs.renderMsc(
  'msc { a,b; a=>>b[label="render this"; }',
  {
    elementId: "yourOtherCoolId",
  },
  handleRenderMscResult,
);

function handleRenderMscResult(pError, pSuccess) {
  if (Boolean(pError)) {
    console.log(pError);
    return;
  } else if (Boolean(pSuccess)) {
    console.log("That worked - cool!");
    return;
    // the svg is in the pSuccess argument
  }
  console.log("Wat! Error nor success?");
}

The second parameter in the renderMsc call takes some options that influence rendering e.g.

mscgenjs.renderMsc (
  'a=>>b:render this;',
  {
    elementId: "yourThirdCoolId",
    inputType: "msgenny", // language to parse - default "mscgen"; other accepted languages: "xu", "msgenny" and "json"
    mirrorEntitiesOnBottom: true, // draws entities on both top and bottom of the chart - default false
    additionalTemplate: "lazy", // use a predefined template. E.g. "lazy" or "classic". Default empty
    includeSource: false, // whether the generated svg should include the source in a desc element
  },

In doc/samples you'll find a simple dynamic integration using webpack and one using requirejs.

Transpiling

You can use the second function of the root module for transpiling to and from msgenny, mscgen, xù and json and for exporting to dot and doxygen. This function does not depend on the DOM so you can use it not only in browsers & browser-likes, but also hack-free in node.

try {
  let lResult = mscgenjs.translateMsc(
    'wordwraparcs=on; you =>> me: can we translate this to Mscgen please?; me >> you: "yes, you can - use translateMsc";',
    {
      inputType: "msgenny", // defaults to mscgen - other accepted formats: msgenny, xu, json
      outputType: "mscgen", // defaults to json - other accepted formats: mscgen, msgenny, xu, dot, doxygen, ast
    },
  );
  console.log(lResult);
} catch (pError) {
  console.error(pError);
}

// result:
//
// msc {
//   wordwraparcs=true;
//
//   you,
//   me;
//
//   you =>> me [label="can we translate this to Mscgen please?"];
//   me >> you [label="yes, you can - use translateMsc"];
// }

Battle tested implementations

Software that uses mscgenjs:

Hacking on mscgenjs itself

Building mscgenjs

See build.md.

How does mscgenjs work?

You can start reading about that over here

License

This software is free software licensed under GPLv3. This means (a.o.) you can use it as part of other free software, but not as part of non free software.

Dependencies and their licenses

We built mscgen_js on various libraries, each of which have their own license:

It uses tslint and dependency-cruiser to maintain some modicum of verifiable code quality. You can see the build history in GitHub actions.

Thanks

  • Mike McTernan for creating the wonderful MscGen language, the accompanying c implementation and for releasing both to the public domain (the last one under a GPLv2 license to be precise).
  • David Majda for cooking the fantastic and lightning fast peggy parser generator.
  • Elijah Insua for jsdom, which allows us to test rendering vector graphics in Node.js without having to resort to outlandish hacks.

Build status

linting & test coverage coverage report npm stable version total downloads on npm GPL-3.0