import type { Quarter } from '../../../../types' ; import type { Match } from '../../../types' ; import buildMatchFn from '../../../_lib/buildMatchFn/index' ; import buildMatchPatternFn from '../../../_lib/buildMatchPatternFn/index' ; const matchOrdinalNumberPattern = /^(\d+)(af|ail|ydd|ed|fed|eg|ain)?/i ; const parseOrdinalNumberPattern = /\d+/i ; const matchEraPatterns = { narrow : /^(c|o)/i , abbreviated : /^(c\.?\s?c\.?|o\.?\s?c\.?)/i , wide : /^(cyn christ|ar ôl crist|ar ol crist)/i , } ; const parseEraPatterns = { wide : [ /^c/i , /^(ar ôl crist|ar ol crist)/i ] as const , any : [ /^c/i , /^o/i ] as const , } ; const matchQuarterPatterns = { narrow : /^[1234]/i , abbreviated : /^ch[1234]/i , wide : /^(chwarter 1af)|([234](ail|ydd)? chwarter)/i , } ; const parseQuarterPatterns = { any : [ /1/i , /2/i , /3/i , /4/i ] as const , } ; const matchMonthPatterns = { narrow : /^(i|ch|m|e|g|a|h|t|rh)/i , abbreviated : /^(ion|chwe|maw|ebr|mai|meh|gor|aws|med|hyd|tach|rhag)/i , wide : /^(ionawr|chwefror|mawrth|ebrill|mai|mehefin|gorffennaf|awst|medi|hydref|tachwedd|rhagfyr)/i , } ; const parseMonthPatterns = { narrow : [ /^i/i , /^ch/i , /^m/i , /^e/i , /^m/i , /^m/i , /^g/i , /^a/i , /^m/i , /^h/i , /^t/i , /^rh/i , ] as const , any : [ /^io/i , /^ch/i , /^maw/i , /^e/i , /^mai/i , /^meh/i , /^g/i , /^a/i , /^med/i , /^h/i , /^t/i , /^rh/i , ] as const , } ; const matchDayPatterns = { narrow : /^(s|ll|m|i|g)/i , short : /^(su|ll|ma|me|ia|gw|sa)/i , abbreviated : /^(sul|llun|maw|mer|iau|gwe|sad)/i , wide : /^dydd (sul|llun|mawrth|mercher|iau|gwener|sadwrn)/i , } ; const parseDayPatterns = { narrow : [ /^s/i , /^ll/i , /^m/i , /^m/i , /^i/i , /^g/i , /^s/i ] as const , wide : [ /^dydd su/i , /^dydd ll/i , /^dydd ma/i , /^dydd me/i , /^dydd i/i , /^dydd g/i , /^dydd sa/i , ] as const , any : [ /^su/i , /^ll/i , /^ma/i , /^me/i , /^i/i , /^g/i , /^sa/i ] as const , } ; const matchDayPeriodPatterns = { narrow : /^(b|h|hn|hd|(yn y|y|yr|gyda'r) (bore|prynhawn|nos|hwyr))/i , any : /^(y\.?\s?[bh]\.?|hanner nos|hanner dydd|(yn y|y|yr|gyda'r) (bore|prynhawn|nos|hwyr))/i , } ; const parseDayPeriodPatterns = { any : { am : /^b|(y\.?\s?b\.?)/i , pm : /^h|(y\.?\s?h\.?)|(yr hwyr)/i , midnight : /^hn|hanner nos/i , noon : /^hd|hanner dydd/i , morning : /bore/i , afternoon : /prynhawn/i , evening : /^gyda'r nos$/i , night : /blah/i , } , } ; 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 ) as Quarter , } ) , 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 : 'any' , parsePatterns : parseDayPeriodPatterns , defaultParseWidth : 'any' , } ) , } ; export default match ;