forked from mgcrea/angular-strap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindent.js
More file actions
32 lines (26 loc) · 849 Bytes
/
indent.js
File metadata and controls
32 lines (26 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
'use strict';
angular.module('mgcrea.ngStrapDocs')
.value('indent', function(text, spaces) {
if(!text) return text;
var lines = text.split(/\r?\n/);
var prefix = ' '.substr(0, spaces || 0);
var i;
// Remove any leading blank lines
while(lines.length && lines[0].match(/^\s*$/)) lines.shift();
// Remove any trailing blank lines
while(lines.length && lines[lines.length - 1].match(/^\s*$/)) lines.pop();
// Calculate proper indent
var minIndent = 999;
for(i = 0; i < lines.length; i++) {
var line = lines[0];
var indent = line.match(/^\s*/)[0];
if(indent !== line && indent.length < minIndent) {
minIndent = indent.length;
}
}
for(i = 0; i < lines.length; i++) {
lines[i] = prefix + lines[i].substring(minIndent).replace(/=""/g, '');
}
lines.push('');
return lines.join('\n');
});