Created
August 29, 2025 11:01
-
-
Save 1mehdifaraji/7ccb4f6fbf1acb2c333fee487f33c964 to your computer and use it in GitHub Desktop.
Converting English (Latin) numbers to Persian and vice versa.
This file contains hidden or 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
| export const e2p = (input: string | number) => { | |
| const persianDigits = ["۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹"]; | |
| return input.toString().replace(/\d/g, (d) => persianDigits[parseInt(d)]); | |
| }; | |
| export const p2e = (input: string | number) => { | |
| const persianDigits = ["۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹"]; | |
| return input | |
| .toString() | |
| .replace(/[۰-۹]/g, (d) => persianDigits.indexOf(d).toString()); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment