# @bruju/automata-composer

> Basic finite state automata building by composition

Latest version **1.0.1** (published 2022-05-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install @bruju/automata-composer
pnpm add @bruju/automata-composer
yarn add @bruju/automata-composer
bun add @bruju/automata-composer
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2022-05-16 |
| First published | 2022-02-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 20.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Julian Bruyat |
| Maintainers | bruju |
| Keywords | Automata, FSA |

## Links

- npm: https://www.npmjs.com/package/@bruju/automata-composer
- Repository: https://github.com/BruJu/automata-composer
- Homepage: https://github.com/BruJu/automata-composer#readme
- Issues: https://github.com/BruJu/automata-composer/issues
- npm.io page: https://npm.io/package/@bruju/automata-composer

## Recent versions

- 1.0.1 (latest) — 2022-05-16
- 1.0.0 — 2022-02-23

## README

# Automata Composer

This package lets users build finite state automata by composing
automatas with the operators `chain` (concatenation), `or` (|),
`maybe` (?), `star` (*), `plus` (+) and `inverse` (reverse all transitions).

Transitions are strings of any length and minimization is automatically applied
when the automata is built.


## How to use

### Recognize a word

```js
import { unit } from "@bruju/automata-composer"; 
const automata = unit("hamster").build();
console.log(automata.test(["hamster"])); // true
console.log(automata.test(["ham", "ster"])); // false
```


### Recognize a known sequence

```js
import { chain, unit } from "@bruju/automata-composer"; 
const helloWorld = chain(unit("Hello"), unit("world")).build();

console.log(helloWorld.test(["Hello", "world"])); // true
```


### A more complex pattern

```js
import { chain, unit, or, plus, maybe } from "@bruju/automata-composer"; 

const theAnimals = chain(
  or(unit("Save"), unit("Kill")),
  unit("the"),
  unit("animals"),
  plus(unit("!")),
  maybe(unit("(This is a GDQ reference)"))
).build();

// Both true
console.log(theAnimals.test(["Save", "the", "animals", "!", "!", "!"]));
console.log(theAnimals.test([
  "Kill", "the", "animals", "!", "(This is a GDQ reference)"
]));
```


## Theory

Theory is partly inspired by :
- https://en.wikipedia.org/wiki/DFA_minimization
- https://www.dcs.ed.ac.uk/home/mic/FiniteStateMachines2-slides.pdf 


## License

Licensed under the MIT Licence by Julian Bruyat

---
_Source: https://npm.io/package/@bruju/automata-composer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
