| 
									
										
										
										
											2019-07-24 12:07:07 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							| 
									
										
										
										
											2020-05-19 12:08:49 -07:00
										 |  |  |  * Copyright Google LLC All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2019-07-24 12:07:07 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Template string function that can be used to dedent the resulting | 
					
						
							|  |  |  |  * string literal. The smallest common indentation will be omitted. | 
					
						
							| 
									
										
										
										
											2020-06-25 15:38:18 +02:00
										 |  |  |  * Additionally, whitespace in empty lines is removed. | 
					
						
							| 
									
										
										
										
											2019-07-24 12:07:07 +02:00
										 |  |  |  */ | 
					
						
							|  |  |  | export function dedent(strings: TemplateStringsArray, ...values: any[]) { | 
					
						
							|  |  |  |   let joinedString = ''; | 
					
						
							|  |  |  |   for (let i = 0; i < values.length; i++) { | 
					
						
							|  |  |  |     joinedString += `${strings[i]}${values[i]}`; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   joinedString += strings[strings.length - 1]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const matches = joinedString.match(/^[ \t]*(?=\S)/gm); | 
					
						
							|  |  |  |   if (matches === null) { | 
					
						
							|  |  |  |     return joinedString; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const minLineIndent = Math.min(...matches.map(el => el.length)); | 
					
						
							|  |  |  |   const omitMinIndentRegex = new RegExp(`^[ \\t]{${minLineIndent}}`, 'gm'); | 
					
						
							| 
									
										
										
										
											2020-06-25 15:38:18 +02:00
										 |  |  |   const omitEmptyLineWhitespaceRegex = /^[ \t]+$/gm; | 
					
						
							|  |  |  |   const result = minLineIndent > 0 ? joinedString.replace(omitMinIndentRegex, '') : joinedString; | 
					
						
							|  |  |  |   return result.replace(omitEmptyLineWhitespaceRegex, ''); | 
					
						
							| 
									
										
										
										
											2019-07-24 12:07:07 +02:00
										 |  |  | } |