-
Notifications
You must be signed in to change notification settings - Fork 113
/
fa.ts
33 lines (28 loc) · 1.02 KB
/
fa.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { faNums, arNums, faDigitsRegex } from "../digits.constants";
// Types
import type { DigitsConverter } from "../digits.types";
/**
* digitsFaToEn
*
* @category Digits
* @description Takes a string and
* returns a string that represents the same value but
* its farsi digits are replaced with english digits
*/
const digitsFaToEn: DigitsConverter = (value) => {
if (typeof value !== "string") throw TypeError("PersianTools: digitsFaToEn - The input must be string");
return String(value).replace(faDigitsRegex, (char) => `${faNums.indexOf(char)}`);
};
/**
* digitsFaToAr
*
* @category Digits
* @description Takes a string and
* returns a string that represents the same value but
* its farsi digits are replaced with arabic digits
*/
const digitsFaToAr: DigitsConverter = (value) => {
if (typeof value !== "string") throw TypeError("PersianTools: digitsFaToAr - The input must be string");
return String(value).replace(faDigitsRegex, (char) => arNums[faNums.indexOf(char)]);
};
export { digitsFaToEn, digitsFaToAr };