import { isSameMonth } from 'date-fns' ; import { ActiveModifiers , Modifiers } from 'types/Modifiers' ; import { isMatch } from './isMatch' ; /** Return the active modifiers for the given day. */ export function matchModifiers ( day , /** The modifiers to match for the given date. */ modifiers , /** The month where the day is displayed, to add the "outside" modifiers.  */ displayMonth ? ) { const modifiersList = Object . keys ( modifiers ) . reduce ( ( previousValue , key ) : string [ ] => { const modifier = modifiers [ key ] ; if ( isMatch ( day , modifier ) ) { previousValue . push ( key ) ; } return previousValue ; } , [ ] ) ; const activeModifiers = { } ; modifiersList . forEach ( ( modifier ) => ( activeModifiers [ modifier ] = true ) ) ; if ( displayMonth && ! isSameMonth ( day , displayMonth ) ) { activeModifiers . outside = true ; } return activeModifiers ; }