import { unixEOL } from './string-formatter' ; import { zip } from './array' ; import { trim , trimRight } from './string' ; experimental param strings param args returns export function codeBlock ( strings , ... args ) { const pre = strings . slice ( 0 , - 1 ) . map ( string => { const trimmed = trimRight ( string ) ; return trimmed . length === string . length ? string : trimmed + unixEOL ; } ) ; pre . push ( strings [ strings . length - 1 ] ) ; const indents = strings . slice ( 0 , - 1 ) . map ( s => { const indentation = s . split ( unixEOL ) . pop ( ) ! ; return ! indentation . trim ( ) ? indentation : '' ; } ) ; const post = args . map ( ( arg , i ) => ( '' + arg ) . split ( unixEOL ) . map ( subArg => indents [ i ] + subArg ) . join ( unixEOL ) ) ; const zipped = zip ( pre , post ) ; return trim ( zipped . join ( '' ) ) ; }