Skip to content

Instantly share code, notes, and snippets.

@1mehdifaraji
Created November 24, 2024 03:50
Show Gist options
  • Save 1mehdifaraji/127e51402f3ebca5e2353ebf38a3bae5 to your computer and use it in GitHub Desktop.
Save 1mehdifaraji/127e51402f3ebca5e2353ebf38a3bae5 to your computer and use it in GitHub Desktop.
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