persian-national-id
v2.0.0
Published
This package is a validator for the Persian national id and generates a valid Persian national id
Maintainers
Readme
Persian National ID
A TypeScript/JavaScript package for validating and generating Persian (Iranian) national ID numbers (کد ملی).
Features
- ✅ Validate Persian national ID numbers
- ✅ Generate valid Persian national ID numbers
- ✅ Full TypeScript support with type definitions
- ✅ Supports both ESM and CommonJS
- ✅ Zero dependencies
- ✅ Lightweight
Installation
npm install persian-national-idUsage
ESM (ES Modules)
import { ValidNationalId, GenerateNationalId } from "persian-national-id";
// Validate a national ID
const isValid = ValidNationalId("0959744487");
console.log(isValid); // true
// Generate a valid national ID
const nationalId = GenerateNationalId();
console.log(nationalId); // e.g., '0959744487'CommonJS
const { ValidNationalId, GenerateNationalId } = require("persian-national-id");
// Validate a national ID
const isValid = ValidNationalId("1234567890");
console.log(isValid); // false
// Generate a valid national ID
const nationalId = GenerateNationalId();
console.log(nationalId); // e.g., '0959744487'API
ValidNationalId(nationalId: string): boolean
Validates a Persian national ID number.
Parameters:
nationalId(string): The national ID to validate (10 digits)
Returns:
boolean:trueif valid,falseotherwise
Example:
ValidNationalId("0959744487"); // true
ValidNationalId("1234567890"); // false
ValidNationalId("0000000000"); // falseGenerateNationalId(): string
Generates a valid Persian national ID number.
Returns:
string: A valid 10-digit national ID
Example:
const id = GenerateNationalId();
console.log(id); // e.g., '0959744487'Contributing
Contributions are welcome! This is an open-source project.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
