A simple JavaScript library To use the most commonly used string operations.
Include functions of persian.js
$ yarn add starkstring
conststarkString=require("starkstring").default;//orimportstarkStringfrom"starkstring";Used for converting Arabic characters to Persian.
Example:
starkString(" علي ").trim()// Remove spaces.persianChar()// Convert arabic `ي` to persian `ی`.toString();//Returns: "علی"Used for converting Persian and arabic Number to English numbers.
Example:
starkString("۳۴۵ ٤٥").englishNumber().toString();//returns: 345 45Used for converting Arabic and English numbers to Persian.
Example:
starkString("٣٤٥ 78").persianNumber().toString();//returns: ۳۴۵ ۷۸Used for converting Arabic and Persian numbers to English.
Example:
starkString("345").arabicNumber().toString();//returns: ٣٤٥Used to normalize url
Example:
starkString("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 http://fa.wikipedia.org/wiki/%D8%B5%D9%81%D8%AD%D9%87%D9%94_%D8%A7%D8%B5%D9%84%DB%8C/Used for converting Persian char to English char.
Example:
starkString("لخخلمث").switchKey().toString();//returns: googleUsed for representing numbers as Persian words.
Example:
starkString("1372").digitsToWords().toString();//returns: یک هزار و سیصد و هفتاد و دوExample:
starkString("آمده ای ولی من رفته ام و می آییم").halfSpace().toString();//returns: آمدهای ولی من رفتهام و میآییمWhether is value integer
Example:
starkString("344327905").isInteger();// return truestarkString("34432.7905").isInteger();// return falsestarkString("g344327905").isInteger();// return falseWhether is value bank card
Example:
starkString("6104337638408961").isValidBankCard();// return trueconvert english number to currency format
Example:
starkString("120000.00").currency().toString();// return 120,000.00starkString("120000").currency().persianNumber().toString();// return ۱۲۰,۰۰۰Remove anything expect numbers
Example:
starkString(" amount 12,000 dollar").parseNumber().toString();// return 12000convert any char to star ("*")
Example:
starkString("password").security().toString();// return ********You can use all of the functions together with one StarkString instance.
Example:
starkString("علي٤2465").persianChar().englishNumber().persianNumber().toString();//returns: علی۴۲۴۶۵This is a open-source project. Fork the project, complete the code and send pull request.
