import { mapKeys , pick } from 'lodash' ; import { directories } from '../util/directories' ; import { files } from '../util/category' ; import { get } from '../util/get' ; import { separate } from '../util/separate' ; import { timeArray } from '../util/timeArray' ; import { validate } from '../util/validate' ; import { write } from '../util/write' ; import { width } from '../util/width' ; const monthsArray = [ 'Jan' , 'Feb' , 'Mar' , 'Apr' , 'May' , 'Jun' , 'Jul' , 'Aug' , 'Sep' , 'Oct' , 'Nov' , 'Dec' ] ; const northHemisphere = monthsArray . map ( ( month ) => `nh${ month }` ) ; const southHemisphere = monthsArray . map ( ( month ) => `sh${ month }` ) ; param months return function activeMonths ( months ) { let available = [ [ ] ] ; for ( const month in months ) { if ( months [ month ] ) { available [ available . length - 1 ] . push ( month ) ; } else available . push ( [ ] ) ; } available = available . filter ( ( months ) => months . length ) ; return available . map ( ( months ) => months . length > 1 ? `${ months [ 0 ] } - ${ months [ months . length - 1 ] }` : months [ 0 ] ) ; } param creature return function hemisphere ( creature ) { const hemispheres = { north : pick ( creature , northHemisphere ) , south : pick ( creature , southHemisphere ) } ; for ( const hemisphere in hemispheres ) { const months = mapKeys ( hemispheres [ hemisphere ] , ( value , key ) => key . replace ( /sh|nh/g , '' ) ) ; const valid = validate ( months ) ; const time = separate ( Object . values ( valid ) [ 0 ] , ';' ) ; let timespan = time . map ( ( time ) => timeArray ( time ) ) ; timespan = timespan . length === 1 ? timespan . flat ( ) : timespan ; const monthArray = Object . keys ( valid ) . map ( ( month ) => monthsArray . indexOf ( month ) + 1 ) ; hemispheres [ hemisphere ] = { time , timeArray : timespan , months : activeMonths ( months ) , monthsArray : monthArray } ; } return hemispheres ; } for ( const file of files ( 'Creatures' , directories . sanitized ) ) { const creatures = get ( file ) ; for ( const creature of creatures ) { creature . hemispheres = hemisphere ( creature ) ; creature . colors = [ creature . color1 , creature . color2 ] . filter ( ( color ) => ! ! color ) ; for ( const key of [ 'color1' , 'color2' , ... northHemisphere , ... southHemisphere ] ) { delete creature [ key ] ; } } write ( file , creatures , width ( 'Creatures' ) ) ; }