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 Issues

card number validation

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

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

Request : a shared json file that contains constants

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

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

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

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

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

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

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

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 هستش.

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?

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.

new feature

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

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

Fix isPersian issues

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

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

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 rimraf to v5.0.7
  • chore(deps): update dependency eslint to v8.57.0
  • chore(deps): update dependency eslint-plugin-promise to v6.2.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

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"

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!

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

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

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?

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

سلام.

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

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

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

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

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

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

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.

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

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

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!

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.

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

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.

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.

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.

toPersianChars It does not work properly

سلام

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

مثال:

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

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

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"

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?

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

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 ...

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.

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.

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.

(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

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.