/******************************************************************************
 * Copyright 2021 TypeFox GmbH
 * This program and the accompanying materials are made available under the
 * terms of the MIT License, which is available in the project root.
 ******************************************************************************/ const leadingWhitespace = /^(s*\n)+/ ; const newline = /\n/g ; const nonWhitespace = /\S|$/ ; param staticParts param substitutions returns export function s ( staticParts , ... substitutions ) { const lines = substitutions . reduce ( ( acc , subst , i ) => acc + align ( String ( subst ) , acc ) + staticParts [ i + 1 ] , staticParts [ 0 ] ) . split ( '\n' ) . map ( line => line . trimRight ( ) ) ; const indent = findIndentation ( lines ) ; return lines . map ( line => line . slice ( indent ) . trimRight ( ) ) . join ( '\n' ) . trimRight ( ) . replace ( leadingWhitespace , '' ) ; } function align ( subst , acc ) { const length = Math . max ( 0 , acc . length - acc . lastIndexOf ( '\n' ) - 1 ) ; const indent = ' ' . repeat ( length ) ; return subst . replace ( newline , '\n' + indent ) ; } function findIndentation ( lines ) { const indents = lines . filter ( line => line . length > 0 ) . map ( line => line . search ( nonWhitespace ) ) ; const min = indents . length === 0 ? 0 : Math . min ( ... indents ) ; return Math . max ( 0 , min ) ; }