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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@polagram/core

v0.4.1

Published

`@polagram/core` is the core parsing and AST manipulation library for the Polagram project. It provides functionality to parse diagram languages (currently focusing on Mermaid Sequence Diagrams) into a generic Polagram Abstract Syntax Tree (AST).

Readme

@polagram/core

@polagram/core is the core parsing and AST manipulation library for the Polagram project. It provides functionality to parse diagram languages (currently focusing on Mermaid Sequence Diagrams) into a generic Polagram Abstract Syntax Tree (AST).

Official Website: https://polagram.org/

Installation

npm install @polagram/core

Usage

The library provides a ParserFactory to get the parser for a specific language.

import { ParserFactory, PolagramRoot } from '@polagram/core';

const mermaidCode = `
sequenceDiagram
    Alice->>John: Hello John, how are you?
    John-->>Alice: Great!
`;

try {
  // 1. Get the parser for Mermaid
  const parser = ParserFactory.getParser('mermaid');

  // 2. Parse the code into an AST
  const ast: PolagramRoot = parser.parse(mermaidCode);

  console.log(JSON.stringify(ast, null, 2));
} catch (error) {
  console.error('Parsing failed:', error);
}

Working with the AST

You can traverse the AST using the provided types:

import { ParserFactory, MessageNode } from '@polagram/core';

// ... obtain ast as above

ast.events.forEach(event => {
  if (event.kind === 'message') {
    const msg = event as MessageNode;
    console.log(`From: ${msg.from}, To: ${msg.to}, Text: ${msg.text}`);
  }
});

Features

  • Transformation Engine: A powerful pipeline to transform diagrams based on user intent.
    • Lenses: Create multiple views (e.g., "Overview", "Client Focus") from a single source diagram.
    • Layers: Composable transformation steps (remove, focus, resolve).
  • Mermaid Parsing: Supports standard Mermaid sequence diagram syntax.
    • Participants & Actors
    • Messages (sync, async, different arrow types)
    • Activations & Notes
    • Fragments (loop, alt, opt, etc.)
    • Grouping (box)
  • Robust AST: A standardized Abstract Syntax Tree for sequence diagrams.
  • Generators: Re-generate valid Mermaid code from the transformed AST.

Diagram Transformation

Polagram's core strength is its ability to transform diagrams. You can define Lenses to create different perspectives of the same complex diagram.

Concepts

  • Action: A primitive operation on the AST.
    • remove: Removes matching participants (and their messages).
    • focus: Keeps only matching participants (removes everyone else).
    • merge: Combines multiple participants into a single one (hides internal details).
  • Selector: A criteria to select nodes.
  • Layer: A configuration object defining an action and a selector.
  • Lens: A collection of Layers applied sequentially.

Example: Creating a "Client View" (Remove & Resolve)

import { TransformationEngine, Layer } from '@polagram/core';

// 1. Define Layers
const layers: Layer[] = [
  {
    action: 'remove',
    selector: { kind: 'participant', name: 'Logger' }
  },
  {
    action: 'resolve',
    selector: { kind: 'fragment', condition: 'Success' }
  }
];

// 2. Transform
const engine = new TransformationEngine();
const newAst = engine.transform(ast, layers);

Development

  • pnpm build: Build the package.
  • pnpm test: Run unit tests.

Architecture

This package uses a modular architecture:

  • Parser: Lexer/Parser based architecture for robust syntax handling.
  • AST: Strictly typed AST nodes.
  • Transformer: Layered transformation pipeline using Visitor pattern.

License

MIT