Created
October 7, 2023 14:16
-
-
Save cristobal-io/bb6c264fe139c74de06d827cfc718b94 to your computer and use it in GitHub Desktop.
convert JSON to .env format
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
const { execSync } = require('child_process'); | |
function jsonToEnv(json) { | |
const data = JSON.parse(json); | |
let envData = ''; | |
for (const [key, value] of Object.entries(data)) { | |
envData += `${key}=${value}\n`; | |
} | |
return envData; | |
} | |
function main() { | |
// Get JSON from clipboard | |
const jsonFromClipboard = execSync('pbpaste', { encoding: 'utf8' }); | |
const envData = jsonToEnv(jsonFromClipboard); | |
// Set .env format string to clipboard | |
execSync('pbcopy', { input: envData }); | |
console.log('Converted JSON to .env format and copied to clipboard!'); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment