envfile
Version:
Parse and stringify the environment configuration files and format, also known as .env files and dotenv files
21 lines (20 loc) • 563 B
JavaScript
// builtin
import { argv, stdin, stdout } from 'process';
// local
import { parse, stringify } from './index.js';
// are we wanting to convert from json to env?
const jsonToEnv = argv.slice(1).join(' ').includes('json2env');
// get the data
let data = '';
stdin.on('readable', function () {
const chunk = stdin.read();
if (chunk)
data += chunk.toString();
});
// do the conversion
stdin.on('end', function () {
const result = jsonToEnv
? stringify(JSON.parse(data))
: JSON.stringify(parse(data));
stdout.write(result);
});