# @formeus/core

> Input state and validation manager library for TS/JS

Latest version **1.4.0** (published 2023-12-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install @formeus/core
pnpm add @formeus/core
yarn add @formeus/core
bun add @formeus/core
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.4.0 |
| Published | 2023-12-31 |
| First published | 2023-03-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 26.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | hala94 |
| Keywords | form, form validation |

## Links

- npm: https://www.npmjs.com/package/@formeus/core
- npm.io page: https://npm.io/package/@formeus/core

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.4.0 (latest) — 2023-12-31
- 1.3.0 — 2023-06-05
- 1.2.0 — 2023-04-07
- 1.1.0 — 2023-04-06
- 1.0.1 — 2023-03-14
- 1.0.0 — 2023-03-11

## README

# Formeus 🌀 Core

Formeus core library written in Javascript / Typescript.

Adapters for React, Vue, Solid and Svelte are available but the core
library can also be used.

# Installation

```
yarn add @formeus/core
npm install @formeus/core
pnpm add @formeus/core
```

# Key features

- designed to work with controlled components
- coordinated synchronous and asynchronous validations
- flexible validation times
- validation caching
- protected submit

# Example

```js
const formObservable = createForm({
  initial: {
    username: "",
    password: "",
  },
  validators: {
    username: ({ username }) =>
      username.length == 0
        ? new Error("Must contain at least 1 char.")
        : undefined,
    password: ({ password }) =>
      /^((?=\S*?[A-Z])(?=\S*?[a-z])(?=\S*?[0-9]).{5,})\S/.test(password)
        ? undefined
        : new Error("1 uppercase, 1 lowercase, 1 number and at least 6 chars."),
  },
  asyncValidators: {
    username: ({ username }, signal) => {
      // username is already client side validated here
      return api
        .checkUsernameAvailable(username, signal)
        .then((isAvailable) =>
          isAvailable ? undefined : new Error("username not available")
        )
    },
  },
  onSubmitForm: ({ username, password }) => {
    api.signIn(username, password)
  },
})

// Access methods that don't change
const { update } = formObservable.getSnapshot()

// Subscribe to updates
formObservable.subscribe((result) => {
  const { values, validations, isValid, isValidating } = result
  /// Use results
})
```

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