Sha256: 8905c488b758285ca27105613edb72b179e30740d59bd74c627d1de89293746b

Contents?: true

Size: 610 Bytes

Versions: 19

Compression:

Stored size: 610 Bytes

Contents

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, '');
};

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
ela-4.1.6 node_modules/underscore.string/dedent.js
ela-4.1.5 node_modules/underscore.string/dedent.js
ela-4.1.4 node_modules/underscore.string/dedent.js
ela-4.1.3 node_modules/underscore.string/dedent.js
ela-4.1.2 node_modules/underscore.string/dedent.js
ela-4.1.1 node_modules/underscore.string/dedent.js
ela-4.1.0 node_modules/underscore.string/dedent.js
ela-4.0.0 node_modules/underscore.string/dedent.js
ela-3.4.3 node_modules/underscore.string/dedent.js
ela-3.4.2 node_modules/underscore.string/dedent.js
ela-3.4.0 node_modules/underscore.string/dedent.js
ela-3.3.1 node_modules/underscore.string/dedent.js
ela-3.3.0 node_modules/underscore.string/dedent.js
ela-3.2.0 node_modules/underscore.string/dedent.js
ela-3.1.1 node_modules/underscore.string/dedent.js
ela-3.1.0 node_modules/underscore.string/dedent.js
ela-3.0.0 node_modules/underscore.string/dedent.js
ela-2.0.0 node_modules/underscore.string/dedent.js
ela-1.1.0 node_modules/underscore.string/dedent.js