import { lineWrap , Code , HEADER , NOLINT_MAXLINE } from './util' ; export const getUnits = ( data ) : Code [ ] => { const res = [ ] ; let code = `${ HEADER }${ NOLINT_MAXLINE }\n` ; const units = [ ] ; const categoryMap = { } ; const categories = [ ] ; data . units . forEach ( ( s ) => { const index = s . indexOf ( '-' ) ; const category = s . substring ( 0 , index ) ; let unit = s . substring ( index + 1 ) ; if ( category === 'temperature' && unit === 'generic' ) { unit = category ; } const cat = `'${ category }'` ; let i = categories . indexOf ( cat ) ; if ( i === - 1 ) { i = categories . length ; categories . push ( cat ) ; } categoryMap [ unit ] = i ; units . push ( `'${ unit }'` ) ; } ) ; const unitType = lineWrap ( 60 , ' | ' , units ) ; code += '/** @public */\n' ; code += `export type UnitType = ${ unitType };\n\n` ; const unitCategory = lineWrap ( 60 , ' | ' , categories ) ; code += '/** @public */\n' ; code += `export type UnitCategory = ${ unitCategory };\n` ; res . push ( Code . types ( [ 'autogen.units.ts' ] , code ) ) ; return res ; } ;