UNPKG

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