You have to have NodeJS. If you don't have it, google it and make it happen.
Then you need to install prettier. It's NPM page is here.
To install it, type...
npm install prettier -g
This will install it in a command line utility.
In some file (I do a lot of this, so I created a Scripts folder and called the file, ~/Scripts/bin/js/runPrettier.js, you can do what works for you just remember that the bash file below has to point to the file), insert this:
#!/usr/local/bin/node
const prettier=require('prettier');
var inString='';
var writeStuff = function() {
var outString='';
outString=inString;
outString=outString.replace(/^[\s]$/gm, "/*linebreak*/"); //I like to retain linebreaks
outString=prettier.format(outString)
outString=outString.replace(/\/\*linebreak\*\//gm, ""); //you can remove these if you don't
process.stdout.write(outString);
};
//the rest ========================================================
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(data){
inString+=data;
});
process.stdin.on('end', writeStuff);
Then in a file in the bbedit directory (~/Library/Application Support/BBEdit/Text Filters)
Create a file (I called this 'runPrettier') containing this...#!/bin/bash
~/Scripts/bin/js/runPrettier.js
In the terminal make the bash script executable...
chmod +x ~/Library/Application Support/BBEdit/Text Filters/runPrettier
and, voila!, you have an operating formatter for Javascript.
I assigned mine to a command key so I can always make it pretty.