| Leo Repp | 58b9f11 | 2021-11-22 11:57:47 +0100 | [diff] [blame^] | 1 | 'use strict'; |
| 2 | module.exports = function (str) { | ||||
| 3 | var match = str.match(/^[ \t]*(?=\S)/gm); | ||||
| 4 | |||||
| 5 | if (!match) { | ||||
| 6 | return str; | ||||
| 7 | } | ||||
| 8 | |||||
| 9 | var indent = Math.min.apply(Math, match.map(function (el) { | ||||
| 10 | return el.length; | ||||
| 11 | })); | ||||
| 12 | |||||
| 13 | var re = new RegExp('^[ \\t]{' + indent + '}', 'gm'); | ||||
| 14 | |||||
| 15 | return indent > 0 ? str.replace(re, '') : str; | ||||
| 16 | }; | ||||