I’ve been writing some JS code in Drafts, and occasionally copying/pasting back and forth to web-based formatters. I decided to make this action using the code from JS Beautify.
https://actions.getdrafts.com/a/1L6
Just call it from a draft in JavaScript mode, and it will reformat according to the options in the script:
opts = {
"indent_size": 2,
"indent_char": " ",
"indent_with_tabs": false,
"eol": "\n",
"end_with_newline": false,
"indent_level": 0
"preserve_newlines": true,
"max_preserve_newlines": 10,
"space_in_paren": false,
"space_in_empty_paren": false,
"jslint_happy": false,
"space_after_anon_function": false,
"brace_style": "collapse",
"unindent_chained_methods": false,
"break_chained_methods": false,
"keep_array_indentation": false,
"unescape_strings": false,
"wrap_line_length": 0,
"e4x": false,
"comma_first": false,
"operator_position": "before-newline",
"eval_code": false,
"space_before_conditional": true
};
There may be better ways to do this, but it seems to work pretty well. I minified the code to cut the size in half and make it a little easier on Drafts. I hope it’s useful to someone else!
Nick