# @levidavidmurray/input-formatter

> Input that only allows numbers, and formats the input text to your desired format as you type.

Latest version **1.0.4** (published 2020-04-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install @levidavidmurray/input-formatter
pnpm add @levidavidmurray/input-formatter
yarn add @levidavidmurray/input-formatter
bun add @levidavidmurray/input-formatter
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2020-04-13 |
| First published | 2020-04-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Levi Murray |
| Maintainers | levidavidmurray |

## Links

- npm: https://www.npmjs.com/package/@levidavidmurray/input-formatter
- Repository: https://github.com/levidavidmurray/input-formatter
- npm.io page: https://npm.io/package/@levidavidmurray/input-formatter

## Recent versions

- 1.0.4 (latest) — 2020-04-13
- 1.0.3 — 2020-04-13
- 1.0.2 — 2020-04-13
- 1.0.1 — 2020-04-12
- 1.0.0 — 2020-04-11

## README

# Input Formatter
Input that only allows numbers, and formats the input text to your desired format as you type.

[Try it out!](https://levidavidmurray.github.io/input-formatter)

<img src="https://github.com/levidavidmurray/phone-input-formatter/raw/master/public/showcase.gif" alt="" width="480">

## Usage
```shell script
yarn add @levidavidmurray/input-formatter
```

```typescript
import {InputFormatter} from '@levidavidmurray/input-formatter';

const formatter = InputFormatter({
  formats: {
    3: '(xxx',
    6: '(xxx) xxx',
    10: '(xxx) xxx-xxxx',
    11: '+x (xxx) xxx-xxxx'
  },
  replaceChar: 'x',
  skipFormatOpts: [{length: 10, position: 1, skip: false}],
});

formatter.on('#input');
```

## Formatter Config

```js
{
  // `formats` takes a specified input max-length as a key, and the desired format 
  // for any numeric input string whose length is less than or equal to the max-length
  formats: {
    3: '(xxx',
    6: '(xxx) xxx',
    10: '(xxx) xxx-xxxx',
    11: '+x (xxx) xxx-xxxx'
  },

  // `replaceChar` specifies the character to replace in each format string
  replaceChar: 'x', // default 'x'

  // `skipFormatOpts` an array specifying whether or not to skip formatting when
  // the input length and caret position are at the specified length and position
  skipFormatOpts: [{length: 10, position: 1, skip: false}],
}
```

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