Skip to content

Instantly share code, notes, and snippets.

@parham-ab
Last active October 28, 2024 18:17
Show Gist options
  • Save parham-ab/b546ac18fa393b9aa2c9a17c881ff96a to your computer and use it in GitHub Desktop.
Save parham-ab/b546ac18fa393b9aa2c9a17c881ff96a to your computer and use it in GitHub Desktop.
A simple JS function to convert English & Persian digits together
const englishToPersian = (n) => n.toString().replace(/\d/g, (d) => "۰۱۲۳۴۵۶۷۸۹"[d]);
const persianToEnglish = (n) =>
n.toString().replace(/[۰-۹]/g, (d) => "۰۱۲۳۴۵۶۷۸۹".indexOf(d));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment