Persian Tools provides 27+ utilities for Persian language processing:
# npm
npm install @persian-tools/persian-tools
# yarn
yarn add @persian-tools/persian-tools
# pnpm
pnpm add @persian-tools/persian-tools
ES Modules (Recommended)
import { numberToWords, digitsEnToFa, verifyIranianNationalId } from '@persian-tools/persian-tools';
numberToWords(1234); // "یک هزار و دویست و سی و چهار"
digitsEnToFa("123"); // "۱۲۳"
verifyIranianNationalId("0499370899"); // true
CommonJS
const { numberToWords } = require('@persian-tools/persian-tools');
Browser CDN
<script src="https://cdn.jsdelivr.net/npm/@persian-tools/persian-tools/build/persian-tools.umd.js"></script>
<script>
console.log(PersianTools.numberToWords(1234));
</script>
import { numberToWords } from '@persian-tools/persian-tools';
// Basic usage
numberToWords(1234); // "یک هزار و دویست و سی و چهار"
numberToWords("12,345"); // "دوازده هزار و سیصد و چهل و پنج"
// Ordinal numbers
numberToWords(3, { ordinal: true }); // "سوم"
numberToWords(21, { ordinal: true }); // "بیست و یکم"
// Supports up to MAX_SAFE_INTEGER (2^53 - 1)
numberToWords(9007199254740991); // Works perfectly!
import { wordsToNumber } from '@persian-tools/persian-tools';
// Basic conversion
wordsToNumber("سه هزار دویست و دوازده"); // 3212
wordsToNumber("منفی یک میلیون"); // -1000000
// Advanced options
wordsToNumber("دوازده هزار", {
digits: "fa", // Return Persian digits: "۱۲۰۰۰"
addCommas: true // Add commas: "12,000"
});
// Fuzzy matching (fixes typos)
wordsToNumber("یگصد و بنجاه هزار", { fuzzy: true }); // 150000
import { verifyIranianNationalId, getPlaceByIranNationalId, createIranianNationalId } from '@persian-tools/persian-tools';
// Validation
verifyIranianNationalId("0499370899"); // true
verifyIranianNationalId("1234567890"); // false
// Location lookup
getPlaceByIranNationalId("0084575948");
// { city: "تهران مرکزی", province: "تهران" }
// Generation
createIranianNationalId(); // "0499370899"
createIranianNationalId({ preventRepeatedDigits: true }); // "1234567890"
import {
createIranianNationalId,
createIranianNationalIdDetailed,
validateNationalIdChecksum
} from '@persian-tools/persian-tools';
// Basic generation
createIranianNationalId(); // "0499370899"
// Generate without repeated digits
createIranianNationalId({ preventRepeatedDigits: true }); // "1234567890"
// Detailed generation with metadata
const result = createIranianNationalIdDetailed({
preventRepeatedDigits: true,
maxRetries: 50
});
console.log(result.nationalId); // "1234567890"
console.log(result.checkDigit); // 0
console.log(result.attempts); // 1
console.log(result.hasRepeatedDigits); // false
console.log(result.digits); // [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
// Validate generated IDs
validateNationalIdChecksum(result.nationalId); // true
// Custom random generator (for testing)
createIranianNationalId({
randomGenerator: () => 0.5 // Always returns 0.5
});
import { isPhoneNumberValid, phoneNumberDetail } from '@persian-tools/persian-tools';
// Validation
isPhoneNumberValid("09123456789"); // true
isPhoneNumberValid("+989123456789"); // true
// Operator detection
phoneNumberDetail("09123456789");
// {
// province: ["البرز", "تهران", ...],
// operator: "همراه اول",
// type: ["permanent"]
// }
import { verifyCardNumber, getBankNameFromCardNumber } from '@persian-tools/persian-tools';
// Card validation
verifyCardNumber("6037701689095443"); // true
// Bank identification
getBankNameFromCardNumber("6219861034529007"); // "بانک سامان"
import { isShebaValid, getShebaInfo } from '@persian-tools/persian-tools';
// IBAN validation
isShebaValid("IR820540102680020817909002"); // true
// Bank info extraction
getShebaInfo("IR820540102680020817909002");
// {
// nickname: "parsian",
// name: "Parsian Bank",
// persianName: "بانک پارسیان",
// accountNumber: "020817909002"
// }
import { isPersian, hasPersian, toPersianChars } from '@persian-tools/persian-tools';
// Persian detection
isPersian("سلام دنیا"); // true
isPersian("Hello World"); // false
hasPersian("This has فارسی text"); // true
// Character cleanup
toPersianChars("علي"); // "علی" (fixes Arabic chars)
import { digitsEnToFa, digitsFaToEn, digitsArToFa } from '@persian-tools/persian-tools';
// English to Persian
digitsEnToFa("123456"); // "۱۲۳۴۵۶"
// Persian to English
digitsFaToEn("۱۲۳۴۵۶"); // "123456"
// Arabic to Persian
digitsArToFa("٧٨٩"); // "۷۸۹"
import { getNumberPlateInfo } from '@persian-tools/persian-tools';
// Car plates
getNumberPlateInfo("12D45147").info;
// {
// template: "12 D 451 ایران 47",
// province: "مرکزی",
// type: "Car",
// category: "دیپلمات"
// }
// Motorcycle plates
getNumberPlateInfo(12345678).info;
// {
// template: "123-45678",
// province: "مرکز تهران",
// type: "Motorcycle"
// }
import { timeAgo, remainingTime } from '@persian-tools/persian-tools';
// Time ago (Jalali calendar)
timeAgo("1400/03/17 17:55:00"); // "5 دقیقه قبل"
// Remaining time
remainingTime("2025-12-31T23:59:59Z").toString();
// "۱ سال و ۲ ماه و ۱۵ روز"
import { slugify, createSlug, slugifySimple } from '@persian-tools/persian-tools';
// Basic usage
slugify("سلام دنیا"); // "سلام-دنیا"
slugify("چگونه برنامهنویسی یاد بگیریم؟"); // "چگونه-برنامه-نویسی-یاد-بگیریم"
// Custom options
slugify("سلام دنیا", {
separator: "_", // Use underscore instead of dash
maxLength: 20, // Limit length
lowercase: false // Don't convert to lowercase
}); // "سلام_دنیا"
// Preserve numbers
slugify("سال ۱۴۰۰", { preserveNumbers: true }); // "سال-۱۴۰۰"
// Helper functions
createSlug("مقاله جدید"); // "مقاله-جدید"
slugifySimple("تست ساده"); // "تست-ساده"
import { analyzeText, getTextSummary, getTextComplexity, cleanText } from '@persian-tools/persian-tools';
// Full analysis
const analysis = analyzeText("این یک متن فارسی است.");
// {
// statistics: {
// totalWords: 5,
// totalCharacters: 20,
// persianCharacters: 15,
// // ... more stats
// },
// language: {
// primaryLanguage: "persian",
// confidence: 95,
// isPurePersian: true
// },
// readability: {
// complexity: "ساده",
// readingTime: 1,
// averageWordsPerSentence: 5
// },
// suggestions: [...]
// }
// Quick helpers
getTextSummary("سلام دنیا");
// "متن شامل 2 کلمه در 1 جمله است. زبان اصلی: فارسی (100% اطمینان). زمان مطالعه تقریبی: 1 دقیقه."
getTextComplexity("این جمله ساده است"); // "ساده"
// Text cleaning
cleanText("سَلامٌ 123 دنیا"); // "سلام ۱۲۳ دنیا"
git clone https://github.com/persian-tools/persian-tools.git
cd persian-tools
pnpm install
pnpm build # Build the library
pnpm test # Run tests
pnpm test:watch # Watch mode testing
pnpm lint # Lint code
pnpm lint:fix # Fix linting issues
Pooleno Exchange |
![]() Bank Maskan PWA |
![]() MyDong |
![]() Melkba |
Using Persian Tools in your project? Add it here!
We welcome contributions! Please see our Contributing Guide for details.
git checkout -b my-feature
pnpm test
and pnpm lint
Thanks to these amazing people (emoji key):
This project follows the all-contributors specification.
MIT License - see LICENSE for details.
Made with ❤️ by the Persian developer community