Skip to content

Instantly share code, notes, and snippets.

@beginor
Created November 28, 2016 09:16
Show Gist options
  • Select an option

  • Save beginor/633be78cc4ab6630c7c37f30c3671f8b to your computer and use it in GitHub Desktop.

Select an option

Save beginor/633be78cc4ab6630c7c37f30c3671f8b to your computer and use it in GitHub Desktop.
parse and beautify javascript with uglify-js
import * as uglifyJs from 'uglify-js';
import * as path from 'path';
import * as fs from 'fs';
var p = path.resolve(__dirname, 'jsapi/esri/nls/zh-cn/jsapi.js');
console.log(p);
fs.readFile(p, { encoding: 'utf-8' }, (ex, data) => {
//console.log(data);
var result = uglifyJs.parse(data, {});
var js = result.print_to_string({
beautify: true,
quote_keys: false,
space_colon: true,
bracketize: true,
semicolons: true,
comments: true,
ascii_only: false,
width: 80
});
console.log(js);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment