@adobe/aio-lib-core-config
Advanced tools
Comparing version 2.0.0 to 2.0.1
{ | ||
"name": "@adobe/aio-lib-core-config", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Adobe I/O Configuration Module", | ||
@@ -5,0 +5,0 @@ "main": "./src/index.js", |
@@ -18,3 +18,3 @@ <!-- | ||
[![Downloads/week](https://img.shields.io/npm/dw/@adobe/aio-lib-core-config.svg)](https://npmjs.org/package/@adobe/aio-lib-core-config) | ||
[![Build Status](https://travis-ci.com/adobe/aio-lib-core-config.svg?branch=master)](https://travis-ci.com/adobe/aio-lib-core-config) | ||
![Node.js CI](https://github.com/adobe/aio-lib-core-config/workflows/Node.js%20CI/badge.svg) | ||
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) | ||
@@ -54,3 +54,3 @@ [![Codecov Coverage](https://img.shields.io/codecov/c/github/adobe/aio-lib-core-config/master.svg?style=flat-square)](https://codecov.io/gh/adobe/aio-lib-core-config/) | ||
## Peristent File Locations | ||
## Persistent File Locations | ||
@@ -57,0 +57,0 @@ ### User Configuration |
@@ -26,2 +26,3 @@ /* | ||
const parse = (file) => { | ||
checkForDuplicates(file) | ||
const buf = Buffer.from(fs.readFileSync(file, 'utf-8')) | ||
@@ -32,2 +33,39 @@ return dotenv.parse(buf) // will return an object | ||
/** | ||
* parse file for environmental variables and log debug message for duplicate definitions | ||
* | ||
* @param {String} file filepath to parse | ||
*/ | ||
const checkForDuplicates = (file) => { | ||
try { | ||
const NEWLINES_MATCH = /\n|\r|\r\n/ | ||
const RE_INI_KEY_VAL = /^\s*([\w.-]+)\s*=\s*(.*)?\s*$/ | ||
const buf = Buffer.from(fs.readFileSync(file, 'utf-8')) | ||
const obj = {} | ||
const dupKeys = [] | ||
buf.toString().split(NEWLINES_MATCH).forEach(function(line, idx) { | ||
const keyValueArr = line.match(RE_INI_KEY_VAL) | ||
if (keyValueArr != null) { | ||
const key = keyValueArr[1] | ||
if (obj[key]) { | ||
dupKeys.push(`${key}`) | ||
} else { | ||
obj[key] = 'dummy' | ||
} | ||
} | ||
}) | ||
if (dupKeys.length > 0) { | ||
let debugMsg = 'duplicate declaration of environment variable(s)' | ||
dupKeys.forEach((key) => { | ||
debugMsg = debugMsg + ` ${key},` | ||
}) | ||
debugMsg = debugMsg.slice(0, -1) | ||
debugMsg = debugMsg + ` in ${file}` | ||
debug(debugMsg) | ||
} | ||
} catch (err) { | ||
// Ignore | ||
} | ||
} | ||
/** | ||
* returns all keys in o1 that arent in o2 | ||
@@ -34,0 +72,0 @@ * |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
33613
582