Giter Site home page Giter Site logo

persian-tools / persian-tools Goto Github PK

View Code? Open in Web Editor NEW
1.0K 14.0 113.0 4.14 MB

An anthology of a variety of tools for the Persian language in javascript

Home Page: http://persian-tools.js.org/

License: MIT License

JavaScript 0.51% TypeScript 98.97% Makefile 0.43% Shell 0.10%
number-to-words words-to-numbers verify-bank-nunber iranian-national-id verify-national-id persian-language persian-characters iban sheba card-number

persian-tools's Introduction

Persian tools

PersianTools is a standalone, library-agnostic JavaScript that enables some of the Persian features for use in the JavaScript.

Rate on Openbase CI/CD codecov GitHub license PRs Welcome CodeFactor GitHub contributors Wallaby.js


Features

Getting started

There are two main ways to get PersianTools.js in your JavaScript project: via script tags or by installing it from NPM and using a build tool like Parcel, WebPack, or Rollup.

via Script Tag

Add the following code to an HTML file:

<html>
	<head>
		<!-- Load PersianTools.js -->
		<script src="https://cdn.jsdelivr.net/npm/@persian-tools/persian-tools/build/persian-tools.umd.js"></script>

		<!-- Place your code in the script tag below. You can also use an external .js file -->
		<script type="text/javascript">
			// Notice there is no 'import' statement. 'all persian-tools functions like digitsEnToFa, etc...' is available on the index-page
			// because of the script tag above.

			// Takes a string made of English digits only, and returns a string that represents the same number but with Persian digits
			var convertToFa = PersianTools.digitsEnToFa(1234567);

			// etc...
		</script>
	</head>

	<body></body>
</html>

Open up that html file in your browser, and the code should run!

Install

Install the PersianTools to your project using yarn or npm. Note: Because we use ES2017 syntax (such as import), this workflow assumes you are using a modern browser, or a bundler/transpiler to convert your code to something older browsers understand.

$ npm install --save @persian-tools/persian-tools

or

$ yarn add @persian-tools/persian-tools

Simple usage

import * as persianTools from "@persian-tools/persian-tools";
// or
import { digitsEnToFa } from "@persian-tools/persian-tools";

// Takes a string made of English digits only, and returns a string that represents the same number but with Persian digits
const convertedToFa = persianTools.digitsEnToFa(1234567);
// or
const convertedToFa = digitsEnToFa(1234567);

Usage

Let's take a look at what an example test case would look like using Persian-tools.

Convert Persian words to the number

Options Description Default
fuzzy(Beta) Fix typo in the Persian words by using levenshtein algorithm false
digits Result will be converted to the English or Persian digits en
addCommas Commas will be added to the Result false
  • Convert with no option
import { wordsToNumber } from "@persian-tools/persian-tools";

wordsToNumber("منفی سه هزارمین"); // -3000
wordsToNumber("منفی سه هزارم"); // -3000
wordsToNumber("منفی سه هزار"); // -3000
wordsToNumber("سه هزار دویست و دوازده"); // 3212
wordsToNumber("دوازده هزار بیست دو"); // 12022
  • Digits converter
wordsToNumber("منفی سه هزارمین", { digits: "fa" }); // "-۳۰۰۰"
wordsToNumber("دوازده هزار بیست دو", { digits: "fa" }); // ۱۲۰۲۲
  • Add commas
wordsToNumber("منفی سه هزارمین", { addCommas: true }); // "-3,000"
wordsToNumber("دوازده هزار بیست دو", { addCommas: true }); // "12,022"
  • Fuzzy typo fixer(v1.5.0):
import { WordsToNumber } from "@persian-tools/persian-tools";

wordsToNumber("یگصد و بنجاه هزار", { fuzzy: true }); // "150000"
wordsToNumber("دویشت ر بیشت هزار", { fuzzy: true }); // "220000"
wordsToNumber("منقی ضد", { fuzzy: true }); // "-100"

Convert Numbers to Persian words

import { numberToWords } from "@persian-tools/persian-tools";

numberToWords(500443); // "پانصد هزار و چهار صد و چهل و سه"
numberToWords("500,443"); // "پانصد هزار و چهار صد و چهل و سه"
numberToWords("500,443", { ordinal: true }); // "پانصد هزار و چهار صد و چهل و سوم"
numberToWords(30000000000); // "سی میلیارد"

NOTE: This function supports the largest safe integer (9007199254740991 / 2^53 - 1)

Add and remove commas

