1 stringify = require("json-stable-stringify")
2 uglify = require("jsonminify")
5 prettify = (editor, sorted) ->
6 wholeFile = editor.getGrammar().name == 'JSON'
9 text = editor.getText()
10 editor.setText(formatter.pretty(text, sorted))
12 text = editor.replaceSelectedText({}, (text) ->
13 formatter.pretty(text, sorted)
16 minify = (editor, sorted) ->
17 wholeFile = editor.getGrammar().name == 'JSON'
20 text = editor.getText()
21 editor.setText(formatter.minify(text))
23 text = editor.replaceSelectedText({}, (text) ->
24 formatter.minify(text);
27 formatter.pretty = (text, sorted) ->
28 editorSettings = atom.config.get('editor')
29 if editorSettings.softTabs?
30 space = Array(editorSettings.tabLength + 1).join(" ")
35 parsed = JSON.parse(text)
37 return stringify(parsed, { space: space })
39 return JSON.stringify(parsed, null, space)
43 formatter.minify = (text) ->
52 atom.commands.add 'atom-workspace',
53 'pretty-json:prettify': ->
54 editor = atom.workspace.getActiveTextEditor()
56 'pretty-json:sort-and-prettify': ->
57 editor = atom.workspace.getActiveTextEditor()
58 prettify(editor, true)
59 'pretty-json:minify': ->
60 editor = atom.workspace.getActiveTextEditor()