summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/libnpx/node_modules/dotenv/lib/main.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/libnpx/node_modules/dotenv/lib/main.js')
-rw-r--r--deps/npm/node_modules/libnpx/node_modules/dotenv/lib/main.js39
1 files changed, 17 insertions, 22 deletions
diff --git a/deps/npm/node_modules/libnpx/node_modules/dotenv/lib/main.js b/deps/npm/node_modules/libnpx/node_modules/dotenv/lib/main.js
index 1f0df92719..eb96e7fd56 100644
--- a/deps/npm/node_modules/libnpx/node_modules/dotenv/lib/main.js
+++ b/deps/npm/node_modules/libnpx/node_modules/dotenv/lib/main.js
@@ -1,29 +1,28 @@
'use strict'
-const fs = require('fs')
-const path = require('path')
+var fs = require('fs')
/*
* Parses a string or buffer into an object
- * @param {(string|Buffer)} src - source to be parsed
- * @returns {Object} keys and values from src
+ * @param {String|Buffer} src - source to be parsed
+ * @returns {Object}
*/
function parse (src) {
- const obj = {}
+ var obj = {}
// convert Buffers before splitting into lines and processing
src.toString().split('\n').forEach(function (line) {
// matching "KEY' and 'VAL' in 'KEY=VAL'
- const keyValueArr = line.match(/^\s*([\w\.\-]+)\s*=\s*(.*)?\s*$/)
+ var keyValueArr = line.match(/^\s*([\w\.\-]+)\s*=\s*(.*)?\s*$/)
// matched?
if (keyValueArr != null) {
- const key = keyValueArr[1]
+ var key = keyValueArr[1]
// default undefined or missing values to empty string
- let value = keyValueArr[2] || ''
+ var value = keyValueArr[2] ? keyValueArr[2] : ''
// expand newlines in quoted values
- const len = value ? value.length : 0
+ var len = value ? value.length : 0
if (len > 0 && value.charAt(0) === '"' && value.charAt(len - 1) === '"') {
value = value.replace(/\\n/gm, '\n')
}
@@ -40,18 +39,16 @@ function parse (src) {
/*
* Main entry point into dotenv. Allows configuration before loading .env
- * @param {Object} options - options for parsing .env file
- * @param {string} [options.path=.env] - path to .env file
- * @param {string} [options.encoding=utf8] - encoding of .env file
- * @returns {Object} parsed object or error
+ * @param {Object} options - valid options: path ('.env'), encoding ('utf8')
+ * @returns {Boolean}
*/
function config (options) {
- let dotenvPath = path.resolve(process.cwd(), '.env')
- let encoding = 'utf8'
+ var path = '.env'
+ var encoding = 'utf8'
if (options) {
if (options.path) {
- dotenvPath = options.path
+ path = options.path
}
if (options.encoding) {
encoding = options.encoding
@@ -60,15 +57,13 @@ function config (options) {
try {
// specifying an encoding returns a string instead of a buffer
- const parsed = parse(fs.readFileSync(dotenvPath, { encoding }))
+ var parsedObj = parse(fs.readFileSync(path, { encoding: encoding }))
- Object.keys(parsed).forEach(function (key) {
- if (!process.env.hasOwnProperty(key)) {
- process.env[key] = parsed[key]
- }
+ Object.keys(parsedObj).forEach(function (key) {
+ process.env[key] = process.env[key] || parsedObj[key]
})
- return { parsed }
+ return { parsed: parsedObj }
} catch (e) {
return { error: e }
}