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

djinn

v0.1.0

Published

Finite State Automata

Downloads

5

Readme

Djinn: Finite State Automata in Javascript

Technical inspirations:

Notes from various emails:

FSMs are effectively directed graphs (with a global source), so I extracted everything possible into a directed graph class.

https://github.com/automatthew/djinn/blob/master/src/digraph.coffee

The FSA class extends Digraph. It has accept, match, and matches methods for testing input strings or arrays. It's still suffering from cruft, feature creep, and indecision. The test script shows you pretty much all the primitives it offers.

https://github.com/automatthew/djinn/blob/master/src/fsa.coffee https://github.com/automatthew/djinn/blob/master/test/fsaTest.js


I had graphs on the brain this weekend, so I refurbished Djinn.

There's now a base Digraph class that requires you to implement your own Vertex and Arc (a.k.a. node and edge) classes. So far I supply a NaiveDigraph subclass that's based on mindless OO patterns and a SequenceAcceptor (currently using NaiveDigraph, but could use any other Digraph class). The SequenceAcceptor is a limited FSM for matching strings or arrays.

Aside from refurbishings, the really cool thing that happened was the implementation of digraph-intersection. In other words, Djinn can now take two FSMs and generate an intersection of the grammars they express. String matching is a special case of FSA intersection where the string is assumed to be a trivial FSA with each state having one and only one transition to the next state.

Near Future Coolness: the intersection algorithm for finite state acceptors is apparently a special case of the composition algorithm for finite state transducers. That is, where an Acceptor can only return matches from inputs, a Transducer can return transformations. FSTransducer composition is exactly analogous to function or set composition.

Limitations: I stepped waaaay back from my idea of allowing each FSA transition to do arbitrary matching. Doing anything other than exact matching drops you straight into Cartesian Product territory. That territory may well be worth exploring for situations with known bounds on the number of arcs per vertex (aka transitions leaving each state), but I'm not assuming that constraint for now. It should be near-trivial to add later, by augmenting the way the Arc classes test equivalence.

Interoperability: AT&T's fsm and OpenFST emit and consume simple text formats. Djinn easily could be modified to emit/consume these formats. This means that a production environment could take FSMs created in the browser by Djinn and perform complex, CPU intensive operations with a highly-optimized OpenFST application. Or a browser could use Djinn to perform less intensive operations on an FSM constructed and maintained by OpenFST.

TODOS:

  • subclass of Digraph that uses an adjacency list for vertex/arc operations
  • dump/load functions for OpenFST text format
  • transducer subclass (both input and output values for each arc)
  • regex compiler (mostly for demo)
  • subclass that maintains a codebook of arc values, using integer labels for the actual arc storage.