# @turing-machine-js/builder

> A turing machine builder — declarative state-table construction. Not actively developed by the author; the same state-table pattern is also shown as an inline example in @turing-machine-js/machine's README. Contributions welcome.

Latest version **7.1.0** (published 2026-07-06) · GPL-3.0-or-later license · 0 weekly downloads

## Install

```sh
npm install @turing-machine-js/builder
pnpm add @turing-machine-js/builder
yarn add @turing-machine-js/builder
bun add @turing-machine-js/builder
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 7.1.0 |
| Published | 2026-07-06 |
| First published | 2020-05-04 |
| Weekly downloads | 0 |
| License | GPL-3.0-or-later |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 58.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Ruslan Gilmullin |
| Maintainers | mellonis |
| Keywords | turing, machine, builder |

## Links

- npm: https://www.npmjs.com/package/@turing-machine-js/builder
- Repository: https://github.com/mellonis/turing-machine-js
- Homepage: https://github.com/mellonis/turing-machine-js#readme
- Issues: https://github.com/mellonis/turing-machine-js/issues?utf8=✓&q=is%3Aissue+is%3Aopen+label%3A%22pkg%3A+builder%22+label%3Abug
- npm.io page: https://npm.io/package/@turing-machine-js/builder

## Recent versions

- 7.1.0 (latest) — 2026-07-06
- 7.0.0-alpha.8 (next) — 2026-06-02
- 7.0.0 — 2026-06-03
- 7.0.0-alpha.7 — 2026-05-30
- 7.0.0-alpha.6 — 2026-05-28
- 7.0.0-alpha.5 — 2026-05-25
- 7.0.0-alpha.4 — 2026-05-23
- 7.0.0-alpha.3 — 2026-05-21
- 7.0.0-alpha.2 — 2026-05-21
- 7.0.0-alpha.1 — 2026-05-20
- 6.4.0 — 2026-05-19
- 6.3.0 — 2026-05-19
- 6.2.0 — 2026-05-19
- 6.1.0 — 2026-05-16
- 6.0.1 — 2026-05-09
- … 15 more at https://npm.io/package/@turing-machine-js/builder/versions

## README

# @turing-machine-js/builder

[![npm (tag)](https://img.shields.io/npm/v/@turing-machine-js/builder)](https://www.npmjs.com/package/@turing-machine-js/builder)

> **Status: not actively developed by the author.** The package still works and existing tests pass — but no new features are planned. The same state-table construction pattern is shown as an inline example in [`@turing-machine-js/machine`'s README](../machine/README.md), so most users won't need this package as a separate dependency. **Contributions are welcome** if you'd like to extend it (e.g. multi-tape support, OR-patterns, a string-DSL parser shipped with the package itself).

## What it does

Constructs a Turing machine from a declarative state-table object. Every transition is a single `(state, currentSymbol) → (nextState, nextSymbol, movement)` row — the simplest possible API surface, matching how state machines are typically presented in textbooks.

```javascript
import { Tape } from '@turing-machine-js/machine';
import buildMachine from '@turing-machine-js/builder';

// Flip every bit on the tape; halt when the head reaches a blank.
const [machine, initialState] = buildMachine({
  alphabetString: ' 01',
  initialState: 'flip',
  finalStateList: ['DONE'],
  states: {
    flip: {
      '0': { state: 'flip', symbol: '1', movement: 'R' },
      '1': { state: 'flip', symbol: '0', movement: 'R' },
      ' ': { state: 'DONE', symbol: ' ', movement: 'S' },
    },
  },
});

machine.tapeBlock.replaceTape(new Tape({
  alphabet: machine.tapeBlock.alphabets[0],
  symbols: '0101'.split(''),
}));

await machine.run({ initialState, stepsLimit: 100 });
console.log(machine.tapeBlock.tapes[0].symbols.join('').trim()); // "1010"
```

See [`builder.spec.ts`](src/builder.spec.ts) for a longer worked example — a 27-state binary-string-duplicator (input `#011#` → output `#011#011#`) — including a small parser that reads the textbook `(state,symbol)→(state,symbol,movement);` notation.

## Limitations

The state-table format is intentionally minimal. It does **not** support:

- **OR-patterns** (matching multiple current symbols with one transition row). For `tapeBlock.symbol('^10$')` style patterns, use the raw `@turing-machine-js/machine` API.
- **Multi-tape machines** (`buildMachine` is single-tape only).
- **`withOverriddenHaltState` composition** (the subroutine-call mechanism). For composed machines like `library-binary-numbers`'s `minusOne`, use the raw API.

If you need any of the above, the inline state-table example in [`@turing-machine-js/machine`'s README](../machine/README.md) shows how to write your own `buildMachine`-equivalent in ~30 lines, and you can extend it to fit your case.

## Install

```sh
npm install @turing-machine-js/machine @turing-machine-js/builder
```

`@turing-machine-js/machine` is a peer dependency (so consumer and library share the same singleton sentinels — `haltState`, `ifOtherSymbol`, etc.).

## Links

- [Turing Machine](https://en.wikipedia.org/wiki/Turing_machine) on Wikipedia
- [`@turing-machine-js/machine`](https://github.com/mellonis/turing-machine-js/tree/master/packages/machine) — the core engine, sufficient on its own for most use cases

---
_Source: https://npm.io/package/@turing-machine-js/builder · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
