Turns indentation into {curly brackets} Great for a yml to json converter or something. Credit to @maettig for writing all* the code.
Turn this:
if(3==3)
alert("obviously!")
alert("lol!")
Into:
if(3==3){
alert("obviously!")
alert("lol!")
}
jsperf showing the different methods:
http://jsperf.com/blockifyindents
*almost
Here is an other idea I had. I'm not sure if it works in all cases. Maybe we need to replace the first
.*
with[^\t]*
. Do you have more test cases?