Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | 1x 1x 1x 5x 5x 40x 40x 40x 40x 24x 8x 16x 5x 85x 85x 5x 5x 80x 10x 10x 70x 5x 5x 65x 15x 15x 50x 10x 10x 40x |
import Debug from 'debug';
const debug = new Debug('dotenv-parse-variables');
const DEFAULT_OPTIONS = {
assignToProcessEnv: true,
overrideProcessEnv: false
};
export default (env, options) => {
const envOptions = Object.assign({}, DEFAULT_OPTIONS, options || {});
Object.keys(env).forEach(key => {
debug(`key "${key}" before type was ${typeof env[key]}`);
env[key] = parseKey(env[key], key);
debug(`key "${key}" after type was ${typeof env[key]}`);
if (envOptions.assignToProcessEnv === true) {
if (envOptions.overrideProcessEnv === true) {
process.env[key] = env[key] || process.env[key];
} else {
process.env[key] = process.env[key] || env[key];
}
}
});
return env;
};
function parseKey(value, key) {
debug(`parsing key ${key} with value ${value}`);
// if the value is wrapped in bacticks e.g. (`value`) then just return its value
if (value.toString().indexOf('`') === 0
&& value.toString().lastIndexOf('`') === value.toString().length - 1) {
debug(`key ${key} is wrapped in bacticks and will be ignored from parsing`);
return value.toString().substring(1, value.toString().length - 1);
}
// if the value ends in an asterisk then just return its value
if (value.toString().lastIndexOf('*') === value.toString().length - 1
&& value.toString().indexOf(',') === -1) {
debug(`key ${key} ended in * and will be ignored from parsing`);
return value.toString().substring(0, value.toString().length - 1);
}
// Boolean
if (value.toLowerCase() === 'true' || value.toLowerCase() === 'false') {
debug(`key ${key} parsed as a Boolean`);
return value === 'true';
}
// Number
if (!isNaN(value)) {
debug(`key ${key} parsed as a Number`);
return Number(value);
}
// Array
if (value.indexOf(',') !== -1) {
debug(`key ${key} parsed as an Array`);
return value.split(',').map(parseKey);
}
return value;
}
|