3 var trim = require('trim');
4 var repeat = require('repeat-string');
5 var getIndent = require('./get-indentation');
7 module.exports = indentation;
13 /* Remove the minimum indent from every line in `value`.
14 * Supports both tab, spaced, and mixed indentation (as
15 * well as possible). */
16 function indentation(value, maximum) {
17 var values = value.split(C_NEWLINE);
18 var position = values.length + 1;
19 var minIndent = Infinity;
26 values.unshift(repeat(C_SPACE, maximum) + '!');
29 indentation = getIndent(values[position]);
31 matrix[position] = indentation.stops;
33 if (trim(values[position]).length === 0) {
37 if (indentation.indent) {
38 if (indentation.indent > 0 && indentation.indent < minIndent) {
39 minIndent = indentation.indent;
48 if (minIndent !== Infinity) {
49 position = values.length;
52 stops = matrix[position];
55 while (index && !(index in stops)) {
60 trim(values[position]).length !== 0 &&
69 values[position] = padding + values[position].slice(
70 index in stops ? stops[index] + 1 : 0
77 return values.join(C_NEWLINE);