import { addCommas, removeCommas } from "@persian-tools/persian-tools";

addCommas(30000000); // "30,000,000"

removeCommas("30,000,000"); // 30000000

Convert Persian numbers to Arabic or English numbers and vice versa

import {
	digitsArToFa,
	digitsArToEn,
	digitsEnToFa,
	digitsFaToEn,
	digitsEnToAr,
	digitsFaToAr,
} from "@persian-tools/persian-tools";

digitsArToFa("۸۹123۴۵"); // "۸۹123۴۵"

digitsArToEn("٨٩123٤٥"); // "8912345"

digitsEnToFa("123۴۵۶"); // "۱۲۳۴۵۶"

digitsEnToAr("123٤٥٦"); // "۱۲۳٤٥٦"

digitsFaToAr("۱۷۸۲۳۴۰۵۶۹"); // ١٧٨٢٣٤٠٥٦٩

Validate Iranian national number(code-e Melli)

import { verifyIranianNationalId, getPlaceByIranNationalId } from "@persian-tools/persian-tools";

verifyIranianNationalId("0499370899"); // true
verifyIranianNationalId("0684159415"); // false

Validate Iranian legal id(shenase hoghoghi)

import { verifyIranianLegalId } from "@persian-tools/persian-tools";

verifyIranianLegalId(10380285692); // false
verifyIranianLegalId(10380284790); // true

Find city and province name by national-id(code-e Melli)

getPlaceByIranNationalId("0084575948").city; // "تهران مرکزی"

Bank number validation and get the name of the bank by bank account number

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

verifyCardNumber(6037701689095443); // true

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

Validate the correctness of the text of the Persian language and clear the Arabic letters in the Persian text.

import { isPersian, hasPersian, toPersianChars } from "@persian-tools/persian-tools";

isPersian("این یک متن فارسی است؟"); // true
isPersian("Lorem Ipsum Test"); // false
isPersian("هل هذا نص فارسي؟"); // false

hasPersian("This text includes فارسی"); // true

toPersianChars("علي"); // علی

Note: You can pass 2 more options to isPersian to customize it as your needs:

  • isComplex: If you pass true, Then it accepts some of regular arabic characters which are commons in persian texts.(default is false)
  • trimPattern: By default the function skips some of characters e.g. "'-+()؟. and whitespaces. You can pass your own customized regex as you need.

Fix Persian characters in URL.

import { URLfix } from "@persian-tools/persian-tools";

URLfix(
	"https://fa.wikipedia.org/wiki/%D9%85%D8%AF%DB%8C%D8%A7%D9%88%DB%8C%DA%A9%DB%8C:Gadget-Extra-Editbuttons-botworks.js",
); // "https://fa.wikipedia.org/wiki/مدیاویکی:Gadget-Extra-Editbuttons-botworks.js"
URLfix("https://en.wikipedia.org/wiki/Persian_alphabet"); // "https://en.wikipedia.org/wiki/Persian_alphabet",
URLfix("Sample Text"); // "Sample Text"

Bill calculator

Method Description Return type
getResult Result of bill calculated information BillResult
getAmount Calculate Bill amount by payment id and bill id which entered by the Bill constructor number
getBillType Get Bill provider type name BillTypes
getBarcode Calculate and get Bill's barcode string
verificationBill Validate entered both Bill id and payment id, and return true if bill id and payment id relation was true boolean
verificationBillId Validate entered Bill id boolean
verificationBillPayment Validate entered Bill payment id boolean
import { Bill } from "@persian-tools/persian-tools";

// Calculate bill amount by bill id and payment id
// Convert to Iranian Rials
// Return bill amount by Toman(Iranian currency type) by default
new Bill({ billId: 1117753200140, paymentId: 12070160, currency: "rial" }).getResult().amount; // 120000

// Find Bill's type by bill id and payment id
new Bill({ billId: 7748317800142, paymentId: 1770160 }).getResult().type; // تلفن ثابت
new Bill({ billId: 9174639504124, paymentId: 12908197 }).getResult().type; // برق
new Bill({ billId: 2050327604613, paymentId: 1070189 }).getResult().type; // آب
new Bill({ billId: 9100074409151, paymentId: 12908190 }).getResult().type; // تلفن همراه
new Bill({ billId: 7748317800105, paymentId: 1770160 }).getResult().type; // unknown

// Check Bill id validation
new Bill({ billId: 7748317800142, paymentId: 1770160 }).getResult().isValidBillId; // true
new Bill({ billId: 2234322344613, paymentId: 1070189 }).getResult().isValidBillId; // false

// Check Bill's payment id validation
new Bill({ billId: 7748317800142, paymentId: 1770160 }).getResult().isValidBillPayment; // true
new Bill({ billId: 9174639504124, paymentId: 12908197 }).getResult().isValidBillPayment; // false

// Check Bill id and payment id relations which is valid or not
new Bill({ billId: 7748317800142, paymentId: 1770160 }).getResult().isValid; // true
new Bill({ billId: 2234322344613, paymentId: 1070189 }).getResult().isValid; // false

// Get barcode from billId and paymentId
new Bill({ billId: 7748317800142, paymentId: 1770160 }).getResult().barcode; // 77483178001420001770160
new Bill({ billId: 9174639504124, paymentId: 12908197 }).getResult().barcode; // 917463950412400012908197

// Get bill bill id and payment id by bill's barcode
new Bill({ barcode: "22343223446130001070189" }).findByBarcode(); // { billId: 2234322344613 , paymentId: 1070189 }

Iranian Sheba(IBAN)

  • Check validation
import { isShebaValid } from "@persian-tools/persian-tools";

isShebaValid("IR820540102680020817909002"); // true
isShebaValid("IR01234567890123456789"); // false
  • Recognize bank information
import { getShebaInfo } from "@persian-tools/persian-tools";

getShebaInfo("IR820540102680020817909002");
/*
 Result: {
    "nickname": "parsian",
    "name": "Parsian Bank",
    "persianName": "بانک پارسیان",
    "code": "054",
    "accountNumberAvailable": true,
    "accountNumber": "020817909002",
    "formattedAccountNumber": "002-00817909-002"
  }
*/

Fix Persian zero-width non-joiner(Replace spaces by half-space)

import { halfSpace } from "@persian-tools/persian-tools";

halfSpace("نمی ‌خواهی درخت ها را ببینیم؟"); // "نمی‌خواهی درخت‌ها را ببینیم؟"

Get information(province, category, type) about vehicles plate

Properties Description Return type
info provide info about plate PlateResultApi
isValid checks if plate is valid or not boolean

Usage

import { Plate } from "@persian-tools/persian-tools";

Plate("12D45147"); // passing string argument

// or passing in object style
Plate({
	number: "1245147",
	char: "الف",
});
  • Getting info about plate
import { Plate } from "@persian-tools/persian-tools";

Plate("12D45147").info;
/*
  {
  	template: 12 D 451 ایران  47
    province: مرکزی ,
    type: Car,
	category: دیپلمات,   
    details: {
	firstTwoDigits: 12,
	plateCharacter: D,
	nextThreeDigits: 451,
	provinceCode: 47
    }
  }
*/

// handle motorcyles plate
Plate(12345678).info;
/*
  {
    template: 123-45678,
	province: مرکز تهران,
    type: Motorcyle,
    category: null,
    details: {
    	digits: 45678
	provinceCode:123
    }
  }
*/

Plates that have farsi digits in them(like: الف، ب، ص) will be returned in this template

  ${first_two_digits}${plate_character}${next_three_digits}ایران${province_code}
  • Checking if plate is valid
import { Plate } from "@persian-tools/persian-tools";

Plate("12D45147").isValid;
/*
  true
*/

Plate(12345678).isValid;
/*
  true
*/

Plate(1234567).isValid;
/*
  will return false - plate character is not provided
*/

Plate(1204567).isValid;
/*
  will return false - plate can't have 0 in its digits (except last digit)
*/

Convert Jalaali date-time into a time ago

Usage

Suppose the current time is equal to 1400/03/17 18:00:00

import { timeAgo } from "@persian-tools/persian-tools";

// Previous
timeAgo("1400/03/17 17:55:00"); // 5 دقیقه قبل
timeAgo("1400/02/17 18:00:00"); // حدود 1 ماه  قبل

// Next
timeAgo("1400/04/07 18:00:00"); // حدود 3 هفته  بعد
timeAgo("1401/03/17 18:00:00"); // حدود 1 سال  بعد

Get the Remaining Time of the Date

Usage

Takes a date(it could be string, number or date) and calculate years, months, days, hours, minutes and seconds remained to that specific date.

import { remainingTime } from "@persian-tools/persian-tools";

remainingTime("2023-05-14T13:35:59Z").toString(); // ۱ سال و ۱ ماه و ۲ روز و ۳ ساعت و ۵ دقیقه و ۸ ثانیه

const { years, months, days, hours, minutes, seconds, isFinished } = remainingTime("2023-05-14T13:35:59Z");
years; // 1
minutes; // 5
isFinished; // false

remainingTime("2018-04-12T10:30:51Z").isFinished; // true

Validate and find information of phone number

Usage

  • Finding information such as province, type and model of phone number
import { phoneNumberDetail } from "@persian-tools/persian-tools";

phoneNumberDetail("9123456789");
/*
  {
    province: ["البرز", "زنجان", "سمنان", "قزوین", "قم", "برخی از شهرستان های استان مرکزی"],
    base: "تهران",
    operator: "همراه اول",
    type: ["permanent"],
  }
*/

phoneNumberDetail("09022002580");
/*
  {
    province: [],
    base: "کشوری",
    operator: "ایرانسل",
    type: ["permanent", "credit"],
  }
*/

phoneNumberDetail("09981000000");
/*
  {
    province: [],
    base: "کشوری",
    operator: "شاتل موبایل",
    type: ["credit"],
  }
*/
  • Validating phone number
import { phoneNumberValidator } from "@persian-tools/persian-tools";

phoneNumberValidator("09122002580"); // true
phoneNumberValidator("09192002580"); // true

phoneNumberValidator("+989022002580"); // true
phoneNumberValidator("09022002580"); // true
phoneNumberValidator("989022002580"); // true
phoneNumberValidator("00989022002580"); // true
phoneNumberValidator("9022002580"); // true

phoneNumberValidator("09802002580"); // false
  • Normalizing phone number
import { phoneNumberNormalizer } from "@persian-tools/persian-tools";

phoneNumberNormalizer("+989022002580", "0"); // 09022002580
phoneNumberNormalizer("989022002580", "0"); // 09022002580
phoneNumberNormalizer("09022002580", "0"); // 09022002580
phoneNumberNormalizer("09022002580", "+98"); // +989022002580

Find capital city by province name

Usage

This function returns the Capital City name by its state name. if it can't find anything, it will throws an error.

import { findCapitalByProvince } from "@persian-tools/persian-tools";

findCapitalByProvince("خراسان رضوی"); // مشهد
findCapitalByProvince("آذربایجان شرقی"); // تبریز

// this throw an error string 'no province found'
findCapitalByProvince("دبی");

Todo

  • Write Jalaali and Gregorian functions to convert Date together.

Contributing

Thank you for your interest in contributing! Please feel free to put up a PR for any issue or feature request.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Who's using Persian tools?


Bank Maskan

MyDong

Melkba

If you're curious to see what can be accomplished with Persian tools, check out these apps!

If you have a software you'd like to see added, please open a pull request! All that's required is a name, link, and a PNG icon.

Contributors ✨

Thanks goes to these wonderful people (emoji key):


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

📖

This project follows the all-contributors specification. Contributions of any kind welcome!

Supporters 👐

Stargazers repo roster for @persian-tools/persian-tools

persian-tools's People

Contributors

ali-master avatar allcontributors[bot] avatar amir-alipour avatar amirqasemi74 avatar amirzenoozi avatar danialnoaein avatar dependabot[bot] avatar geek-sajjad avatar ghonchesefidi avatar github-actions[bot] avatar hasanisaeed avatar hesamp avatar hessamnadr avatar mediv0 avatar meiti-x avatar mhsattarian avatar miladmeidanshahi avatar mmkargar avatar moh3n9595 avatar mrunderline avatar mssoheil avatar pooooriya avatar pshaddel avatar psparsa avatar renovate[bot] avatar sadrahallaj avatar seyyedkhandon avatar shahabbasian avatar tahanamdar avatar themasix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

persian-tools's Issues

Request : a shared json file that contains constants

لطفا حالات زیر را در نظر بگیرید

اگر یک سرشماره به سرشماره های همراه اول اضافه بشه همه ی ما باید ریپازیتوری هامون رو اپدیت کنیم

برای شهر و استان ها هم این اتفاق میفته

توی php اگر بخوایم سینتکس شبیه پکیج اصلی در بیاد باید از Trait استفاده کنیم که توی trait نمیشه constant تعریف کرد . همینطور امکان استفاده از متغیرهای کلاس هنگام تعریف یک متغیر دیگه نیست . این مباحث راه حل دارن و در پول ریکوئست آخر حتی به پیاده سازی پرداخته میشه

همچنین در برخی موارد ناهماهنگی های فولدربندی در بین پروژه ها بابت این ثابت ها بوجود اومده . بعضیا درون فولدر جدا . بعضیا یک فایلی ها جدا چند فایلی ها کنار هم و ...

اما حس کردم یک جای کار بابت موارد بالا میلنگه و چه خوب میشد یه فایل json واحدی وجود می داشت که مثل یک asset استفاده میکردیم و اپدیتش هم میکردیم راحت . ما به پیاده سازی ادامه میدیم اما دوست داشتم نظرتونو در این مورد بدونم که ایا راهی وجود داره یا نه . شایدم این مورد حساسیت الکی باشه

فایل های json میتونن با یک action cronjob طوری آپدیت بشن

Proposal: Support for numberplate

Is your feature request related to a problem? Please describe.
Add support for vehicle number plates

Describe the solution you'd like
Getting info about the given numberplate. province code, type (car or bike), the category that it belongs to (Personal plate, government, military, etc...)

Describe alternatives you've considered

Additional context

Syntax proposal

usage

import { Plate } from "....";

const vehicle = new Plate("12گ34511");
// or
const vehicle = new Plate({
  number: 1234511,
  char: "گ"
})

Plate class can take string or Object as argument ( in string Farsi character will jump to the end )

getting info about numberplate

const vehicle = new Plate("12گ34511");

vehicle.info();

/*
  should return: 

  {
    plate: 12 گ 345 ایران 23,
    province: "تهران",
    category: "شخصی",
    type: "موتور سیکلت"
  }
*/

validating number plate

const vehicle = new Plate("12گ34511");

vehicle.isValid();

/*
  Should return true or false
*/

@ali-master
Please let me know what do you think.
if this ok with you I can work on RP

husky give an error when I'm commit

Describe the bug
I want to contribute to this project but husky gives me this error :
husky - pre-commit hook exited with code 1 (error)

Expected behavior
we have a problem in the js-abbreviation-number package
vs code say : Cannot find module 'js-abbreviation-number' or its corresponding type declarations.

Screenshots

error when I'm commit

image

error when npm test (i don't change anything just add multi files)

image

wordsToNumber not working

سلام
من از طریق npm پکیج رو نصب کردم و خیلی خوب داره کار می‌کنه 👌🏽
اما wordsToNumber ارور زیر رو می‌ده:
Unhandled Runtime Error
TypeError: _persian_tools_persian_tools__WEBPACK_IMPORTED_MODULE_4__.wordsToNumber 
is not a function

پروژه‌ام React با Next.js هستش.

Persian Remained Time

In many projects we have a persian count down but we have to implement it somehow to get the remained minutes remained hours, days, etc.

A function like this will solve this issue:

remainedTime("2019-01-01 03:01:45") = {
Century: 0,
Year: 2,
Month: 4,
Day: 3,
Hour: 5
Minure: 2,
Second: 20
};

remainedTime("2019-01-01 03:01:45").toString() = "۲ سال و ۴ ماه و ۳ روز ۵ ساعت و ۲ دقیقه و بیست ثانیه"

If you consider this function useful, I think I can start working on this issue.

addCommas return Undefiend

Hello. Thanks for great library.
But there is an issue with the addCommas function. If I use addCommas on 0 number, it returns undefiend which I think it should return that 0 instead.

addCommas(0) // undefiend

Node 17 support

persian-tools is incompatible with node 17

error @persian-tools/[email protected]: The engine "node" is incompatible with this module. Expected version ">=10.0.0 <=16". Got "17.2.0"

I test it with node@17 and it seams is compatible, please just upgrade dependency

accountNumber in parsed shebaCode becomes undefined

Describe the bug
Sometime accountNumber and formattedAccountNumber in parsed shebaCode becomes undefined

To Reproduce
Steps to reproduce the behavior:

  1. use recognize to parse shebaCode

Expected behavior
if accountNumberAvailable is true, then accountNumber and formattedAccountNumber should be available.

Example

image

NOTE: I have faced with this issue using Pasargad Bank shebaCode.

Additional context
Package Version: 1.7.1

Iranian Sheba section not rendered in docs

Describe the bug
i tried to fix it but can't find any docs folder or file to fixing it but i send a issue.

Screenshots

image

Desktop (please complete the following information):
i don't think it is depend to my device information.

nationalcode validation maybe need review

Hi again,
in the validation of national code when user type 1111111111 or 222222222 or any same numbers
the function returns true, but actually, its the wrong national code, and no one has this national code, maybe need to check another condition to check if all numbers same then return false

Expected behavior
return false

Converting a date into a time ago

Hi guys
Thanks for this magnificent tool.
I have a class in my project to convert a date into a time ago as follows:

datetime time ago
0 - 59 seconds چند ثانیه قبل
.. ..
22 - 36 hours یک روز قبل
25 - 45 days یک ماه پیش
.. ..
546 days+ N سال قبل

I would like this feature to be in this tool as well.

better CI/CD

Since your Travis build has some errors, it can be awesome if persian-tools switch to CircleCI or GitHub actions or even more accurate continuous integrated flow with Travis. Codcov can be added for better detection in code coverage as well as.

National ID Validation returns true when used on same numbers in a row

Describe the bug
Numbers like 0000000000, 1111111111, 2222222222, ... 9999999999 are considered valid with verifyIranianNationalId()!

Expected behavior
I'm not sure if it's a bug or we have national ids like these, but for me, it seems to be a bug.

Tested on different browsers and devices and the result is the same.
"@persian-tools/persian-tools": "^1.7.0"

toPersianChars It does not work properly

سلام

من میخواهم، ورودی کاربر را یکبار از toPersianChars رد کنم و با isPersian فارسی یا انگلیسی بودن ورودی رو بررسی کنم اما در بعضی کلمات فارسی که از تابع toPersianChars رد میشن isPersian دیگه اونو فارسی نمیشناسه

مثال:

isPersian(toPersianChars('مهدی'))     // false
isPersian(toPersianChars('شاه'))     // false
isPersian(toPersianChars('سلام'))     // true

تبدیل حروف به عدد

سلام.

درباره یه موردی یه سوال برام ایجاد شد.
توی Readme درباره تبدیل حروف به عدد، این مورد نوشته شده:

WordsToNumber.convert("دوازده هزار بیست دو", { digits: "fa" }) // ۱۲۰۲۲

۱- اعداد در واقع با جداکننده «و» بیان میشن مثلا همین عدد ۱۲۰۲۲ رو اگه کسی بخواد به حروف بنویسه، بصورت «دوازده هزار و بیست و دو» می‌نویسه. این حالت، در واقع حالت استاندارد هست؛ و مثلا NumberFormatter زبان سوییفت، به همین صورت و با «و» اعداد رو به حروف تبدیل می‌کنه. چون بهرحال مفهوم «دوازده هزار بیست دو» می‌تونه متفاوت باشه. مثلا اگه توی مکالمه همچین عبارتی گفته بشه، برداشت‌های زیر ممکنه رخ بده:

  • دوازده هزار | بیست | دو : ۱۲۰۰۰ | ۲۰ | ۲
  • دوازده | هزار | بیست | دو : ۱۲ | ۱۰۰۰ | ۲۰ | ۲

اما اگه عبارت «دوازده هزار و بیست و دو» گفته بشه، فقط مفهوم عددی «۱۲۰۲۲» رو می‌رسونه.
در نتیجه به نظر این مورد باید مورد بازبینی قرار بگیره.

Fix isPersian issues

the isPersian module should detect only Persian strings and should be aware of Arabic and other none English strings.

(method) String.substr(from: number, length?: number): string , deprecated !

Hi, thanks for this cool package and for supporting the Iranian open source community
In verifyIranianNationalId function TSlint said (method) String.substr(from: number, length?: number): string was deprecated

Screenshots
image

Desktop (please complete the following information):

  • OS:Windows 11
  • Browser Chrome
  • Version 96

get bank name by account_number

Hi every one,
thank you very much to this very good project.
if we could find bank name by account number (شماره حساب)
It will be great
if it's possible please added
thanks alot again

digitsEnToFa is not defined

Hi Ali,
Thanks for this amazing library.
I tested this code in html file:

<html>
  <head>
    <script src="https://cdn.jsdelivr.net/npm/persian-tools"> </script>
    <script type="text/javascript">    
      var convertToFa = digitsEnToFa(1234567);
    </script>
  </head>

  <body>
  </body>
</html>

But there is an error :

Uncaught ReferenceError: digitsEnToFa is not defined

Where is the problem?

Node Engine Problem

Describe the bug
I try to install the Latest version of persian-tools in my projects but I got this error :

 @persian-tools/[email protected]: The engine "node" is incompatible with this module. Expected version ">=12<16". Got "14.16.0"

I have this issue in v14.0, v14.15.0 , v14.16.0

Convert English digits to Arabic

Hi and thanks again for the project
it would be useful if we also had digitsEnToAr function to convert between English and Arabic digits.
Thanks alot!

new feature

توی پروژه من یه بررسی کردم الگوریتمی برای تایید صحت شناسه ملی افراد حقوقی نداریم.

الگوریتم بررسیش
اگر اوکیه بنظرت و نداریمش. بسپارش به من و اضافه میکنم :)

For Jalali and Gregorian date converter

Is your feature request related to a problem? Please describe.
No.

To convert Jalali and Gregorian dates to each other you can find the source from my library here which is the precise conversion for Jalali, Gregorian, and Islamic (moon) date.

How is "addCommas" different from "toLocaleString()"?

This is a question, not an issue.
In JS, we can easily add commas with (number).toLocaleString(). While both this and addCommas(number) both accept only English numbers and do the same thing, what is the real difference between them? Which one should I use?

Error handling issue

@ali-master

I've read the source of the project, and I realize the project missing Error handling.
what your think about that.

I'm looking forward to hearing from you.

Validate National ID with Persian/Arabic Numbers

Currently, only English numbers can be used to validate the national id.
Is there a way to accept Persian/Arabic numbers without converting the number?

verifyIranianNationalId("0499370899"); // true
verifyIranianNationalId("۰۴۹۹۳۷۰۸۹۹"); // false
verifyIranianNationalId("٠٤٩٩٣٧٠٨٩٩"); // false

Random User Generator

If we have a little module to generate random users with Persian names and information it should be useful, sample user:

[{
    "firstName": "علی",
    "lastName": "فرهادی",
    "gender": "male",
    "nationalNumber": "001-234567-8",
    "birthDate": "1994-02-15",
    "province": "تهران"
}]

this module will be able to generate users base on gender, province, age, ...
what's your opinion?

Refactor README

Hey guys,
there are a lot of extra examples in "README". in many validating functions, 1 or 2 examples is enough. I think we should remove extra examples to make "README" more clear.

card number validation

6219861034529007002229988112233
این شماره کارت طبق الگوریتم شما معتبر است ؟
16 رقم اول آن معتبر است اما بقیه اعداد الکی هست
ممکنه شماره کارت بیشتر از 16 رقم باشه ولی محدودیت داره و بازم هر چیزی نمیتونه باشه درست میگم ؟

Strange behavior with chained number conversions

When using chained/multiple number conversions, the result isn't correct.
converted = digitsFaToEn(digitsArToFa(nationalID));

for example:

0499370899 => 0499370899
۰۴۹۹۳۷۰۸۹۹ => 0499370899
٠٤٩٩٣٧٠٨٩٩ => ٠4٩٩٣٧٠٨٩٩ // incorrect

I used different unicode ranges for arabic, but the only number considered as arabic is 4.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): replace dependency standard-version with commit-and-tag-version 9.5.0
  • chore(deps): update dependency eslint-plugin-security to v2.1.1
  • chore(deps): update dependency eslint to v8.57.0
  • chore(deps): update dependency prettier to v3.2.5
  • chore(deps): update dependency prettier-eslint to v16.3.0
  • chore(deps): update actions/cache action to v4
  • chore(deps): update actions/upload-artifact action to v4
  • chore(deps): update codecov/codecov-action action to v4
  • chore(deps): update commitlint monorepo to v19 (major) (@commitlint/cli, @commitlint/config-conventional)
  • chore(deps): update dependency eslint to v9
  • chore(deps): update dependency eslint-plugin-security to v3
  • chore(deps): update dependency eslint-plugin-standard to v5
  • chore(deps): update dependency husky to v9
  • chore(deps): update typescript-eslint monorepo to v7 (major) (@typescript-eslint/eslint-plugin, @typescript-eslint/parser)
  • 🔐 Create all rate-limited PRs at once 🔐

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/codeql-analysis.yml
  • actions/checkout v3
  • github/codeql-action v1
  • github/codeql-action v1
  • github/codeql-action v1
.github/workflows/codesee-arch-diagram.yml
  • Codesee-io/codesee-action v2
.github/workflows/continuous-integration.yml
  • actions/checkout v3
  • actions/setup-node v3
  • actions/cache v3
  • codecov/codecov-action v3
  • actions/upload-artifact v3
npm
package.json
  • fastest-levenshtein ^1.0.16
  • @commitlint/cli 18.4.3
  • @commitlint/config-conventional 18.4.3
  • @types/jest 29.5.11
  • @typescript-eslint/eslint-plugin 6.16.0
  • @typescript-eslint/parser 6.16.0
  • cross-env 7.0.3
  • eslint 8.56.0
  • eslint-config-standard 17.1.0
  • eslint-friendly-formatter 4.0.1
  • eslint-plugin-import 2.29.1
  • eslint-plugin-node 11.1.0
  • eslint-plugin-prettier 5.1.2
  • eslint-plugin-promise 6.1.1
  • eslint-plugin-security 2.1.0
  • eslint-plugin-standard 4.1.0
  • husky 8.0.3
  • microbundle 0.15.1
  • prettier 3.1.1
  • prettier-eslint 16.2.0
  • rimraf 5.0.5
  • standard-version 9.5.0
  • typedoc 0.22.16
  • vite ^5.0.10
  • vitest 1.1.0
  • node >=14
  • npm >=7.0.0

  • Check this box to trigger a request for Renovate to run again on this repository

issue "addCommas"

hey guys!
thanks a lot about this awesome package ,it helped me in my project by converting "numberToWord".

today I wanted to use "addCommas" and I saw a mistake my code :
html :

<div class="form-group">
<input name="PostPriceCity" id="PostPriceCity" placeholder="هزینه ارسال برای همشهری" class="form-control" />
</div>

js :

$('#PostPriceCity').on('keyup', function () {
        var GetValue = $(this).val();
        $(this).val(PersianTools.addCommas(GetValue))
    });

my number is for example 5000000 and return is 5,0,0,0,000🤯

I hope you fix this

another problem is using this function. before ,writing just $(this).val(PersianTools.addCommas(GetValue)) returns the resualt but now I have an error in Console and it says : "PersianTools is not defined" so how can I use "addComma" without problem?

your package was added to my project with <script> tag and I can't use npm or anything else ...

wordsToNumber return wrong number

wrong number on over a million:

console.log(wordsToNumber("یک میلیون و دویست هزار و سیصد و پنجاه و هفت")); // 1000200357
console.log(wordsToNumber("سه میلیارد و دویست میلیون و سیصد و پنجاه و هفت هزار و دویست و پنج")); // 3000000200000357000

but under a million returned correct number:

console.log(wordsToNumber("سیصد و پنجاه و هفت هزار و دویست و پنج")); // 357205

Convert 0 to Persian digit

Describe the bug
Hi and thanks for this great and useful project.
The issues is when function digitsEnToFa is called to convert digit 0, it returns undefined. it works fine for numbers contain 0, but returns undefined for 0 itself.

To Reproduce
digitsEnToFa(0)

Expected behavior
the function should return ۰ .

thanks again!

Webpack failed to parse source map

Describe the bug
Webpack compile app with following warning:

WARNING in ./node_modules/@persian-tools/persian-tools/build/persian-tools.esm.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from '***/node_modules/@persian-tools/persian-tools/build/persian-tools.esm.js.map' file: Error: ENOENT: no such file or directory, open '***/node_modules/@persian-tools/persian-tools/build/persian-tools.esm.js.map'

Looks like Webpack can not find the source map file.

Screenshots
image

Additional context
Produced on CRA project.
From yarn.lock:

react@^18.2.0:
  version "18.2.0"

[email protected]:
  version "5.0.1"

webpack@^5.64.4:
  version "5.73.0"

webpack-sources@^1.4.3:
  version "1.4.3"

webpack-sources@^2.2.0:
  version "2.3.1"

webpack-sources@^3.2.3:
  version "3.2.3"

Per Method Packages

As you know, lodash has a capability to import modularized sub-packages called per method packages
It is good for you to make this package modularized especially for the independent functionalities.
for example when a project only needs one of these package functionalities e.g. Sheba, it is better to add and import it like this:

yarn add persian-tools.sheba
import Sheba from 'persian-tools.sheba'

this approach is good for minimizing projects bundle size when using this package because many projects don't need all of these package functionalities

Ideas

Is your feature request related to a problem? No

Describe the solution you'd like
New ideas which we can add to the PersianTools:

  • Calculate bill information by Bill id and Payment id.
  • Get bank information via IBAN number.
  • Replace spaces by half-space in Persian texts.
  • Write a great typescript documentation.
  • Design and implement a website for the demo by React and Github-pages.
  • Implement the Persian-tools for the Vue.js.
  • Implement the Persian-tools for the Angular.js.
  • Implement the Persian-tools for the Angular 2+.

This list will be completed day by day.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.