# validate-luhn-mod-n

> Validates Luhn Mod N check values

Latest version **1.0.6** (published 2022-04-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install validate-luhn-mod-n
pnpm add validate-luhn-mod-n
yarn add validate-luhn-mod-n
bun add validate-luhn-mod-n
```

## 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.6 |
| Published | 2022-04-23 |
| First published | 2020-01-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Alfred Myers |
| Maintainers | alfredmyers |
| Keywords | Luhn |

## Links

- npm: https://www.npmjs.com/package/validate-luhn-mod-n
- Repository: https://github.com/alfredmyers/validate-luhn-mod-n
- Homepage: https://github.com/alfredmyers/validate-luhn-mod-n#readme
- Issues: https://github.com/alfredmyers/validate-luhn-mod-n/issues
- npm.io page: https://npm.io/package/validate-luhn-mod-n

## Recent versions

- 1.0.6 (latest) — 2022-04-23
- 1.0.5 — 2022-02-13
- 1.0.4 — 2021-06-26
- 1.0.3 — 2021-01-11
- 1.0.2 — 2020-07-24
- 1.0.1 — 2020-03-20
- 1.0.0 — 2020-01-17

## README

# validate-luhn-mod-n

![GitHub](https://img.shields.io/github/license/alfredmyers/validate-luhn-mod-n.svg?style=flat)
![Node CI](https://github.com/alfredmyers/validate-luhn-mod-n/workflows/Node%20CI/badge.svg)
![Node.js Package](https://github.com/alfredmyers/validate-luhn-mod-n/workflows/Node.js%20Package/badge.svg)

Validates Luhn Mod N check values

Code based on <https://en.wikipedia.org/wiki/Luhn_mod_N_algorithm>
with minimal modifications.

## Installing

```sh
npm install validate-luhn-mod-n
```

## API

### Parameters

Parameter | Description
--- | ---
codePointFromCharacter | Function to obtain a code point from a character
n | Number of valid characters
input | Input string

## Using

The following example is based on the one found at <https://en.wikipedia.org/wiki/Luhn_mod_N_algorithm>

```javascript
const map = 'abcdef';  // Character to code-point map
const validateLuhnModN = require('validate-luhn-mod-n');

const valid = validateLuhnModN(character => map.indexOf(character), map.length, 'abcdefe'))

// valid === true 
```

The following example uses JavaScript's native function parseInt to do the mapping based on radix/mod 36.

```javascript
const validateLuhnModN = require('validate-luhn-mod-n');
const radix = 36
const valid = validateLuhnModN(character => Number.parseInt(character, radix), radix, '1134806PJFB000010013CD18D');

// valid === true 
```

The following example builds upon the previous one and demonstrates a possible way to do validation against an arbitrary regular expression before calculating the check character.

```javascript
const validateLuhnModN = require('validate-luhn-mod-n');
const radix = 36;
const pattern = /^([A-Z]|\d){4}\d{3}([A-Z]|\d){15}\d{2}([A-Z]|\d)$/;

if (!pattern.test(input)) {
  throw new Error('Invalid identifier format!');
}

const valid = validateLuhnModN(character => Number.parseInt(character, radix), radix, '1134806PJFB000010013CD18D');

// valid === true
```

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