export function dedentString ( string ) { const trimmedStr = string . replace ( /^\n*/m , '' ) . replace ( /[ \t\n]*$/ , '' ) ; let indent = '' ; for ( const char of trimmedStr ) { if ( char !== ' ' && char !== '\t' ) { break ; } indent += char ; } return trimmedStr . replace ( RegExp ( '^' + indent , 'mg' ) , '' ) ; } /**
 * An ES6 string tag that fixes indentation and also trims string.
 *
 * Example usage:
 * ```ts
 * const str = dedent`
 *   {
 *     test
 *   }
 * `;
 * str === "{\n  test\n}";
 * ```
 */ export function dedent ( strings , ... values ) { let str = strings [ 0 ] ; for ( let i = 1 ; i < strings . length ; ++ i ) { str += values [ i - 1 ] + strings [ i ] ; } return dedentString ( str ) ; }