# state-mechanic

> A state machine that tracks and validates state, allows for hide/show logic and can run an action when a state is entered.

Latest version **1.2.45** (published 2023-10-27) · ISC license · 0 weekly downloads

## Install

```sh
npm install state-mechanic
pnpm add state-mechanic
yarn add state-mechanic
bun add state-mechanic
```

## 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.2.45 |
| Published | 2023-10-27 |
| First published | 2023-07-01 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 57 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | webelone |
| Maintainers | webelone |
| Keywords | state-mechanic, typescript, state-machine, state, machine, state-machine, node, vanilla |

## Links

- npm: https://www.npmjs.com/package/state-mechanic
- Repository: https://github.com/lenwebel/state-mechanic
- Homepage: https://github.com/lenwebel/state-mechanic#readme
- Issues: https://github.com/lenwebel/state-mechanic/issues
- npm.io page: https://npm.io/package/state-mechanic

## Alternatives

- [@reckona/mreact-store](https://npm.io/package/@reckona/mreact-store.md) — 976 weekly downloads
- [regular-state](https://npm.io/package/regular-state.md) — 410 weekly downloads
- [@pacote/flux-actions](https://npm.io/package/@pacote/flux-actions.md) — 65 weekly downloads
- [@pilotlab/lux-debug](https://npm.io/package/@pilotlab/lux-debug.md) — 39 weekly downloads
- [vue-persist-state](https://npm.io/package/vue-persist-state.md) — 19 weekly downloads

## Recent versions

- 1.2.45 (latest) — 2023-10-27
- 1.2.44 — 2023-10-27
- 1.2.43 — 2023-08-09
- 1.2.42 — 2023-08-09
- 1.2.41 — 2023-08-02
- 1.2.40 — 2023-08-01
- 1.2.39 — 2023-08-01
- 1.2.38 — 2023-08-01
- 1.2.37 — 2023-07-07
- 1.2.34 — 2023-07-07
- 1.2.33 — 2023-07-07
- 1.2.32 — 2023-07-07
- 1.2.31 — 2023-07-07
- 1.2.30 — 2023-07-07
- 1.2.29 — 2023-07-07
- … 34 more at https://npm.io/package/state-mechanic/versions

## README

# state-mechanic

And another state machine

## Install

`npm install state-mechanic`

## Usage

```javascript

import {StateConfig} from '../StateMachine/model';
import {StateMechanic} from '../StateMachine/stateMechanics';
import assert from 'assert';

export interface CreateListingModel {
    type?: 'singleCard' | 'mixedBundle' | 'sealedSingle';
}

export const config: StateConfig<CreateListingModel> = {
    type: {
        name: 'Create Listing',
        url: '/createListing/listing-type',
        state: {
            singleCard: {
                name: 'Single Card',
                url: '/createListing/single-card',
                validate: (model: CreateListingModel) => {
                    return model.type === 'singleCard';
                },
            },
            mixedBundle: {
                name: 'Mixed Bundle',
                url: '/createListing/mixed-bundle',
                state: {
                    title: {
                        name: 'Title',
                        url: '/createListing/mixed-bundle/title',
                        hide: (model?: CreateListingModel) => {
                            return ['singleCard', 'mixedBundle'].includes(model?.type);
                        },
                    },
                    tagSelection: {
                        name: 'Tag Selection',
                        url: '/createListing/mixec-bundle/tag-selection',
                        hide: (model?: CreateListingModel) => {
                            return ['singleCard', 'mixedBundle'].includes(model?.type);
                        },
                    },
                },
            },
            sealedSingle: {
                name: 'Sealed Single',
                url: '/createListing/sealed-single',
            },
        },
    },
};


const instance = new StateMechanic(config);
let state = instance.state.type;

state = state.next();
assert(state.name === 'Single Card', "should be single Card");
state = state.next();
assert(state.name === 'Mixed Bundle');
state = state.next();
assert(state.name === 'Title');
expect(1).toBe(1);


```

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