npm package: @iasig/idnx-validator
Description: JavaScript/TypeScript library for validating Moldova national IDs (IDNP, IDNO, IDNV)
Author: iasig.md
Latest version: 1.0.0

# Moldova National IDs - Validator

[![npm version](https://badge.fury.io/js/%40iasig%2Fidnx-validator.svg)](https://www.npmjs.com/package/@iasig/idnx-validator)
[![CI/CD](https://github.com/iasig/idnx-validator/workflows/CI%2FCD/badge.svg)](https://github.com/iasig/idnx-validator/actions)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

## Overview
IDNX-Validator is a TypeScript/JavaScript library designed for validating different types of IDs from the Republic of Moldova's national registry. This library efficiently validates personal national IDs (`validateIDNP`), organisation IDs (`validateIDNO`), and vehicle IDs (`validateIDNV`), ensuring their compliance with specific format and checksum standards.

## Features
- **TypeScript Support:** Full TypeScript support with type definitions included
- **Personal National ID Validation (`validateIDNP`):** Validates IDs assigned to individuals, ensuring they follow a specific 13-digit format and pass checksum verification
- **Organization ID Validation (`validateIDNO`):** Checks organization IDs for format compliance and accuracy based on their unique 13-digit structure
- **Vehicle ID Validation (`validateIDNV`):** Ensures vehicle IDs adhere to the prescribed 13-digit format and pass the checksum test
- **Zero Dependencies:** Lightweight with no external dependencies
- **Comprehensive Tests:** 100% test coverage

## Installation

```bash
npm install @iasig/idnx-validator
```

Or using yarn:

```bash
yarn add @iasig/idnx-validator
```

Or using pnpm:

```bash
pnpm add @iasig/idnx-validator
```

## Usage

### JavaScript

```js
const { validateIDNP, validateIDNO, validateIDNV } = require('@iasig/idnx-validator');

// Validate Personal National ID
const isValidIDNP = validateIDNP('2001234567897');
console.log(isValidIDNP); // true or false

// Validate Organization ID
const isValidIDNO = validateIDNO('1001234567896');
console.log(isValidIDNO); // true or false

// Validate Vehicle ID
const isValidIDNV = validateIDNV('3001234567898');
console.log(isValidIDNV); // true or false
```

### TypeScript

```typescript
import { validateIDNP, validateIDNO, validateIDNV } from '@iasig/idnx-validator';

// Validate Personal National ID
const isValidIDNP: boolean = validateIDNP('2001234567897');
console.log(isValidIDNP); // true or false

// Validate Organization ID
const isValidIDNO: boolean = validateIDNO('1001234567896');
console.log(isValidIDNO); // true or false

// Validate Vehicle ID
const isValidIDNV: boolean = validateIDNV('3001234567898');
console.log(isValidIDNV); // true or false
```

## API

### `validateIDNP(value: string): boolean`
Validates a Moldovan Personal National ID (IDNP).
- **Parameter:** `value` - The IDNP to validate (13-digit string starting with 2 or 09)
- **Returns:** `true` if the IDNP is valid, `false` otherwise

### `validateIDNO(value: string): boolean`
Validates a Moldovan Organization ID (IDNO).
- **Parameter:** `value` - The IDNO to validate (13-digit string starting with 1)
- **Returns:** `true` if the IDNO is valid, `false` otherwise

### `validateIDNV(value: string): boolean`
Validates a Moldovan Vehicle ID (IDNV).
- **Parameter:** `value` - The IDNV to validate (13-digit string starting with 3)
- **Returns:** `true` if the IDNV is valid, `false` otherwise

## How It Works
The library employs regular expressions and a checksum calculation method to validate the IDs. It uses three different regular expressions, each tailored to a specific type of ID:
- **IDNP_REGEX:** For personal national IDs (starts with 2 or 09)
- **IDNO_REGEX:** For organization IDs (starts with 1)
- **IDNV_REGEX:** For vehicle IDs (starts with 3)

The validation process involves:
1. Checking the format using the appropriate regular expression
2. Verifying the checksum, which is calculated based on the first 12 digits using the formula:
   - Each digit is multiplied by a weight (7, 3, or 1 in a repeating pattern)
   - The sum modulo 10 must equal the 13th digit

## Development

### Setup
```bash
npm install
```

### Build
```bash
npm run build
```

### Run Tests
```bash
npm test
```

### Run Tests with Coverage
```bash
npm run test:coverage
```

## License
IDNX-Validator is open-source and available under the [MIT License](LICENSE).

## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.

---

Visit [iasig.md](https://iasig.md) to learn more about our products.