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

mdfa

v0.9.1

Published

Create and run Finite Deterministic Machines (DFAs)

Downloads

3

Readme

mdfa

A Determinitic Finite Automata (DFA) implementation based on a monad implementation. mdfa

About

The motivation for implementing this module was to develop a DFA implementation based on the monad programming structure.

Installation

npm install mdfa

Module Usage

Define the desired DFA in a Javascript Object.

For Example the following DFA:

/*

This DFA accepts the binary input which has an even number of zeros

states: S1, S2
alphabet: 0, 1
start: S1
accept: S1
transition table:
|---|---|----|
|   | 0 |  1 |
|___|___|____|
| S1| S2| S1 |
|___|___|____|
| S2| S1| S2 |
|___|___|____|

*/

should be defined as:

var dfaDefinition = {
    states: ['S1', 'S2'],
    alphabet: ['0', '1'],
    transition: {
        'S1': {
            '0': 'S2',
            '1': 'S1'
        },
        'S2': {
            '0': 'S1',
            '1': 'S2'
        }
    },
    start: 'S1',
    accept: ['S1']
};

Then the DFA object can be created:

var createDfa = require('mdfa').create;
var dfa = createDfa(dfaDefinition);

One or more character input can be given to the DFA object using the step('string') method:

dfa.step('0').step('1001').step('1000000').step('0')

The current state can be accessed with the then(callback) method:

dfa.then(function (result) {
    console.log('current state: ', result.state);
});

To see if the DFA accepts the current state the then(callback) method can be used:

dfa.then(function (result) {
    console.log('isAccepted: ', result.isAccepted);
});

The step('string') and then(callback) methods are chainable:

dfa.then(print)
   .step('0')
   .then(print)
   .step('0')
   .then(print)
   .step('1')
   .then(print)
   .step('0100')
   .then(print)
   .step('0')
   .then(print);

// helper method to print the current state
function print(result) {
    console.log('current state: ', result.state);
    console.log('accept: ', result.isAccepted);
}

Running the tests

From inside the mdfa project folder run:

npm install

and then

npm test

Running the example

Copy and Paste the examples/dfa_even_zeros.js file to your current folder.

Install the mdfa module (npm install mdfa) if you have not already installed it.

Run: node dfa_even_zeros.js

The example demonstrates the module's usage by creating and running a DFA, which accepts the binary input with even number of zeros.