import { DurationInput } from './types' ; import { parse } from './parse' ; import { UNITS_META , UNITS_META_MAP } from './lib/units' ; example export const toMilliseconds = ( duration ) : number => { const parsed = parse ( duration ) ; return UNITS_META . reduce ( ( total , { unit , milliseconds } ) => { return total + ( parsed [ unit ] * milliseconds ) ; } , 0 ) ; } ; example export const toUnit = ( duration , unit ) : number => { return toMilliseconds ( duration ) / UNITS_META_MAP [ unit ] . milliseconds ; } ; const createDurationConverter = ( unit ) => { return ( duration ) : number => toUnit ( duration , unit ) ; } ; example export const toSeconds = createDurationConverter ( 'seconds' ) ; example export const toMinutes = createDurationConverter ( 'minutes' ) ; example export const toHours = createDurationConverter ( 'hours' ) ; example export const toDays = createDurationConverter ( 'days' ) ; example export const toWeeks = createDurationConverter ( 'weeks' ) ; example export const toMonths = createDurationConverter ( 'months' ) ; example export const toYears = createDurationConverter ( 'years' ) ;