Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
P

persian-tools

> 编程语言
Open source

A comprehensive, high-performance TypeScript toolkit for Persian (Farsi) text, numbers, validation, and locale utilities — works in Node.js, Bun, and the browse

1.2K stars0 likes1 views
WebsiteGitHub

About

A comprehensive, high-performance TypeScript toolkit for Persian (Farsi) text, numbers, validation, and locale utilities — works in Node.js, Bun, and the browse


✨ Features

Persian Tools provides 27+ utilities for Persian language processing:

Numbers & Text

  • Number Conversion: Persian words ↔ numbers with fuzzy matching
  • Digit Conversion: Persian ↔ Arabic ↔ English digits
  • Comma Formatting: Add/remove thousands of separators
  • Ordinal Numbers: Convert to/from ordinal forms

️ Validation & Verification

  • National ID: Validate & generate Iranian national codes (کد ملی)
  • Legal ID: Validate Iranian legal entity IDs (شناسه حقوقی)
  • Phone Numbers: Validate & extract operator info
  • Bank Cards: Validate & identify bank names
  • Extract Card Numbers: Advanced card extraction with fuzzy matching & performance optimization
  • IBAN/Sheba: Validate Iranian bank account numbers

Geographic & Location

  • Place Lookup: Find city/province by national ID
  • Capital Cities: Get province capitals
  • Coordinates: Find province from GPS coordinates
  • Vehicle Plates: Parse Iranian license plates

Financial & Utilities

  • Bill Calculator: Parse Iranian utility bills
  • Bank Detection: Identify banks from card numbers
  • IBAN Tools: Complete Iranian banking support

Text Processing

  • Persian Validation: Detect pure Persian text
  • Character Cleanup: Remove Arabic chars from Persian
  • URL Fixing: Decode Persian URLs
  • Half-Space: Fix Persian typography
  • Time Utilities: Persian time-ago & remaining time
  • Slugify: Generate URL-safe slugs from Persian text
  • Text Analysis: Comprehensive Persian text analysis

Quick Start

Installation

bash
# npm
npm install @persian-tools/persian-tools

# yarn  
yarn add @persian-tools/persian-tools

# pnpm
pnpm add @persian-tools/persian-tools

# bun (recommended)
bun add @persian-tools/persian-tools

Usage

ES Modules (Recommended)

typescript
import { numberToWords, digitsEnToFa, verifyIranianNationalId } from '@persian-tools/persian-tools';

numberToWords(1234); // "یک هزار و دویست و سی و چهار"
digitsEnToFa("123"); // "۱۲۳"
verifyIranianNationalId("0499370899"); // true

CommonJS

javascript
const { numberToWords } = require('@persian-tools/persian-tools');

Browser CDN

xml

AI Agent Skills

Persian Tools ships first-class Agent Skills — focused, retrievable instruction files that let Claude Code, Cursor, Copilot, and other AI coding assistants understand the library's modules, conventions, and Persian-language nuances without you having to paste context every time.

Install the skills into your editor

bash
# Bun
bunx skills add @persian-tools/persian-tools

# npm
npx skills add @persian-tools/persian-tools

# pnpm
pnpm dlx skills add @persian-tools/persian-tools

Each command pulls the skills/ directory into your project's local skills folder so your AI agent retrieves them automatically when you ask about a Persian Tools utility.


API Reference

Number Conversion

numberToWords - Convert numbers to Persian words

typescript
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!

wordsToNumber - Convert Persian words to numbers

typescript
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

️ Validation

National ID Validation - Validate Iranian national codes

typescript
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"

National ID Generation - Generate valid Iranian national codes

…

Phone Number Validation - Iranian mobile numbers

typescript
import { isPhoneNumberValid, phoneNumberDetail } from '@persian-tools/persian-tools';

// Validation
isPhoneNumberValid("09123456789"); // true
isPhoneNumberValid("+989123456789"); // true

// Operator detection
phoneNumberDetail("09123456789");
// {
//   province: ["البرز", "تهران", ...],
//   operator: "همراه اول",
//   type: ["permanent"]
// }

