Socket
Socket
Sign inDemoInstall

dotenv

Package Overview
Dependencies
Maintainers
4
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dotenv - npm Package Compare versions

Comparing version 6.0.0 to 6.1.0

.flowconfig

18

CHANGELOG.md

@@ -7,2 +7,14 @@ # Change Log

## [6.1.0] - 2018-10-08
### Added
- `debug` option for `config` and `parse` methods will turn on logging
## [6.0.0] - 2018-06-02
### Changed
- *Breaking:* drop support for Node v4 ([#304](https://github.com/motdotla/dotenv/pull/304))
## [5.0.0] - 2018-01-29

@@ -16,3 +28,3 @@

### Changed
### Changed

@@ -91,3 +103,5 @@ - *Breaking*: default `path` is now `path.resolve(process.cwd(), '.env')`

[Unreleased]: https://github.com/motdotla/dotenv/compare/v5.0.0...HEAD
[Unreleased]: https://github.com/motdotla/dotenv/compare/v6.1.0...HEAD
[6.1.0]: https://github.com/motdotla/dotenv/compare/v6.0.0...v6.1.0
[6.0.0]: https://github.com/motdotla/dotenv/compare/v5.0.0...v6.0.0
[5.0.0]: https://github.com/motdotla/dotenv/compare/v4.0.0...v5.0.0

@@ -94,0 +108,0 @@ [4.0.0]: https://github.com/motdotla/dotenv/compare/v3.0.0...v4.0.0

@@ -0,1 +1,3 @@

/* @flow */
(function () {

@@ -2,0 +4,0 @@ require('./lib/main').config(

6

lib/cli-options.js

@@ -1,4 +0,6 @@

const re = /^dotenv_config_(.+)=(.+)/
/* @flow */
module.exports = function optionMatcher (args) {
const re = /^dotenv_config_(encoding|path|debug)=(.+)$/
module.exports = function optionMatcher (args /*: Array<string> */) {
return args.reduce(function (acc, cur) {

@@ -5,0 +7,0 @@ const matches = cur.match(re)

@@ -0,14 +1,38 @@

/* @flow */
/*::
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
}
*/
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} keys and values from src
*/
function parse (src) {
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'

@@ -33,2 +57,4 @@ const keyValueArr = line.match(/^\s*([\w.-]+)\s*=\s*(.*)?\s*$/)

obj[key] = value
} else if (debug) {
log(`did not match key and value when parsing line ${idx + 1}: ${line}`)
}

@@ -40,20 +66,18 @@ })

/*
* 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
*/
function config (options) {
// Populates process.env from .env file
function config (options /*: ?DotenvConfigOptions */) /*: DotenvConfigOutput */ {
let dotenvPath = path.resolve(process.cwd(), '.env')
let encoding = 'utf8'
let encoding /*: string */ = 'utf8'
let debug = false
if (options) {
if (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
}
}

@@ -63,3 +87,3 @@

// specifying an encoding returns a string instead of a buffer
const parsed = parse(fs.readFileSync(dotenvPath, { encoding }))
const parsed = parse(fs.readFileSync(dotenvPath, { encoding }), { debug })

@@ -69,2 +93,4 @@ Object.keys(parsed).forEach(function (key) {

process.env[key] = parsed[key]
} else if (debug) {
log(`"${key}" is already defined in \`process.env\` and will not be overwritten`)
}

@@ -71,0 +97,0 @@ })

{
"name": "dotenv",
"version": "6.0.0",
"version": "6.1.0",
"description": "Loads environment variables from .env file",
"main": "lib/main.js",
"scripts": {
"flow": "flow",
"pretest": "npm run lint",

@@ -27,9 +28,9 @@ "test": "tap tests/*.js --100",

"readmeFilename": "README.md",
"author": "scottmotte",
"license": "BSD-2-Clause",
"devDependencies": {
"sinon": "^5.0.2",
"standard": "^11.0.1",
"standard-markdown": "^4.0.2",
"tap": "^11.1.4"
"flow-bin": "^0.82.0",
"sinon": "^6.3.5",
"standard": "^12.0.1",
"standard-markdown": "^5.0.1",
"tap": "^12.0.1"
},

@@ -39,3 +40,8 @@ "dependencies": {},

"node": ">=6"
},
"standard": {
"ignore": [
"flow-typed/"
]
}
}

@@ -74,3 +74,3 @@ # dotenv

[`process.env`](https://nodejs.org/docs/latest/api/process.html#process_process_env),
and return an Object with a `parsed` key containing the loaded content or an `error` key if it failed.
and return an Object with a `parsed` key containing the loaded content or an `error` key if it failed.

@@ -95,7 +95,7 @@ ```js

You can specify a custom path if your file containing environment variables is
You may specify a custom path if your file containing environment variables is
named or located differently.
```js
require('dotenv').config({path: '/full/custom/path/to/your/env/vars'})
require('dotenv').config({ path: '/full/custom/path/to/your/env/vars' })
```

@@ -111,5 +111,15 @@

```js
require('dotenv').config({encoding: 'base64'})
require('dotenv').config({ encoding: 'base64' })
```
#### Debug
Default: `false`
You may turn on logging to help debug why certain keys or values are not being set as you expect.
```js
require('dotenv').config({ debug: process.env.DEBUG })
```
## Parse

@@ -128,2 +138,18 @@

### Options
#### Debug
Default: `false`
You may turn on logging to help debug why certain keys or values are not being set as you expect.
```js
const dotenv = require('dotenv')
const buf = Buffer.from('hello world')
const opt = { debug: true }
const config = dotenv.parse(buf, opt)
// expect a debug message because the buffer is not in KEY=VAL form
```
### Rules

@@ -266,1 +292,2 @@

* [dotenv-webpack](https://github.com/mrsteele/dotenv-webpack)
* [env-path](https://github.com/benrei/env-path)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc