import { Code , HEADER , NOLINT } from './util' ; type MapType = { [ x ] : number ; } ; const DIGIT = /\d/g ; const key = ( k ) : string => ( DIGIT . test ( k [ 0 ] ) ? `'${ k }'` : k ) ; const encode = ( map ) : string => { let raw = '' ; Object . keys ( map ) . forEach ( ( k ) => { if ( raw . length > 0 ) { raw += ',' ; } raw += `${ key ( k ) }:${ map [ k ] }` ; } ) ; return raw ; } ; const DAYS = { sun : 1 , mon : 2 , tue : 3 , wed : 4 , thu : 5 , fri : 6 , sat : 7 } ; export const getWeekData = ( data ) : Code [ ] => { const minDays = { } ; Object . keys ( data . minDays ) . forEach ( ( k ) => { minDays [ k ] = Number ( data . minDays [ k ] ) ; } ) ; const firstDay = { } ; Object . keys ( data . firstDay ) . forEach ( ( k ) => { if ( k . indexOf ( '-alt-variant' ) !== - 1 ) { return ; } const name = data . firstDay [ k ] ; firstDay [ k ] = DAYS [ name ] ; } ) ; let code = HEADER + NOLINT ; code += `export const weekFirstDay: { [x: string]: number } = {${ encode ( firstDay ) }};\n\n` ; code += NOLINT ; code += `export const weekMinDays: { [x: string]: number } = {${ encode ( minDays ) }};\n` ; return [ Code . core ( [ 'internals' , 'calendars' , 'autogen.weekdata.ts' ] , code ) ] ; } ;