Last active
May 28, 2024 17:42
-
-
Save brentsimmons/7819109 to your computer and use it in GitHub Desktop.
This is a BBEdit text filter for indenting (and beautifying) JavaScript.
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
#!/usr/local/bin/node | |
// PBS 12/5/13 | |
// This is a BBEdit text filter for indenting (and beautifying) JavaScript. | |
// It goes in ~/Library/Application Support/BBEdit/Text Filters/ | |
// | |
// On my machine I assigned it a keyboard shortcut: cmd-' | |
// | |
// It requires the js-beautify Node module: https://github.com/einars/js-beautify | |
// | |
// The trick, in the script, was providing the full path to the globally-installed js-beautify module. | |
// | |
// I figured out how to write a BBEdit/Node text filter from the very nice example here: | |
// http://www.mtaa.net/mtaaRR/news/twhid/geek/use_node_js_with_bbedit_text_filters_feature.html | |
var jsbeautify = require('/usr/local/lib/node_modules/js-beautify').js_beautify; | |
process.stdin.resume(); | |
process.stdin.setEncoding('utf8'); | |
process.stdin.on('data', function(chunk) { | |
var s = jsbeautify(chunk, { | |
indent_size: 2, | |
brace_style: "end-expand" | |
}); | |
process.stdout.write(s); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is the code for the BASH script I now use: