anorgatarrak-wordpress-theme/node_modules/underscore.string/dedent.js

29 lines
610 B
JavaScript
Raw Normal View History

var makeString = require('./helper/makeString');
function getIndent(str) {
var matches = str.match(/^[\s\\t]*/gm);
var indent = matches[0].length;
for (var i = 1; i < matches.length; i++) {
indent = Math.min(matches[i].length, indent);
}
return indent;
}
module.exports = function dedent(str, pattern) {
str = makeString(str);
var indent = getIndent(str);
var reg;
if (indent === 0) return str;
if (typeof pattern === 'string') {
reg = new RegExp('^' + pattern, 'gm');
} else {
reg = new RegExp('^[ \\t]{' + indent + '}', 'gm');
}
return str.replace(reg, '');
};