Created
November 13, 2017 01:45
-
-
Save symmetriq/70aacd65a054e69fa176c5b4b108f62f to your computer and use it in GitHub Desktop.
BBEdit: JSON to JS
This file contains 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 JS | |
//------------------------------------------------------------------------------- | |
// Jason Sims <[email protected]> | |
//------------------------------------------------------------------------------- | |
// | |
// Transforms a JSON object into JavaScript | |
// | |
// 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 JS" 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); | |
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