Last active
August 12, 2019 22:19
-
-
Save eAmin/1fcf5608aa1bd19229c60af2ba25b310 to your computer and use it in GitHub Desktop.
Tweet sized English number to Persian converter and vice versa.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Tweet sized English number to Persian converter and vice versa. | |
* You can find out old and obsolete version in here: https://gist.github.com/eAmin/786108 | |
* by Amin Akbari | |
* MIT License | |
*/ | |
/** | |
* Convert English numbers to Persian | |
* | |
* @param {string|number|array} val the Value need to convert | |
* @returns {string} | |
*/ | |
export function toPersianDigit(val) { | |
return (val + '').replace(/[0-9]/g, digit => String.fromCharCode( digit.charCodeAt(0) + 1728 )); | |
} | |
/** | |
* Convert Persian numbers to English | |
* | |
* @param {string|number|array} val the Value need to convert | |
* @returns {string} | |
*/ | |
export function toEnglishDigit(val) { | |
return (val + '').replace(/[\u06F0-\u06F9]/g, digit => String.fromCharCode( digit.charCodeAt(0) - 1728 )); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment