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

@iatools/cesm

v0.4.0

Published

[CESM](https://github.com/IsaacAderogba/cesm) (Content Expression State Machine) is s a JavaScript toolkit for building state machines that match content expressions.

Downloads

5

Readme

CESM, a toolkit for building content expression state machines

CESM (Content Expression State Machine) is s a JavaScript toolkit for building state machines that match content expressions.

“Content expression” is a term coined from Prosemirror, where regex-like expressions are used to constrain text editor schemas. CESM can be used for similar purposes.

CESM, like many of my projects, has been primarily built for my use cases. If you wish to extend the base functionality, you're encouraged to fork the package.

Guides

Installation

CESM can be installed as a library from NPM.

npm install @iatools/cesm

You can then use CESM’s functional API to construct different content expressions. The following demonstrates how we might construct xy*|z.

import { or, and, char, rep } from "@iatools/cesm";

const re = or(
  and(
    char("x"),
    rep(
      char("y")
      )
  ),
  char("z")
);

re.test("x") // true
re.test("xyy") // true
re.test("z") // true
re.test("a") // false

Importantly, CESM doesn’t support partial matching of a string. This would violate the anticipated usage for content expressions like those seen in Prosemirror.

Docs

States

In CESM, a state is a node in the state machine graph. Each graph can only have one accepting state, which is the last input character.

For example, a simple character can be built with just two states:

import { NFA, State } from "@iatools/cesm";

export const char = (symbol: string): NFA => {
  const inputState = new State();
  const outputState = new State({ isAccepting: true });
  inputState.addTransition(symbol, outputState);

  return new NFA({ inputState, outputState });
};

This can then be used to match single characters.

const re = char("a");
re.test("a"); // true
re.test("b"); // false

On most occassions, you won’t be dealing with individual states. Rather, you’ll be working with the higher abstraction Machines that are easily composable.

Machines

CESM supports building an NFA state machine.

A Machine is a simple wrapper over an inputState and an outputState. On most occassions, you'll be interacting with the test method on such machines that return true for valid patterns and false for invalid ones.

The real strength of a machine is in their composability. Expressions such as xy*|z are compositions of the following machines:

import { or, and, char, rep } from "@iatools/cesm";

const re = or(
  and(
    char("x"),
    rep(
      char("y")
      )
  ),
  char("z")
);

Factories

Factory functions provide a simplified interface for constructing state machines. CESM currently supports the following machines:

  • char machine for matching against single characters.
  • eps machine for matching against empy characters.
  • and machine for concatenating two sub-machines.
  • or machine for a disjunction on two sub-machines.
  • rep machine for repeating a sub-machine zero or more times.
  • plus machine for repeating a sub-machine one or more times.
  • opt machine for matching a sub-machine zero or once.

In truth, char, eps, and, or, and rep are the fundamental building block machines that all other machines can be built on top of.