Created
November 24, 2024 03:50
-
-
Save 1mehdifaraji/127e51402f3ebca5e2353ebf38a3bae5 to your computer and use it in GitHub Desktop.
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 enNums = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]; | |
export const faNums = ["۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹"]; | |
export const arNums = ["٠", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩"]; | |
export const enDigitsRegex = /[0-9]/g; | |
export const faDigitsRegex = /[۰۱۲۳۴۵۶۷۸۹]/g; | |
export const arDigitsRegex = /[٠١٢٣٤٥٦٧٨٩]/g; | |
const ar2p = (value) => String(value).replace(arDigitsRegex, (char) => faNums[arNums.indexOf(char)]) | |
const ar2e = (value) => String(value).replace(arDigitsRegex, (char) => `${arNums.indexOf(char)}`) | |
const p2e = (value) => String(value).replace(faDigitsRegex, (char) => `${faNums.indexOf(char)}`) | |
const p2ar = (value) => String(value).replace(faDigitsRegex, (char) => arNums[faNums.indexOf(char)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment