1 | var indentRe = /^\s+/;
|
2 | var tabRe = /^\t+/g;
|
3 | var nlRe = /\r\n|[\r\n]/;
|
4 |
|
5 | module.exports = unindent;
|
6 |
|
7 | function unindent(code, opts) {
|
8 | var tabSize = opts && opts.tabSize;
|
9 |
|
10 | var indent = indentRe.exec(code);
|
11 | if (indent) indent = indent[0];
|
12 |
|
13 | return code.split(nlRe).map(function (line) {
|
14 | if (indent && line.substr(0, indent.length) === indent) {
|
15 | line = line.substr(indent.length);
|
16 | }
|
17 | if (tabSize) {
|
18 | line = line.replace(tabRe, function (tabs) {
|
19 | return tabs.replace(/\t/g, new Array(tabSize + 1).join(' '));
|
20 | });
|
21 | }
|
22 | return line;
|
23 | }).join('\n');
|
24 | } |
\ | No newline at end of file |