Skip to content

Commit

Permalink
Use min-indent (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiebuilds authored and sindresorhus committed Nov 4, 2017
1 parent dbeb232 commit 089df03
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 5 additions & 5 deletions index.js
@@ -1,14 +1,14 @@
'use strict';
const minIndent = require('min-indent');

module.exports = str => {
const match = str.match(/^[ \t]*(?=\S)/gm);
const indent = minIndent(str);

if (!match) {
if (indent === 0) {
return str;
}

// TODO: Use spread operator when targeting Node.js 6
const indent = Math.min.apply(Math, match.map(x => x.length));
const re = new RegExp(`^[ \\t]{${indent}}`, 'gm');

return indent > 0 ? str.replace(re, '') : str;
return str.replace(re, '');
};
3 changes: 3 additions & 0 deletions package.json
Expand Up @@ -31,6 +31,9 @@
"string",
"str"
],
"dependencies": {
"min-indent": "^1.0.0"
},
"devDependencies": {
"ava": "*",
"xo": "*"
Expand Down

0 comments on commit 089df03

Please sign in to comment.