Skip to content

Instantly share code, notes, and snippets.

@amir9480
Created November 15, 2018 08:16
Show Gist options
  • Save amir9480/4998c4a939b4ba9c2cd9d25f096564f2 to your computer and use it in GitHub Desktop.
Save amir9480/4998c4a939b4ba9c2cd9d25f096564f2 to your computer and use it in GitHub Desktop.
javascript helpers
window.enToFa = function (text) {
text = String(text);
text = text.replace(/0/g, '۰');
text = text.replace(/1/g, '۱');
text = text.replace(/2/g, '۲');
text = text.replace(/3/g, '۳');
text = text.replace(/4/g, '۴');
text = text.replace(/5/g, '۵');
text = text.replace(/6/g, '۶');
text = text.replace(/7/g, '۷');
text = text.replace(/8/g, '۸');
text = text.replace(/9/g, '۹');
return text;
}
window.faToEn = function (text) {
text = String(text);
text = text.replace(/۰/g, '0');
text = text.replace(/۱/g, '1');
text = text.replace(/۲/g, '2');
text = text.replace(/۳/g, '3');
text = text.replace(/۴/g, '4');
text = text.replace(/۵/g, '5');
text = text.replace(/۶/g, '6');
text = text.replace(/۷/g, '7');
text = text.replace(/۸/g, '8');
text = text.replace(/۹/g, '9');
text = text.replace(/٤/g, '4');
text = text.replace(/٥/g, '5');
text = text.replace(/٦/g, '6');
return text;
}
window.numberFormat = function (input) {
return String(input).replace(/(\d)(?=(\d{3})+\b)/g, "$1,");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment