0.1.0 • Published 5 years ago

persianstring v0.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

starkString

A simple JavaScript library To use the most commonly used string operations.
Include functions of persian.js Build Status

TOC

install

$ yarn add starkString

Functions

1) Convert Arabic characters to Persian


Used for converting Arabic characters to Persian.

Example:

starkString(" علي ").trim().persianChar().toString(); //returns: علی

2) Convert to English numbers from Persian and arabic Number


Used for converting Persian and arabic Number to English numbers.

Example:

starkString("۳۴۵ ٤٥").englishNumber().toString(); //returns: 345 45

3) Convert to Persian numbers from Arabic and English Number


Used for converting Arabic and English numbers to Persian.

Example:

starkString("٣٤٥ 78").persianNumber().toString(); //returns: ۳۴۵ ۷۸

4) Convert to Arabic numbers from English and Persian Number


Used for converting Arabic and Persian numbers to English.

Example:

starkString("345").arabicNumber().toString(); //returns:  ٣٤٥

6) Decode Percent-encoding Characters in URLs


Used to convert unreadable Persian characters in URL to readable characters.

Example:

starkString("https://fa.wikipedia.org/wiki/%D8%B5%D9%81%D8%AD%D9%87%D9%94_%D8%A7%D8%B5%D9%84%DB%8C").fixURL().toString(); //returns https://fa.wikipedia.org/wiki/صفحهٔ_اصلی

7) Change keyboard layout


Used for converting Persian char to English char.

Example:

starkString("لخخلمث").switchKey().toString(); //returns: google

8) Convert numbers to words


Used for representing numbers as Persian words.

Example:

starkString("1372").digitsToWords().toString(); //returns: یک هزار و سیصد و هفتاد و دو

9) Zero-width non-joiner correction


Example:

starkString("آمده ای ولی من رفته ام و می آییم").halfSpace().toString(); //returns: آمده‌ای ولی من رفته‌ام و می‌آییم

10) Integer number validation


Whether is value integer

Example:

starkString("344327905").isInteger() // return true

starkString("34432.7905").isInteger() // return false
starkString("g344327905").isInteger() // return false

11) back card number validation


Whether is value back card

Example:

starkString("6104337638408961").isValidBankCard() // return true

12) convert number to currency format


Whether is value back card

Example:

starkString("120000.00").currency().toString() // return 120,000.00

starkString("120000").currency().persianNumber().toString() // return ۱۲۰,۰۰۰

Chainable using


You can use all of the functions together with one StarkString instance (in v0.3).

Example:

starkString("علي٤2465").persianChar().englishNumber().persianNumber().toString(); //returns: علی۴۲۴۶۵

Contributing

This is a open-source project. Fork the project, complete the code and send pull request.