# payment-formatter

> A flexible, lightweight library to format payment card numbers

Latest version **1.0.4** (published 2018-07-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install payment-formatter
pnpm add payment-formatter
yarn add payment-formatter
bun add payment-formatter
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2018-07-10 |
| First published | 2018-02-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 16 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 19 |
| Author | jxom |
| Maintainers | jmoxey |
| Keywords | payment, formatter, credit, debit, card, cvc, expiry |

## Links

- npm: https://www.npmjs.com/package/payment-formatter
- Repository: https://github.com/medipass/payment-formatter
- Homepage: https://github.com/medipass/payment-formatter#readme
- Issues: https://github.com/medipass/payment-formatter/issues
- npm.io page: https://npm.io/package/payment-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

- 1.0.4 (latest) — 2018-07-10
- 1.0.3 — 2018-05-18
- 1.0.2 — 2018-02-07
- 1.0.1 — 2018-02-07
- 0.0.1 — 2018-02-06
- 0.0.0 — 2018-02-06

## README

# payment-formatter

> A flexible, lightweight (1.5kB), non-dependant library to format payment card input fields. 

## Install

```
$ npm install payment-formatter
```

## Usage

```js
import paymentFormatter from 'payment-formatter';

paymentFormatter({
  selector: 'input#card-number',
  inputType: 'cardNumber'
});
paymentFormatter({
  inputType: 'expiry',
  selector: 'input#card-expiry'
})
paymentFormatter({
  cardType: 'mastercard',
  inputType: 'cvc',
  selector: 'input#card-cvc'
})
```

or with pure HTML (useful for payment fields within an iframe):

```html
<html>
  <body>
    <input id="card-number" auto-complete="cc-number" pattern="[0-9]*" placeholder="Card number" type="text">
    <input id="card-expiry" auto-complete="cc-expiry" pattern="[0-9]*" placeholder="Card expiry" type="text">
    <input id="card-cvc" auto-complete="cc-cvc" pattern="[0-9]*" placeholder="Card cvc" type="text">
    <script src="https://unpkg.com/payment-formatter@latest/umd/index.js"></script>
    <script>
      paymentFormatter({
        inputType: 'cardNumber',
        selector: 'input#card-number'
      })
      paymentFormatter({
        inputType: 'expiry',
        selector: 'input#card-expiry'
      })
      paymentFormatter({
        cardType: 'mastercard',
        inputType: 'cvc',
        selector: 'input#card-cvc'
      })
    </script>
  </body>
</html>

```

## API

### paymentFormatter({ cardType, inputType, selector })

#### cardType

Type: `string` (required for `inputType = 'cvc'`)<br>
Type of card. E.g.: `mastercard`, `amex`, `visa`

#### inputType

Type: `string` (required)<br>
Type of payment input. Available: `cardNumber`, `cvc`, `expiry`

#### selector

Type: `string` (required)<br>
CSS selector of the targeted input field.

## License

MIT © [Medipass Solutions](https://medipass.com.au/)

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