Created
August 10, 2016 14:31
-
-
Save groner/049471edae56647e22a6101d8f667293 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function dedent(block) { | |
// Find the common leading space in a block of text, then remove it. Tabs are NOT handled. | |
//let spaces = Math.min.apply(null, block.match(/^ +(?=[^ ])/gm).map((ws) => ws.length)); | |
//let spaces = block.match(/^ +(?=[^ ])/gm).map((ws) => ws.length).reduce(Math.min); | |
let spaces = block.match(/^ +(?=[^ ])/gm).reduce((a,b) => a<b?a:b).length; | |
return block.replace(new RegExp(`^ {1,${spaces}}`, 'gm'), ''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment