-
-
Save monkeym4ster/f586a1f3aa701bb7e5e8bc568ec313ec to your computer and use it in GitHub Desktop.
CoffeeScript beautify function
This file contains 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
beautify: (string, indent = 0) -> | |
switch ch = string[0] || '' | |
when '' then "" | |
when '{' or '[' then "#{ch}\n#{Array(++indent+1).join('\t')}#{@beautify(string[1..], indent)}" | |
when '}' or ']' then "\n#{Array(--indent+1).join('\t')}#{ch}#{@beautify(string[1..], indent)}" | |
when ',' then "#{ch}\n#{Array(indent+1).join('\t')}#{@beautify(string[1..], indent)}" | |
when ':' then " : #{@beautify(string[1..], indent)}" | |
else "#{ch}#{@beautify(string[1..], indent)}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment