nav tabs on admin dashboard
This commit is contained in:
85
node_modules/dotenv/lib/main.js
generated
vendored
85
node_modules/dotenv/lib/main.js
generated
vendored
@@ -1,28 +1,51 @@
|
||||
'use strict'
|
||||
/* @flow */
|
||||
/*::
|
||||
|
||||
var fs = require('fs')
|
||||
type DotenvParseOptions = {
|
||||
debug?: boolean
|
||||
}
|
||||
|
||||
// keys and values from src
|
||||
type DotenvParseOutput = { [string]: string }
|
||||
|
||||
type DotenvConfigOptions = {
|
||||
path?: string, // path to .env file
|
||||
encoding?: string, // encoding of .env file
|
||||
debug?: string // turn on logging for debugging purposes
|
||||
}
|
||||
|
||||
type DotenvConfigOutput = {
|
||||
parsed?: DotenvParseOutput,
|
||||
error?: Error
|
||||
}
|
||||
|
||||
/*
|
||||
* Parses a string or buffer into an object
|
||||
* @param {String|Buffer} src - source to be parsed
|
||||
* @returns {Object}
|
||||
*/
|
||||
function parse (src) {
|
||||
var obj = {}
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
function log (message /*: string */) {
|
||||
console.log(`[dotenv][DEBUG] ${message}`)
|
||||
}
|
||||
|
||||
// Parses src into an Object
|
||||
function parse (src /*: string | Buffer */, options /*: ?DotenvParseOptions */) /*: DotenvParseOutput */ {
|
||||
const debug = Boolean(options && options.debug)
|
||||
const obj = {}
|
||||
|
||||
// convert Buffers before splitting into lines and processing
|
||||
src.toString().split('\n').forEach(function (line) {
|
||||
src.toString().split('\n').forEach(function (line, idx) {
|
||||
// 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')
|
||||
}
|
||||
@@ -31,39 +54,45 @@ function parse (src) {
|
||||
value = value.replace(/(^['"]|['"]$)/g, '').trim()
|
||||
|
||||
obj[key] = value
|
||||
} else if (debug) {
|
||||
log(`did not match key and value when parsing line ${idx + 1}: ${line}`)
|
||||
}
|
||||
})
|
||||
|
||||
return obj
|
||||
}
|
||||
|
||||
/*
|
||||
* Main entry point into dotenv. Allows configuration before loading .env
|
||||
* @param {Object} options - valid options: path ('.env'), encoding ('utf8')
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
function config (options) {
|
||||
var path = '.env'
|
||||
var encoding = 'utf8'
|
||||
// Populates process.env from .env file
|
||||
function config (options /*: ?DotenvConfigOptions */) /*: DotenvConfigOutput */ {
|
||||
let dotenvPath = path.resolve(process.cwd(), '.env')
|
||||
let encoding /*: string */ = 'utf8'
|
||||
let debug = false
|
||||
|
||||
if (options) {
|
||||
if (options.path) {
|
||||
path = options.path
|
||||
if (options.path != null) {
|
||||
dotenvPath = options.path
|
||||
}
|
||||
if (options.encoding) {
|
||||
if (options.encoding != null) {
|
||||
encoding = options.encoding
|
||||
}
|
||||
if (options.debug != null) {
|
||||
debug = true
|
||||
}
|
||||
}
|
||||
|
||||
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 }), { debug })
|
||||
|
||||
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]
|
||||
} else if (debug) {
|
||||
log(`"${key}" is already defined in \`process.env\` and will not be overwritten`)
|
||||
}
|
||||
})
|
||||
|
||||
return { parsed: parsedObj }
|
||||
return { parsed }
|
||||
} catch (e) {
|
||||
return { error: e }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user