1 |
|
2 |
|
3 |
|
4 | export const PERSIAN_DIGITS = [
|
5 | '۰',
|
6 | '۱',
|
7 | '۲',
|
8 | '۳',
|
9 | '۴',
|
10 | '۵',
|
11 | '۶',
|
12 | '۷',
|
13 | '۸',
|
14 | '۹',
|
15 | ];
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | export const ARABIC_DIGITS = ['٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'];
|
21 |
|
22 |
|
23 |
|
24 | export const PERSIAN_ZERO_CHAR_CODE = PERSIAN_DIGITS[0].charCodeAt(0);
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | export const ARABIC_ZERO_CHAR_CODE = ARABIC_DIGITS[0].charCodeAt(0);
|
30 |
|
31 | export function toNumeric(value) {
|
32 | return String(value).replace(/[^-\d]/g, '');
|
33 | }
|
34 |
|
35 | export function toPersianDigits(value) {
|
36 | return String(value).replace(/[0-9]/g, w => PERSIAN_DIGITS[parseInt(w)]);
|
37 | }
|
38 |
|
39 | export function toEnglishDigits(value) {
|
40 | return String(value)
|
41 | .replace(/[۰-۹]/g, w => w.charCodeAt(0) - PERSIAN_ZERO_CHAR_CODE)
|
42 | .replace(/[٠-٩]/g, w => w.charCodeAt(0) - ARABIC_ZERO_CHAR_CODE);
|
43 | }
|
44 |
|
45 | export function weekDays() {
|
46 | return [
|
47 | 'شنبه',
|
48 | '۱ شنبه',
|
49 | '۲ شنبه',
|
50 | '۳ شنبه',
|
51 | '۴ شنبه',
|
52 | '۵ شنبه',
|
53 | 'جمعه',
|
54 | ];
|
55 | }
|