Skip to content

Instantly share code, notes, and snippets.

@eAmin
Last active August 12, 2019 22:19
Show Gist options
  • Save eAmin/1fcf5608aa1bd19229c60af2ba25b310 to your computer and use it in GitHub Desktop.
Save eAmin/1fcf5608aa1bd19229c60af2ba25b310 to your computer and use it in GitHub Desktop.
Tweet sized English number to Persian converter and vice versa.
/**
* 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