@iasig/idnx-validator
v1.0.0
Published
JavaScript/TypeScript library for validating Moldova national IDs (IDNP, IDNO, IDNV)
Maintainers
Readme
Moldova National IDs - Validator
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
npm install @iasig/idnx-validatorOr using yarn:
yarn add @iasig/idnx-validatorOr using pnpm:
pnpm add @iasig/idnx-validatorUsage
JavaScript
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 falseTypeScript
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 falseAPI
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:
trueif the IDNP is valid,falseotherwise
validateIDNO(value: string): boolean
Validates a Moldovan Organization ID (IDNO).
- Parameter:
value- The IDNO to validate (13-digit string starting with 1) - Returns:
trueif the IDNO is valid,falseotherwise
validateIDNV(value: string): boolean
Validates a Moldovan Vehicle ID (IDNV).
- Parameter:
value- The IDNV to validate (13-digit string starting with 3) - Returns:
trueif the IDNV is valid,falseotherwise
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:
- Checking the format using the appropriate regular expression
- 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
npm installBuild
npm run buildRun Tests
npm testRun Tests with Coverage
npm run test:coverageLicense
IDNX-Validator is open-source and available under the MIT License.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Visit iasig.md to learn more about our products.
