react-native-hilal 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +221 -2
- package/lib/module/calendar/Chevron.js +60 -0
- package/lib/module/calendar/Chevron.js.map +1 -0
- package/lib/module/calendar/DayCell.js +48 -0
- package/lib/module/calendar/DayCell.js.map +1 -0
- package/lib/module/calendar/HilalCalendar.js +288 -0
- package/lib/module/calendar/HilalCalendar.js.map +1 -0
- package/lib/module/calendar/index.js +5 -0
- package/lib/module/calendar/index.js.map +1 -0
- package/lib/module/calendar/month.js +178 -0
- package/lib/module/calendar/month.js.map +1 -0
- package/lib/module/calendar/styles.js +125 -0
- package/lib/module/calendar/styles.js.map +1 -0
- package/lib/module/calendar/theme.js +49 -0
- package/lib/module/calendar/theme.js.map +1 -0
- package/lib/module/calendar/types.js +4 -0
- package/lib/module/calendar/types.js.map +1 -0
- package/lib/module/core/convert.js +160 -0
- package/lib/module/core/convert.js.map +1 -0
- package/lib/module/core/days.js +61 -0
- package/lib/module/core/days.js.map +1 -0
- package/lib/module/core/format.js +37 -0
- package/lib/module/core/format.js.map +1 -0
- package/lib/module/core/index.js +6 -0
- package/lib/module/core/index.js.map +1 -0
- package/lib/module/core/locale.js +59 -0
- package/lib/module/core/locale.js.map +1 -0
- package/lib/module/core/types.js +2 -0
- package/lib/module/core/types.js.map +1 -0
- package/lib/module/core/umalqura-data.js +24 -0
- package/lib/module/core/umalqura-data.js.map +1 -0
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/calendar/Chevron.d.ts +13 -0
- package/lib/typescript/src/calendar/Chevron.d.ts.map +1 -0
- package/lib/typescript/src/calendar/DayCell.d.ts +22 -0
- package/lib/typescript/src/calendar/DayCell.d.ts.map +1 -0
- package/lib/typescript/src/calendar/HilalCalendar.d.ts +7 -0
- package/lib/typescript/src/calendar/HilalCalendar.d.ts.map +1 -0
- package/lib/typescript/src/calendar/index.d.ts +4 -0
- package/lib/typescript/src/calendar/index.d.ts.map +1 -0
- package/lib/typescript/src/calendar/month.d.ts +63 -0
- package/lib/typescript/src/calendar/month.d.ts.map +1 -0
- package/lib/typescript/src/calendar/styles.d.ts +119 -0
- package/lib/typescript/src/calendar/styles.d.ts.map +1 -0
- package/lib/typescript/src/calendar/theme.d.ts +31 -0
- package/lib/typescript/src/calendar/theme.d.ts.map +1 -0
- package/lib/typescript/src/calendar/types.d.ts +58 -0
- package/lib/typescript/src/calendar/types.d.ts.map +1 -0
- package/lib/typescript/src/core/convert.d.ts +54 -0
- package/lib/typescript/src/core/convert.d.ts.map +1 -0
- package/lib/typescript/src/core/days.d.ts +24 -0
- package/lib/typescript/src/core/days.d.ts.map +1 -0
- package/lib/typescript/src/core/format.d.ts +23 -0
- package/lib/typescript/src/core/format.d.ts.map +1 -0
- package/lib/typescript/src/core/index.d.ts +5 -0
- package/lib/typescript/src/core/index.d.ts.map +1 -0
- package/lib/typescript/src/core/locale.d.ts +21 -0
- package/lib/typescript/src/core/locale.d.ts.map +1 -0
- package/lib/typescript/src/core/types.d.ts +7 -0
- package/lib/typescript/src/core/types.d.ts.map +1 -0
- package/lib/typescript/src/core/umalqura-data.d.ts +15 -0
- package/lib/typescript/src/core/umalqura-data.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +3 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +180 -4
- package/src/calendar/Chevron.tsx +55 -0
- package/src/calendar/DayCell.tsx +83 -0
- package/src/calendar/HilalCalendar.tsx +399 -0
- package/src/calendar/index.ts +8 -0
- package/src/calendar/month.ts +213 -0
- package/src/calendar/styles.ts +127 -0
- package/src/calendar/theme.ts +69 -0
- package/src/calendar/types.ts +61 -0
- package/src/core/convert.ts +192 -0
- package/src/core/days.ts +64 -0
- package/src/core/format.ts +65 -0
- package/src/core/index.ts +18 -0
- package/src/core/locale.ts +138 -0
- package/src/core/types.ts +6 -0
- package/src/core/umalqura-data.ts +34 -0
- package/src/index.tsx +2 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
export type Locale = 'ar' | 'en';
|
|
2
|
+
export type Digits = 'arabic' | 'latin';
|
|
3
|
+
export type CalendarType = 'hijri' | 'gregorian';
|
|
4
|
+
export type WeekdayFormat = 'short' | 'long';
|
|
5
|
+
|
|
6
|
+
const HIJRI_MONTHS: Record<Locale, readonly string[]> = {
|
|
7
|
+
ar: [
|
|
8
|
+
'محرم',
|
|
9
|
+
'صفر',
|
|
10
|
+
'ربيع الأول',
|
|
11
|
+
'ربيع الآخر',
|
|
12
|
+
'جمادى الأولى',
|
|
13
|
+
'جمادى الآخرة',
|
|
14
|
+
'رجب',
|
|
15
|
+
'شعبان',
|
|
16
|
+
'رمضان',
|
|
17
|
+
'شوال',
|
|
18
|
+
'ذو القعدة',
|
|
19
|
+
'ذو الحجة',
|
|
20
|
+
],
|
|
21
|
+
en: [
|
|
22
|
+
'Muharram',
|
|
23
|
+
'Safar',
|
|
24
|
+
"Rabi' al-Awwal",
|
|
25
|
+
"Rabi' al-Thani",
|
|
26
|
+
'Jumada al-Ula',
|
|
27
|
+
'Jumada al-Akhirah',
|
|
28
|
+
'Rajab',
|
|
29
|
+
"Sha'ban",
|
|
30
|
+
'Ramadan',
|
|
31
|
+
'Shawwal',
|
|
32
|
+
"Dhu al-Qi'dah",
|
|
33
|
+
'Dhu al-Hijjah',
|
|
34
|
+
],
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// Saudi/Gulf style month names (يناير، فبراير ...), not the Levantine
|
|
38
|
+
// names (كانون الثاني، شباط ...).
|
|
39
|
+
const GREGORIAN_MONTHS: Record<Locale, readonly string[]> = {
|
|
40
|
+
ar: [
|
|
41
|
+
'يناير',
|
|
42
|
+
'فبراير',
|
|
43
|
+
'مارس',
|
|
44
|
+
'أبريل',
|
|
45
|
+
'مايو',
|
|
46
|
+
'يونيو',
|
|
47
|
+
'يوليو',
|
|
48
|
+
'أغسطس',
|
|
49
|
+
'سبتمبر',
|
|
50
|
+
'أكتوبر',
|
|
51
|
+
'نوفمبر',
|
|
52
|
+
'ديسمبر',
|
|
53
|
+
],
|
|
54
|
+
en: [
|
|
55
|
+
'January',
|
|
56
|
+
'February',
|
|
57
|
+
'March',
|
|
58
|
+
'April',
|
|
59
|
+
'May',
|
|
60
|
+
'June',
|
|
61
|
+
'July',
|
|
62
|
+
'August',
|
|
63
|
+
'September',
|
|
64
|
+
'October',
|
|
65
|
+
'November',
|
|
66
|
+
'December',
|
|
67
|
+
],
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// Sunday first, matching Date#getDay().
|
|
71
|
+
const WEEKDAYS: Record<Locale, Record<WeekdayFormat, readonly string[]>> = {
|
|
72
|
+
ar: {
|
|
73
|
+
long: [
|
|
74
|
+
'الأحد',
|
|
75
|
+
'الاثنين',
|
|
76
|
+
'الثلاثاء',
|
|
77
|
+
'الأربعاء',
|
|
78
|
+
'الخميس',
|
|
79
|
+
'الجمعة',
|
|
80
|
+
'السبت',
|
|
81
|
+
],
|
|
82
|
+
short: ['أحد', 'اثنين', 'ثلاثاء', 'أربعاء', 'خميس', 'جمعة', 'سبت'],
|
|
83
|
+
},
|
|
84
|
+
en: {
|
|
85
|
+
long: [
|
|
86
|
+
'Sunday',
|
|
87
|
+
'Monday',
|
|
88
|
+
'Tuesday',
|
|
89
|
+
'Wednesday',
|
|
90
|
+
'Thursday',
|
|
91
|
+
'Friday',
|
|
92
|
+
'Saturday',
|
|
93
|
+
],
|
|
94
|
+
short: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The 12 month names of a calendar, January / Muharram first. Returns a
|
|
100
|
+
* new array on every call.
|
|
101
|
+
*/
|
|
102
|
+
export function getMonthNames(
|
|
103
|
+
calendar: CalendarType,
|
|
104
|
+
locale: Locale
|
|
105
|
+
): string[] {
|
|
106
|
+
const names = calendar === 'hijri' ? HIJRI_MONTHS : GREGORIAN_MONTHS;
|
|
107
|
+
return [...names[locale]];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The 7 weekday names, Sunday first (index matches `Date#getDay()`).
|
|
112
|
+
* Returns a new array on every call.
|
|
113
|
+
*/
|
|
114
|
+
export function getWeekdayNames(
|
|
115
|
+
locale: Locale,
|
|
116
|
+
format: WeekdayFormat = 'long'
|
|
117
|
+
): string[] {
|
|
118
|
+
return [...WEEKDAYS[locale][format]];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const ARABIC_INDIC_ZERO = 0x0660; // ٠
|
|
122
|
+
|
|
123
|
+
/** Replaces the Latin digits 0-9 with Arabic-Indic digits (٠-٩). */
|
|
124
|
+
export function toArabicDigits(input: string | number): string {
|
|
125
|
+
return String(input).replace(/[0-9]/g, (digit) =>
|
|
126
|
+
String.fromCharCode(ARABIC_INDIC_ZERO + Number(digit))
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** The default digits for a locale: Arabic-Indic for 'ar', Latin otherwise. */
|
|
131
|
+
export function defaultDigits(locale: Locale): Digits {
|
|
132
|
+
return locale === 'ar' ? 'arabic' : 'latin';
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Formats a number with the requested digits. */
|
|
136
|
+
export function formatNumber(value: number, digits: Digits): string {
|
|
137
|
+
return digits === 'arabic' ? toArabicDigits(value) : String(value);
|
|
138
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// GENERATED FILE - DO NOT EDIT BY HAND.
|
|
2
|
+
// Generated by scripts/generate-umalqura-table.ts from Node's built-in ICU
|
|
3
|
+
// (v22.22.0, ICU 77.1). Run `yarn generate:umalqura` to rebuild.
|
|
4
|
+
|
|
5
|
+
/** First Hijri year in the table. */
|
|
6
|
+
export const UMALQURA_MIN_YEAR = 1356;
|
|
7
|
+
|
|
8
|
+
/** Last Hijri year in the table. */
|
|
9
|
+
export const UMALQURA_MAX_YEAR = 1500;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Days since 1970-01-01 (in the proleptic Gregorian calendar) of
|
|
13
|
+
* 1 Muharram 1356.
|
|
14
|
+
*/
|
|
15
|
+
export const UMALQURA_START_EPOCH_DAY = -11981;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* One entry per Hijri year from 1356 to 1500. Bit (month - 1) is
|
|
19
|
+
* set when that month has 30 days and clear when it has 29.
|
|
20
|
+
*/
|
|
21
|
+
export const UMALQURA_MONTH_LENGTH_MASKS: readonly number[] = [
|
|
22
|
+
3754, 3732, 3370, 3158, 1198, 2669, 1386, 3413, 3402, 2707, 1323, 2651, 1338,
|
|
23
|
+
1717, 3753, 3410, 3369, 2645, 1197, 1389, 2794, 1764, 3793, 3490, 2730, 2394,
|
|
24
|
+
730, 1465, 2994, 1892, 1737, 1365, 683, 1243, 2746, 1460, 3497, 3410, 2725,
|
|
25
|
+
2349, 621, 2285, 730, 2773, 2725, 2635, 1175, 2359, 694, 2421, 3433, 3410,
|
|
26
|
+
3221, 2347, 603, 1243, 2517, 1490, 3493, 3402, 2709, 1357, 2733, 938, 3026,
|
|
27
|
+
3012, 2953, 2709, 1325, 1453, 2922, 1748, 3529, 3474, 2726, 2390, 686, 1389,
|
|
28
|
+
874, 2901, 2730, 2381, 1181, 2397, 698, 1461, 1450, 3413, 2714, 2350, 622,
|
|
29
|
+
1373, 2778, 1748, 1701, 2855, 2637, 1197, 1389, 2906, 1876, 3913, 3730, 3366,
|
|
30
|
+
2646, 854, 1717, 2986, 2962, 2853, 1675, 2715, 1370, 2778, 1460, 3497, 2898,
|
|
31
|
+
2714, 1334, 630, 1397, 2802, 1748, 1705, 1365, 685, 1213, 2490, 1396, 2921,
|
|
32
|
+
2898, 2709, 1325, 2653, 1242, 2777, 1714, 3733, 3626, 3222, 2350, 2733, 1386,
|
|
33
|
+
3429, 3402,
|
|
34
|
+
];
|
package/src/index.tsx
ADDED