Skip to content

Commit

Permalink
Merge 0a01850 into 472db2e
Browse files Browse the repository at this point in the history
  • Loading branch information
zenflow committed Feb 26, 2018
2 parents 472db2e + 0a01850 commit 7a5e352
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ node_js:
- 6
- 8
- 9

script:
- npm run lint
- npm run test
- npm run coverage
17 changes: 14 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
version: 4.0.{build}
build:
verbosity: minimal
version: "{build}"
build: off
environment:
matrix:
- nodejs_version: "4"
- nodejs_version: "6"
- nodejs_version: "8"
- nodejs_version: "9"
install:
- ps: Install-Product node $env:nodejs_version
- npm install
test_script:
- npm run lint
- npm run test
12 changes: 5 additions & 7 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
const fs = require('fs')
const path = require('path')

const dotenv = module.exports = {}

/*
* 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) {
dotenv.parse = function parse (src) {
const obj = {}

// convert Buffers before splitting into lines and processing
Expand Down Expand Up @@ -45,7 +47,7 @@ function parse (src) {
* @param {string} [options.encoding=utf8] - encoding of .env file
* @returns {Object} parsed object or error
*/
function config (options) {
dotenv.config = dotenv.load = function config (options) {
let dotenvPath = path.resolve(process.cwd(), '.env')
let encoding = 'utf8'

Expand All @@ -60,7 +62,7 @@ function config (options) {

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

Object.keys(parsed).forEach(function (key) {
if (!process.env.hasOwnProperty(key)) {
Expand All @@ -73,7 +75,3 @@ function config (options) {
return { error: e }
}
}

module.exports.config = config
module.exports.load = config
module.exports.parse = parse
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"description": "Loads environment variables from .env file",
"main": "lib/main.js",
"scripts": {
"pretest": "npm run lint",
"test": "lab test/* -r lcov | coveralls",
"test": "lab",
"lint": "standard",
"postlint": "npm run lint-md",
"lint-md": "standard-markdown"
"lint-md": "standard-markdown",
"coverage": "lab -r lcov | coveralls"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion test/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('config', function () {
describe('preload', function () {
it('loads .env', function (done) {
cp.exec(
nodeBinary + ' -r ../config -e "console.log(process.env.BASIC)" dotenv_config_path=./test/.env',
'"' + nodeBinary + '" -r ../config -e "console.log(process.env.BASIC)" dotenv_config_path=./test/.env',
function (err, stdout, stderr) {
if (err) {
return done(err)
Expand Down
2 changes: 1 addition & 1 deletion test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('dotenv', function () {
// 'val' returned as value in `beforeEach`. should keep this ''
dotenv.config()

process.env.test.should.eql('')
Boolean(process.env.test).should.eql(false)
done()
})

Expand Down

0 comments on commit 7a5e352

Please sign in to comment.