Pluvi.On Utils Package
to
Go Lang inspired async await wrapper for easy error handling
const { until } = require('@pluvion/utils').PromiseUtils;
const [result, error] = await until(Promise.resolve({key: 'value'}));
if(error) return console.error(`Error: ${error}`);
if(!result) return console.error(`Nothing here!`);
console.log(`Result: ${result.key}`);
getValue
Get environment variable value converted to native type or default value
const { getValue } = require('@pluvion/utils').StringUtils;
process.env.VAR_NUMERIC="10.2";
process.env.VAR_BOOLEAN="true";
process.env.VAR_STRING="my text";
const varStr = getValue(process.env.VAR_STRING, 'string', null);
console.log(`varStr: ${varStr}`);
const varUnd = getValue(process.env.UNDEFINED_VAR, 'string', null);
console.log(`varStr: ${varUnd}`);
const varNum = getValue(process.env.VAR_NUMERIC, 'number', null);
console.log(`varNum: ${varNum}`);
const varBol = getValue(process.env.VAR_BOOLEAN, 'boolean', null);
console.log(`varBol: ${varBol}`);
const varBolUnd = getValue(process.env.VAR_BOOLEAN_UNDEFINED, 'boolean', null);
console.log(`varBolUnd: ${varBolUnd}`);