# simple-input-formatter

> Minimalist JavaScript to make form input formatting simple

Latest version **0.3.6** (published 2023-12-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install simple-input-formatter
pnpm add simple-input-formatter
yarn add simple-input-formatter
bun add simple-input-formatter
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.6 |
| Published | 2023-12-01 |
| First published | 2023-09-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jon Nyman |
| Maintainers | jon49 |
| Keywords | input, form, html, format, simple, currency, customelement, custom-element, webcomponent, web-component |

## Links

- npm: https://www.npmjs.com/package/simple-input-formatter
- Homepage: https://github.com/jon49/simple-input-formatter#readme
- Issues: https://github.com/jon49/simple-input-formatter/issues
- npm.io page: https://npm.io/package/simple-input-formatter

## 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

- 0.3.6 (latest) — 2023-12-01
- 0.3.5 — 2023-12-01
- 0.3.4 — 2023-12-01
- 0.3.3 — 2023-12-01
- 0.3.2 — 2023-12-01
- 0.3.1 — 2023-12-01
- 0.3.0 — 2023-12-01
- 0.2.2 — 2023-11-17
- 0.2.1 — 2023-11-17
- 0.2.0 — 2023-11-17
- 0.1.5 — 2023-09-05
- 0.1.4 — 2023-09-03
- 0.1.3 — 2023-09-03
- 0.1.2 — 2023-09-01
- 0.1.1 — 2023-09-01
- … 1 more at https://npm.io/package/simple-input-formatter/versions

## README

# Simple Input Formatter

See an example <https://jon49.github.io/simple-input-formatter/>.

Format the input element to whatever you like and only submit the raw data.

This custom element is 1.1 kB minified.

Define your formatter:

```js
(() => {
    let USDollar = new Intl.NumberFormat('en-US', {
        style: 'currency',
        currency: 'USD',
    }); 

    window.currency = {
        format(value) {
            return USDollar.format(value)
        },
        isValid(value) {
            return (isNaN(value))
                ? 'Must be a number'
            : ''
        }
    }
})()
```

Put on your HTML page:

```js
<form>
    <format-input data-format="currency">
        <input
            type="number"
            step="2"
            name="test"
            placeholder="Give me a number!">
    </format-input>
    <button>OK</button>
</form>
```

See the tests to see how it works!

## Change Log

### 0.3.0

Improved handling of invalid data.

Added ability to insert error message in element using `data-show-invalid`.

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