Banking & Finance

Bank Card Validation - Validate and identify Iranian bank cards

typescript
import { verifyCardNumber, getBankNameFromCardNumber } from '@persian-tools/persian-tools';

// Card validation
verifyCardNumber("6037701689095443"); // true

// Bank identification  
getBankNameFromCardNumber("6219861034529007"); // "بانک سامان"

Extract Card Numbers - Advanced card extraction with performance optimization

…

IBAN/Sheba Validation - Iranian bank account validation

typescript
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"
// }

Text Processing

Persian Text Validation - Validate and clean Persian text

typescript
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)

Digit Conversion - Convert between number systems

typescript
import { digitsEnToFa, digitsFaToEn, digitsArToFa } from '@persian-tools/persian-tools';

// English to Persian
digitsEnToFa("123456"); // "۱۲۳۴۵۶"

// Persian to English  
digitsFaToEn("۱۲۳۴۵۶"); // "123456"

// Arabic to Persian
digitsArToFa("٧٨٩"); // "۷۸۹"

Geographic & Utilities

Vehicle Plates - Parse Iranian license plates

typescript
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"
// }

Time Utilities - Persian time formatting

typescript
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(); 
// "۱ سال و ۲ ماه و ۱۵ روز"

Slugify - Generate URL-safe slugs from Persian text

…

Text Analysis - Comprehensive Persian text analysis

…

️ Development

Prerequisites

  • Bun ≥ 1.3 (as runtime and package manager)

Setup

bash
git clone https://github.com/persian-tools/persian-tools.git
cd persian-tools
bun install

Scripts

bash
bun run build        # Build the library
bun run test         # Run tests
bun run test:watch   # Watch mode testing
bun run lint         # Lint code
bun run format       # Format code
bun run lint:fix     # Fix linting issues

Architecture

  • TypeScript: Full type safety with strict mode
  • Build: Unbuild (dual ESM/CJS output)
  • Testing: Vitest with comprehensive coverage
  • Quality: ESLint + Prettier + Husky hooks

Who's Using Persian Tools?

			Maani
		
	
	
		
			

			Pooleno Exchange
		
	
	
		
			

			Bank Maskan PWA
		
	
	
		
			

			MyDong
		
	
	
		
			

			Melkba

Using Persian Tools in your project? Add it here!


In Memory of @mediv0 ️

This project is dedicated to the memory of @mediv0,
a valued contributor whose passion and work helped shape Persian Tools.
Your code lives on, and you will always be remembered in our community. ❤️


Contributing

We welcome contributions! Please see our Contributing Guide for details.

Quick Contribution Steps:

  1. Install Bun (from https://bun.sh)
  2. Fork & Clone the repository
  3. Create a feature branch: git checkout -b my-feature
  4. Make your changes with tests
  5. Run bun run test and bun run lint and bun run format to ensure everything passes
  6. Commit with conventional commits (e.g. feat: add new utility function)
  7. Submit a pull request

‍ Contributors

Ali Torki ⚠️

mssoheil ⚠️

Mohsen ⚠️

Hesam pourghazian

Amir Hossien Qasemi Moqaddam

SeyyedKhandon

msdDaliriyan ⚠️

Mahdi ⚠️

PS-PARSA ⚠️

Amirhossein Douzandeh Zenoozi ⚠️

M0rteza-M ⚠️

mediv0 ⚠️

Poorshad Shaddel ⚠️

Seyed Masih Sajadi ⚠️

Mohammad Ghonchesefidi ⚠️

Saeed Hasani Borzadaran ⚠️

Ali Madihi

Amir

Kaveh Karami

Mehdi Shah abbasian

amirali yavari

Taha Namdar

Alireza Sariri

Sajad Sohrabi

Pouriya Babaali

Mohammad norouzi

Mohamad Amin Mirzaei

Moein Moeinnia

Mostafa Ahangarha

Hamid Nasr

Sina Bayandorian


License

MIT License - see LICENSE for details.


Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScriptcard-numbercode-mellicode-melli-validatorconvert-numbers

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言