Codebase list node-strip-indent / 089df03
Use min-indent (#4) James Kyle authored 6 years ago Sindre Sorhus committed 6 years ago
2 changed file(s) with 8 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
00 'use strict';
1 const minIndent = require('min-indent');
2
13 module.exports = str => {
2 const match = str.match(/^[ \t]*(?=\S)/gm);
4 const indent = minIndent(str);
35
4 if (!match) {
6 if (indent === 0) {
57 return str;
68 }
79
8 // TODO: Use spread operator when targeting Node.js 6
9 const indent = Math.min.apply(Math, match.map(x => x.length));
1010 const re = new RegExp(`^[ \\t]{${indent}}`, 'gm');
1111
12 return indent > 0 ? str.replace(re, '') : str;
12 return str.replace(re, '');
1313 };
3030 "string",
3131 "str"
3232 ],
33 "dependencies": {
34 "min-indent": "^1.0.0"
35 },
3336 "devDependencies": {
3437 "ava": "*",
3538 "xo": "*"