forked from mihai-vlc/sublime-jsfmt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsfmt.js
34 lines (26 loc) · 740 Bytes
/
jsfmt.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict';
var stdin = require('get-stdin');
var jsfmt = require('jsfmt');
var extend = require('extend');
stdin(function(data) {
var scope = process.argv[3];
var conf = jsfmt.getConfig();
var optsJSON = extend({}, conf, JSON.parse(process.argv[4]));
var opts = conf;
var js;
// if we don't have a jsfmtrc file
// use the settings from .sublime-settings
if (! opts.config) {
opts = extend({}, opts, JSON.parse(process.argv[2]));
}
try {
if (scope && scope == 'json') {
js = jsfmt.formatJSON(data, optsJSON);
} else {
js = jsfmt.format(data, opts);
}
process.stdout.write(js);
} catch (err) {
throw err;
}
});