Check out this post on using JSBeautify with Textmate. It has some good instructions on how to install it on your system. On Mac OS X, I used:
cd /tmp
git clone https://github.com/einars/js-beautify.git
cd js-beautify/python
python setup.py install
Then you can simply use js-beautify /path/to/filename.js to have it run.
Check out this post on using JSBeautify with Textmate. It has some good instructions on how to install it on your system. On Mac OS X, I used:
cd /tmp
git clone https://github.com/einars/js-beautify.git
cd js-beautify/python
python setup.py install
Then you can simply use js-beautify /path/to/filename.js to have it run.
Your examples are for the usage as a library not command line. If you are trying to create a script yourself that can take arguments and pass it on to JSBeautifier you should take a look at the argparse module. It has some good examples to get you going. Example from docs:
>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('infile', nargs='?', type=argparse.FileType('r'),
... default=sys.stdin)
>>> parser.add_argument('outfile', nargs='?', type=argparse.FileType('w'),
... default=sys.stdout)
>>> parser.parse_args(['input.txt', 'output.txt'])
Namespace(infile=<_io.TextIOWrapper name='input.txt' encoding='UTF-8'>,
outfile=<_io.TextIOWrapper name='output.txt' encoding='UTF-8'>)
>>> parser.parse_args([])
Namespace(infile=<_io.TextIOWrapper name='<stdin>' encoding='UTF-8'>,
outfile=<_io.TextIOWrapper name='<stdout>' encoding='UTF-8'>)
EDIT: you can also use getopt that is used by the jsbeautifier.py itself. If you just want to use jsbeautifier.py as a command line tool, read the usage function from the source code.
» pip install jsbeautifier
» npm install js-beautify