SalmanAA / wordifyfa

Convert numbers to Persian words.
GNU General Public License v3.0
97 stars 15 forks source link

Persian Wordifier converts numbers to words. for example you can use this:

var a = 235000;
var b = wordifyfa(a);
console.log(b); // دویست و سی و پنج هزار
var c = wordifyRials(a); // دویست و سی و پنج هزار ریال
var d = wordifyRialsInTomans(a); // بیست و سه هزار و پانصد تومان
var e = 235736;
var f = wordifyRialsInTomans(e); //  بیست  و  سه  هزار  و  پانصد  و  هفتاد  و  سه  تومان و  شش  ریال
var g = wordifyMomentApprox(new Date(2022,4,4,10,20,0)); // هفت ساعت پیش 
var h = wordifyMomentApprox(new Date(2022,4,4,10,20,0), new Date(2022,4,4,10,21,0), "قبل","بعد"); // یک دقیقه بعد 
var i = wordifyMomentApprox("2022-05-04 10:20:00"); // هفت ساعت پیش
var j = momentApprox("2022-05-04 10:20:00"); // 7 ساعت پیش
var k = wordifyMomentPrecise("2022-05-04 10:20:00"); // هفت ساعت و پنج دقیقه و بیست ثانیه پیش
var l = momentPrecise("2022-05-04 10:20:00"); // 7 ساعت و 5 دقیقه و 20 ثانیه پیش

Warning! in javascript, month starts from zero so new Date(2022,4,4,10,20,0) means month 5 (May)

update (2022-07-14)

update (2022-05-15)

update (2020-05-15)

update (2020-04-18)

update (2020-03-11)

update (2019-09-11)

installation:

1- add this line of code in your html.

<script src="https://github.com/SalmanAA/wordifyfa/raw/master/wordifyfa.js"></script>

or if you are using Node.js

npm i wordifyfa
var wf = require('wordifyfa.js');

2- use the code.

in javascript:

    var a = 93390;
    var b = wordifyfa(a); // نود و سه هزار و سیصد و نود

in Node.js:

    var a = 93390;
    var b = wf.wordifyfa(a); // نود و سه هزار و سیصد و نود

following examples are in javascript. if you want use it in Node.js, you must change it as same as previous sample.

functions:

1 converts number to words

    wordifyfa(number) 
    wordifyfa(43); // چهل و سه

or in Node.js :

    var a = require('./wordifyfa.js');
    a.wordifyfa(number);

2 converts number to words with Rial sign

    wordifyRials(number) 
    wordifyRials(400); // چهارصد ریال

or in Node :

    var a = require('./wordifyfa.js');
    a.worifyfaRials(number);

3 converts number that is in Rials to Tomans and wordifies it

    wordifyRialsInTomans(number) 
    wordifyRialsInTomans(5000); // پانصد تومان

or in Node :

    var a = require('./wordifyfa.js');
    a.wordifyRialsInTomans(number);

4 supports converting persian and arabic digits

    wordifyfa('۱۲۰۰۰۰')

5 convert dates to approximate time in words

    wordifyMomentApprox(date,[base date=current time],[suffix if date is before base date='پیش'], [suffix if date is after base date = 'بعد']);
    // date and base date can be string or date object
    // base date and suffixes are optional

6 convert dates to approximate time in digits

    momentApprox(date,[base date=current time],[suffix if date is before base date='پیش'], [suffix if date is after base date = 'بعد']);
    // date and base date can be string or date object
    // base date and suffixes are optional

7 convert dates to precise time difference (year/month/week/day/hour/minute/second) in words

    wordifyMomentPrecise(date,[base date=current time],[suffix if date is before base date='پیش'], [suffix if date is after base date = 'بعد']);
    // date and base date can be string or date object
    // base date and suffixes are optional

8 convert dates to precise time difference (year/month/week/day/hour/minute/second) in digits

    momentPrecise(date,[base date=current time],[suffix if date is before base date='پیش'], [suffix if date is after base date = 'بعد']);
    // date and base date can be string or date object
    // base date and suffixes are optional

more info:

this code now supports max to 999,999,999,999,999. is it sufficient?

Main Contributors