mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-03 21:19:01 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			22 lines
		
	
	
		
			687 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			22 lines
		
	
	
		
			687 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
export function trimIndentation(strings: TemplateStringsArray) {
 | 
						|
    const str = strings.toString();
 | 
						|
 | 
						|
    // Count the number of spaces on the first line.
 | 
						|
    let numSpaces = 0;
 | 
						|
    while (str.charAt(numSpaces) == " " && numSpaces < str.length) {
 | 
						|
        numSpaces++;
 | 
						|
    }
 | 
						|
 | 
						|
    // Trim the indentation of the first line in all the lines.
 | 
						|
    const lines = str.split("\n");
 | 
						|
    const output = [];
 | 
						|
    for (let i = 0; i < lines.length; i++) {
 | 
						|
        let numSpacesLine = 0;
 | 
						|
        while (str.charAt(numSpacesLine) == " " && numSpacesLine < str.length) {
 | 
						|
            numSpacesLine++;
 | 
						|
        }
 | 
						|
        output.push(lines[i].substring(numSpacesLine));
 | 
						|
    }
 | 
						|
    return output.join("\n");
 | 
						|
}
 |