143 lines
4.1 KiB
JavaScript
143 lines
4.1 KiB
JavaScript
|
import { buildMatchFn } from "../../_lib/buildMatchFn.mjs";
|
|||
|
import { buildMatchPatternFn } from "../../_lib/buildMatchPatternFn.mjs";
|
|||
|
|
|||
|
const matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i;
|
|||
|
const parseOrdinalNumberPattern = /\d+/i;
|
|||
|
|
|||
|
const matchEraPatterns = {
|
|||
|
narrow: /^(ق|ب)/i,
|
|||
|
abbreviated: /^(ق\.?\s?م\.?|ق\.?\s?د\.?\s?م\.?|م\.?\s?|د\.?\s?م\.?)/i,
|
|||
|
wide: /^(قبل از میلاد|قبل از دوران مشترک|میلادی|دوران مشترک|بعد از میلاد)/i,
|
|||
|
};
|
|||
|
const parseEraPatterns = {
|
|||
|
any: [/^قبل/i, /^بعد/i],
|
|||
|
};
|
|||
|
|
|||
|
const matchQuarterPatterns = {
|
|||
|
narrow: /^[1234]/i,
|
|||
|
abbreviated: /^سم[1234]/i,
|
|||
|
wide: /^سهماهه [1234]/i,
|
|||
|
};
|
|||
|
const parseQuarterPatterns = {
|
|||
|
any: [/1/i, /2/i, /3/i, /4/i],
|
|||
|
};
|
|||
|
|
|||
|
const matchMonthPatterns = {
|
|||
|
narrow: /^[جژفمآاماسند]/i,
|
|||
|
abbreviated:
|
|||
|
/^(جنو|ژانـ|ژانویه|فوریه|فور|مارس|آوریل|آپر|مه|می|ژوئن|جون|جول|جولـ|ژوئیه|اوت|آگو|سپتمبر|سپتامبر|اکتبر|اکتوبر|نوامبر|نوامـ|دسامبر|دسامـ|دسم)/i,
|
|||
|
wide: /^(ژانویه|جنوری|فبروری|فوریه|مارچ|مارس|آپریل|اپریل|ایپریل|آوریل|مه|می|ژوئن|جون|جولای|ژوئیه|آگست|اگست|آگوست|اوت|سپتمبر|سپتامبر|اکتبر|اکتوبر|نوامبر|نومبر|دسامبر|دسمبر)/i,
|
|||
|
};
|
|||
|
const parseMonthPatterns = {
|
|||
|
narrow: [
|
|||
|
/^(ژ|ج)/i,
|
|||
|
/^ف/i,
|
|||
|
/^م/i,
|
|||
|
/^(آ|ا)/i,
|
|||
|
/^م/i,
|
|||
|
/^(ژ|ج)/i,
|
|||
|
/^(ج|ژ)/i,
|
|||
|
/^(آ|ا)/i,
|
|||
|
/^س/i,
|
|||
|
/^ا/i,
|
|||
|
/^ن/i,
|
|||
|
/^د/i,
|
|||
|
],
|
|||
|
|
|||
|
any: [
|
|||
|
/^ژا/i,
|
|||
|
/^ف/i,
|
|||
|
/^ما/i,
|
|||
|
/^آپ/i,
|
|||
|
/^(می|مه)/i,
|
|||
|
/^(ژوئن|جون)/i,
|
|||
|
/^(ژوئی|جول)/i,
|
|||
|
/^(اوت|آگ)/i,
|
|||
|
/^س/i,
|
|||
|
/^(اوک|اک)/i,
|
|||
|
/^ن/i,
|
|||
|
/^د/i,
|
|||
|
],
|
|||
|
};
|
|||
|
|
|||
|
const matchDayPatterns = {
|
|||
|
narrow: /^[شیدسچپج]/i,
|
|||
|
short: /^(ش|ج|1ش|2ش|3ش|4ش|5ش)/i,
|
|||
|
abbreviated: /^(یکشنبه|دوشنبه|سهشنبه|چهارشنبه|پنجشنبه|جمعه|شنبه)/i,
|
|||
|
wide: /^(یکشنبه|دوشنبه|سهشنبه|چهارشنبه|پنجشنبه|جمعه|شنبه)/i,
|
|||
|
};
|
|||
|
const parseDayPatterns = {
|
|||
|
narrow: [/^ی/i, /^دو/i, /^س/i, /^چ/i, /^پ/i, /^ج/i, /^ش/i],
|
|||
|
any: [
|
|||
|
/^(ی|1ش|یکشنبه)/i,
|
|||
|
/^(د|2ش|دوشنبه)/i,
|
|||
|
/^(س|3ش|سهشنبه)/i,
|
|||
|
/^(چ|4ش|چهارشنبه)/i,
|
|||
|
/^(پ|5ش|پنجشنبه)/i,
|
|||
|
/^(ج|جمعه)/i,
|
|||
|
/^(ش|شنبه)/i,
|
|||
|
],
|
|||
|
};
|
|||
|
|
|||
|
const matchDayPeriodPatterns = {
|
|||
|
narrow: /^(ب|ق|ن|ظ|ص|ب.ظ.|ع|ش)/i,
|
|||
|
abbreviated: /^(ق.ظ.|ب.ظ.|نیمهشب|ظهر|صبح|بعدازظهر|عصر|شب)/i,
|
|||
|
wide: /^(قبلازظهر|نیمهشب|ظهر|صبح|بعدازظهر|عصر|شب)/i,
|
|||
|
};
|
|||
|
const parseDayPeriodPatterns = {
|
|||
|
any: {
|
|||
|
am: /^(ق|ق.ظ.|قبلازظهر)/i,
|
|||
|
pm: /^(ب|ب.ظ.|بعدازظهر)/i,
|
|||
|
midnight: /^(نیمهشب|ن)/i,
|
|||
|
noon: /^(ظ|ظهر)/i,
|
|||
|
morning: /(ص|صبح)/i,
|
|||
|
afternoon: /(ب|ب.ظ.|بعدازظهر)/i,
|
|||
|
evening: /(ع|عصر)/i,
|
|||
|
night: /(ش|شب)/i,
|
|||
|
},
|
|||
|
};
|
|||
|
|
|||
|
export const match = {
|
|||
|
ordinalNumber: buildMatchPatternFn({
|
|||
|
matchPattern: matchOrdinalNumberPattern,
|
|||
|
parsePattern: parseOrdinalNumberPattern,
|
|||
|
valueCallback: (value) => parseInt(value, 10),
|
|||
|
}),
|
|||
|
|
|||
|
era: buildMatchFn({
|
|||
|
matchPatterns: matchEraPatterns,
|
|||
|
defaultMatchWidth: "wide",
|
|||
|
parsePatterns: parseEraPatterns,
|
|||
|
defaultParseWidth: "any",
|
|||
|
}),
|
|||
|
|
|||
|
quarter: buildMatchFn({
|
|||
|
matchPatterns: matchQuarterPatterns,
|
|||
|
defaultMatchWidth: "wide",
|
|||
|
parsePatterns: parseQuarterPatterns,
|
|||
|
defaultParseWidth: "any",
|
|||
|
valueCallback: (index) => index + 1,
|
|||
|
}),
|
|||
|
|
|||
|
month: buildMatchFn({
|
|||
|
matchPatterns: matchMonthPatterns,
|
|||
|
defaultMatchWidth: "wide",
|
|||
|
parsePatterns: parseMonthPatterns,
|
|||
|
defaultParseWidth: "any",
|
|||
|
}),
|
|||
|
|
|||
|
day: buildMatchFn({
|
|||
|
matchPatterns: matchDayPatterns,
|
|||
|
defaultMatchWidth: "wide",
|
|||
|
parsePatterns: parseDayPatterns,
|
|||
|
defaultParseWidth: "any",
|
|||
|
}),
|
|||
|
|
|||
|
dayPeriod: buildMatchFn({
|
|||
|
matchPatterns: matchDayPeriodPatterns,
|
|||
|
defaultMatchWidth: "wide",
|
|||
|
parsePatterns: parseDayPeriodPatterns,
|
|||
|
defaultParseWidth: "any",
|
|||
|
}),
|
|||
|
};
|