persian-phone-number-normalizer
v1.0.0
Published
Simple yet powerful package for normalizing Persian phone numbers.
Maintainers
Readme
persian-phone-number-normalizer
Validate and normalize Persian phone numbers using blazingly fast implementation which is flexible at the same time.
To install:
npm i persian-phone-number-normalizerUsage with ESM:
import { normalizeNumber } from 'persian-phone-number-normalizer'Usage with CJS:
const { normalizeNumber } = require("persian-phone-number-normalizer")Normalizing a number:
const n = '09123456789'
const normalized = normalizeNumber(n) // +989123456789Persian and Arabic numbers are automatically converted:
const n = '09۱۲3٤٥٦789'
const normalized = normalizeNumber(n) // +989123456789Validate numbers while normalizing:
const n = '0912345'
const normalized = normalizeNumber(n) // falseYou can opt out of English digit conversion or phone number validation:
const n = '091۲345'
const normalized = normalizeNumber(n, { forceEnDigits: false, validate: false }) // +9891۲345Separate functions for other use cases:
import { faToEnDigits, isValidPersianPhoneNumber } from 'persian-phone-number-normalizer'
// or
const { faToEnDigits, isValidPersianPhoneNumber } = require("persian-phone-number-normalizer")
const input = '۱۲۳۴'
const pin = faToEnDigits(input) // 1234
const phoneNumber = '۰۹۱۲۳۴۵۶۷۸۹'
const isValid = isValidPersianPhoneNumber(phoneNumber) // true
const isStrictValid = isValidPersianPhoneNumber(phoneNumber, { normalize: false }) // falseIf you want to report any issues or request features, please open an issue on GitHub.
Contributions are also welcomed.
Development
This project was created using bun init in bun v1.3.11. Bun is a fast all-in-one JavaScript runtime.
To install dependencies:
bun installTo bundle:
bun run buildGenerate types:
tscLint without applying:
bun checkLint with applying safe fixes and formatting:
bun lintRun unit tests:
bun test --concurrent --randomizeIn order to publish package:
npm loginCreate tarball and check before publishing:
bun pm packPublish to npm:
bun publish