index.js 320 B

12345678910111213141516
  1. 'use strict';
  2. module.exports = function (str) {
  3. var match = str.match(/^[ \t]*(?=\S)/gm);
  4. if (!match) {
  5. return str;
  6. }
  7. var indent = Math.min.apply(Math, match.map(function (el) {
  8. return el.length;
  9. }));
  10. var re = new RegExp('^[ \\t]{' + indent + '}', 'gm');
  11. return indent > 0 ? str.replace(re, '') : str;
  12. };