aboutsummaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/libnpx/node_modules/dotenv/lib/main.js
diff options
context:
space:
mode:
authorFallenRiteMonk <fallenritemonk@gmail.com>2018-04-05 11:52:34 -0400
committerMyles Borins <mylesborins@google.com>2018-04-05 16:01:07 -0400
commit25a816dcda7b1db0929501acfe13f2fe5119759b (patch)
treed3df4377a11dfb643b5976d2048d9bb4ee527903 /deps/npm/node_modules/libnpx/node_modules/dotenv/lib/main.js
parentb29c36b80746733994257b7380245102bc3c4cd6 (diff)
downloadandroid-node-v8-25a816dcda7b1db0929501acfe13f2fe5119759b.tar.gz
android-node-v8-25a816dcda7b1db0929501acfe13f2fe5119759b.tar.bz2
android-node-v8-25a816dcda7b1db0929501acfe13f2fe5119759b.zip
deps: upgrade npm to 5.8.0
PR-URL: https://github.com/nodejs/node/pull/19560 Fixes: https://github.com/nodejs/node/issues/19271 Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com>
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, 22 insertions, 17 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 eb96e7fd56..1f0df92719 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,28 +1,29 @@
'use strict'
-var fs = require('fs')
+const fs = require('fs')
+const path = require('path')
/*
* Parses a string or buffer into an object
- * @param {String|Buffer} src - source to be parsed
- * @returns {Object}
+ * @param {(string|Buffer)} src - source to be parsed
+ * @returns {Object} keys and values from src
*/
function parse (src) {
- var obj = {}
+ const obj = {}
// convert Buffers before splitting into lines and processing
src.toString().split('\n').forEach(function (line) {
// matching "KEY' and 'VAL' in 'KEY=VAL'
- var keyValueArr = line.match(/^\s*([\w\.\-]+)\s*=\s*(.*)?\s*$/)
+ const keyValueArr = line.match(/^\s*([\w\.\-]+)\s*=\s*(.*)?\s*$/)
// matched?
if (keyValueArr != null) {
- var key = keyValueArr[1]
+ const key = keyValueArr[1]
// default undefined or missing values to empty string
- var value = keyValueArr[2] ? keyValueArr[2] : ''
+ let value = keyValueArr[2] || ''
// expand newlines in quoted values
- var len = value ? value.length : 0
+ const len = value ? value.length : 0
if (len > 0 && value.charAt(0) === '"' && value.charAt(len - 1) === '"') {
value = value.replace(/\\n/gm, '\n')
}
@@ -39,16 +40,18 @@ function parse (src) {
/*
* Main entry point into dotenv. Allows configuration before loading .env
- * @param {Object} options - valid options: path ('.env'), encoding ('utf8')
- * @returns {Boolean}
+ * @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
*/
function config (options) {
- var path = '.env'
- var encoding = 'utf8'
+ let dotenvPath = path.resolve(process.cwd(), '.env')
+ let encoding = 'utf8'
if (options) {
if (options.path) {
- path = options.path
+ dotenvPath = options.path
}
if (options.encoding) {
encoding = options.encoding
@@ -57,13 +60,15 @@ function config (options) {
try {
// specifying an encoding returns a string instead of a buffer
- var parsedObj = parse(fs.readFileSync(path, { encoding: encoding }))
+ const parsed = parse(fs.readFileSync(dotenvPath, { encoding }))
- Object.keys(parsedObj).forEach(function (key) {
- process.env[key] = process.env[key] || parsedObj[key]
+ Object.keys(parsed).forEach(function (key) {
+ if (!process.env.hasOwnProperty(key)) {
+ process.env[key] = parsed[key]
+ }
})
- return { parsed: parsedObj }
+ return { parsed }
} catch (e) {
return { error: e }
}