dedent = (template_function = String.raw) => (
strings ,
...values
) => {
let lines = interpolated_lines(strings, ...values);
let indentation = get_identation(lines);
let lines_without_identation = lines.map(([first_string, ...rest]) => {
return [first_string.slice(indentation), ...rest];
});
let lines_trimmed = tweak_first_and_last_line(
lines_without_identation,
indentation
);
let elements = concat_lines(lines_trimmed);
let new_strings = [];
let new_values = [];
for (let [string, value] of _.chunk(elements, 2)) {
new_strings.push(string);
if (value) {
new_values.push(value);
}
}
new_strings.raw = new_strings;
return template_function(new_strings, ...new_values);
}