mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2024-12-15 08:56:21 +00:00
14 lines
385 B
JavaScript
14 lines
385 B
JavaScript
|
module.exports = {
|
||
|
stripIndents (string) {
|
||
|
if (!string) return
|
||
|
const result = string.replace(/^[^\S\n]+/gm, '')
|
||
|
const match = result.match(/^[^\S\n]*(?=\S)/gm)
|
||
|
const indent = match && Math.min(...match.map(el => el.length))
|
||
|
if (indent) {
|
||
|
const regexp = new RegExp(`^.{${indent}}`, 'gm')
|
||
|
return result.replace(regexp, '')
|
||
|
}
|
||
|
return result
|
||
|
}
|
||
|
}
|