Created
November 13, 2017 01:46
-
-
Save symmetriq/6b52e484da7cc26375c249ed7463b4aa to your computer and use it in GitHub Desktop.
BBEdit: JSON to CS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
//------------------------------------------------------------------------------- | |
// JSON to CS | |
//------------------------------------------------------------------------------- | |
// Jason Sims <[email protected]> | |
//------------------------------------------------------------------------------- | |
// | |
// Transforms a JSON object into CoffeeScript | |
// | |
// The CoffeeScript version omits all commas that occur at the end of a line | |
// | |
// Based on json-to-js: | |
// https://github.com/Dinoshauer/json-to-js | |
// | |
//------------------------------------------------------------------------------- | |
// | |
// Installation in BBEdit: | |
// | |
// 1. Place this file in your "Text Filters" directory: | |
// ~/Library/Application Support/BBEdit/Text Filters/ | |
// or | |
// ~/Dropbox/Application Support/BBEdit/Text Filters/ | |
// | |
// 2. Install javascript-stringify: | |
// npm i -g javascript-stringify | |
// | |
// 3. Assign a keyboard shortcut to "JSON to CS" in: | |
// BBEdit → Preferences → Menus & Shortcuts → Text → Apply Text Filter | |
// | |
//------------------------------------------------------------------------------- | |
// More scripts & snippets here: | |
// https://gist.github.com/symmetriq | |
//------------------------------------------------------------------------------- | |
var jsStringify = require('javascript-stringify') | |
, data = '' | |
, stdin = process.openStdin(); | |
stdin.on('data', function (chunk) { | |
data += chunk; | |
}); | |
stdin.on('end', function () { | |
var text = jsStringify(JSON.parse(data), null, 2); | |
text = text.replace(/,\n/g, '\n') | |
process.stdout.write(text); | |
process.exit(0); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment