1- import { toString } from "builtin-modules" ;
2-
31export const RomanNumberRegexStr : string = ' *([MDCLXVI]+)' ; // Roman number
42export const CompoundRomanNumberDotRegexStr : string = ' *([MDCLXVI]+(?:\\.[MDCLXVI]+)*)' ; // Compound Roman number with dot as separator
53export const CompoundRomanNumberDashRegexStr : string = ' *([MDCLXVI]+(?:-[MDCLXVI]+)*)' ; // Compound Roman number with dash as separator
@@ -9,6 +7,7 @@ export const CompoundNumberDotRegexStr: string = ' *(\\d+(?:\\.\\d+)*)'; // Comp
97export const CompoundNumberDashRegexStr : string = ' *(\\d+(?:-\\d+)*)' ; // Compound number with dash as separator
108
119export const Date_dd_Mmm_yyyy_RegexStr : string = ' *([0-3]*[0-9]-(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-\\d{4})' ; // Date like 01-Jan-2020
10+ export const Date_Mmm_dd_yyyy_RegexStr : string = ' *((?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-[0-3]*[0-9]-\\d{4})' ; // Date like Jan-01-2020
1211
1312export const DOT_SEPARATOR = '.'
1413export const DASH_SEPARATOR = '-'
@@ -104,17 +103,23 @@ export function getNormalizedRomanNumber(s: string, separator?: string, places?:
104103 }
105104}
106105
107- const DAY_POSITIONS = '00' . length
108- const MONTH_POSITIONS = '00' . length
109- const YEAR_POSITIONS = '0000' . length
106+ export const DAY_POSITIONS = '00' . length
107+ export const MONTH_POSITIONS = '00' . length
108+ export const YEAR_POSITIONS = '0000' . length
110109
111110const MONTHS = [ 'Jan' , 'Feb' , 'Mar' , 'Apr' , 'May' , 'Jun' , 'Jul' , 'Aug' , 'Sep' , 'Oct' , 'Nov' , 'Dec' ]
112111
113- export function getNormalizedDate_dd_Mmm_yyyy_NormalizerFn ( s : string ) : string | null {
114- // Assumption - the regex date matched against input s, no extensive defensive coding needed
115- const components = s . split ( '-' )
116- const day = prependWithZeros ( components [ 0 ] , DAY_POSITIONS )
117- const month = prependWithZeros ( `${ 1 + MONTHS . indexOf ( components [ 1 ] ) } ` , MONTH_POSITIONS )
118- const year = prependWithZeros ( components [ 2 ] , YEAR_POSITIONS )
119- return `${ year } -${ month } -${ day } //`
112+ export function getNormalizedDate_NormalizerFn_for ( separator : string , dayIdx : number , monthIdx : number , yearIdx : number , months ?: string [ ] ) {
113+ return ( s : string ) : string | null => {
114+ // Assumption - the regex date matched against input s, no extensive defensive coding needed
115+ const components = s . split ( separator )
116+ const day = prependWithZeros ( components [ dayIdx ] , DAY_POSITIONS )
117+ const monthValue = months ? `${ 1 + MONTHS . indexOf ( components [ monthIdx ] ) } ` : components [ monthIdx ]
118+ const month = prependWithZeros ( monthValue , MONTH_POSITIONS )
119+ const year = prependWithZeros ( components [ yearIdx ] , YEAR_POSITIONS )
120+ return `${ year } -${ month } -${ day } //`
121+ }
120122}
123+
124+ export const getNormalizedDate_dd_Mmm_yyyy_NormalizerFn = getNormalizedDate_NormalizerFn_for ( '-' , 0 , 1 , 2 , MONTHS )
125+ export const getNormalizedDate_Mmm_dd_yyyy_NormalizerFn = getNormalizedDate_NormalizerFn_for ( '-' , 1 , 0 , 2 , MONTHS )
0 commit comments