An open API service indexing awesome lists of open source software.

https://github.com/plughacker/card-validator

A simple card validator
https://github.com/plughacker/card-validator

Last synced: 11 months ago
JSON representation

A simple card validator

Awesome Lists containing this project

README

          



Card Validator


![CI](https://github.com/plughacker/card-validator/actions/workflows/release.yml/badge.svg)

A simple card validator based on the Braintree validator

## Getting Started

1. Install the `card-validator` 💳

```bash
yarn add @malga/card-validator
# or
npm install @malga/card-validator
# or
pnpm add @malga/card-validator
```

2. Now just validate your cards

```ts
import { valid } from '@malga/card-validator'

valid.number('6274160007029307')
/*
{
card: {
niceType: 'VR',
type: 'vr',
patterns: [ 627416, 637036 ],
gaps: [],
lengths: [ 16 ],
code: { name: 'CVV', size: 3 },
matchStrength: 6
},
isPotentiallyValid: true,
isValid: true
}
*/
```

3. Mask a card number

```ts
import { maskCardNumber } from '@malga/card-validator'

maskCardNumber('0000000000000000')
// 0000 0000 0000 0000
```

## Contributing

Feel free to contribute to this project by submitting pull requests, creating documentation, or bringing ideas to make the project even better!