/
githubmirror
/
dayjs
Обзор
Документация
Войти
/
githubmirror
/
dayjs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
src/locale/ar.js
88 строк
2 KB
Moshe Jonathan Gordon Radian
fix: dont instantiate regexes within ar locale functions to avoid performance overhead (#2898)
01 сен 2025, 08:06
Не верифицирован
01 сен 2025, 08:06
af5e9f0
Код
Авторство
О чём код?
// Arabic [ar] import dayjs from 'dayjs' const months = 'يناير_فبراير_مارس_أبريل_مايو_يونيو_يوليو_أغسطس_سبتمبر_أكتوبر_نوفمبر_ديسمبر'.split('_') const symbolMap = { 1: '١', 2: '٢', 3: '٣', 4: '٤', 5: '٥', 6: '٦', 7: '٧', 8: '٨', 9: '٩', 0: '٠' } const numberMap = { '١': '1', '٢': '2', '٣': '3', '٤': '4', '٥': '5', '٦': '6', '٧': '7', '٨': '8', '٩': '9', '٠': '0' } const fromArabNumeralsRegex = /[١٢٣٤٥٦٧٨٩٠]/g const fromArabComaRegex = /،/g const toArabNumeralsRegex = /\d/g const toArabComaRegex = /,/g const locale = { name: 'ar', weekdays: 'الأحد_الإثنين_الثلاثاء_الأربعاء_الخميس_الجمعة_السبت'.split('_'), weekdaysShort: 'أحد_إثنين_ثلاثاء_أربعاء_خميس_جمعة_سبت'.split('_'), weekdaysMin: 'ح_ن_ث_ر_خ_ج_س'.split('_'), months, monthsShort: months, weekStart: 6, meridiem: hour => (hour > 12 ? 'م' : 'ص'), relativeTime: { future: 'بعد %s', past: 'منذ %s', s: 'ثانية واحدة', m: 'دقيقة واحدة', mm: '%d دقائق', h: 'ساعة واحدة', hh: '%d ساعات', d: 'يوم واحد', dd: '%d أيام', M: 'شهر واحد', MM: '%d أشهر', y: 'عام واحد', yy: '%d أعوام' }, preparse(string) { return string .replace( fromArabNumeralsRegex, match => numberMap[match] ) .replace(fromArabComaRegex, ',') }, postformat(string) { return string .replace(toArabNumeralsRegex, match => symbolMap[match]) .replace(toArabComaRegex, '،') }, ordinal: n => n, formats: { LT: 'HH:mm', LTS: 'HH:mm:ss', L: 'D/M/YYYY', LL: 'D MMMM YYYY', LLL: 'D MMMM YYYY HH:mm', LLLL: 'dddd D MMMM YYYY HH:mm' } } dayjs.locale(locale, null, true) export default locale