Skip to content

Commit

Permalink
fix: update dependencies (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
shazron authored Apr 13, 2023
1 parent 7b6abe6 commit fe94de6
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 71 deletions.
21 changes: 0 additions & 21 deletions .eslintrc.js

This file was deleted.

6 changes: 6 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"globals": {
"fixtureFile": true
},
"extends": "@adobe/eslint-config-aio-lib-config"
}
16 changes: 10 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,22 @@
"js-yaml": "^3.13.0"
},
"devDependencies": {
"@adobe/eslint-config-aio-lib-config": "^2.0.0",
"babel-runtime": "^6.26.0",
"eslint": "^8.38.0",
"eslint-config-standard": "^14.1.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jest": "23.13.2",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-promise": "^4.0.1",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jest": "^23.20.0",
"eslint-plugin-jsdoc": "^37.9.7",
"eslint-plugin-n": "^15.7.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-standard": "^4.0.0",
"jest": "^29.5.0",
"jest-plugin-fs": "^2.9.0",
"jsdoc-to-markdown": "^5.0.3",
"mock-stdin": "^1.0.0",
"tsd-jsdoc": "^2.4.0"
"tsd-jsdoc": "^2.4.0",
"typescript": "^5.0.4"
}
}
10 changes: 6 additions & 4 deletions src/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ const { merge, loadFile, saveFile, getValue, setValue } = require('./util')
/**
* read a file and log exceptions to debug
*
* @param {String} file
* @param {string} file
* @param {Function} debugFn
* @returns {object}
* @private
*/
const readFile = (file) => {
debug(`reading config: ${file}`)
Expand All @@ -35,7 +37,7 @@ const readFile = (file) => {
}

class Config {
reload() {
reload () {
dotenv(true)
// get the env var and use it as the config root key
// this could be aio or wxp or whatever
Expand Down Expand Up @@ -74,7 +76,7 @@ class Config {
return this
}

get(key = '', source) {
get (key = '', source) {
this.values || this.reload()
let vals = this.values

Expand All @@ -87,7 +89,7 @@ class Config {
return JSON.parse(JSON.stringify(value))
}

set(key, value, local = false) {
set (key, value, local = false) {
this.values || this.reload()

const config = (local) ? this.local : this.global
Expand Down
17 changes: 9 additions & 8 deletions src/dotenv.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const dotenv = require('dotenv')
/**
* parse file for environmental variables
*
* @param {String} file filepath to parse
* @param {string} file filepath to parse
* @private
*/
const parse = (file) => {
checkForDuplicates(file)
Expand All @@ -31,7 +32,7 @@ const parse = (file) => {
/**
* parse file for environmental variables and log debug message for duplicate definitions
*
* @param {String} file filepath to parse
* @param {string} file filepath to parse
*/
const checkForDuplicates = (file) => {
try {
Expand All @@ -40,7 +41,7 @@ const checkForDuplicates = (file) => {
const buf = Buffer.from(fs.readFileSync(file, 'utf-8'))
const obj = {}
const dupKeys = []
buf.toString().split(NEWLINES_MATCH).forEach(function(line, idx) {
buf.toString().split(NEWLINES_MATCH).forEach(function (line, idx) {
const keyValueArr = line.match(RE_INI_KEY_VAL)
if (keyValueArr != null) {
const key = keyValueArr[1]
Expand Down Expand Up @@ -68,10 +69,10 @@ const checkForDuplicates = (file) => {
/**
* returns all keys in o1 that arent in o2
*
* @param {Object} o1
* @param {Object} o2
*
* @return {Array} array of keys
* @param {object} o1
* @param {object} o2
* @returns {Array} array of keys
* @private
*/
const diff = (o1, o2) => Object.keys(o1).filter(k => !(k in o2))

Expand All @@ -88,7 +89,7 @@ const clear = () => {
}
}

module.exports = function(force = false) {
module.exports = function (force = false) {
const file = path.join(process.cwd(), '.env')
if (force || global[envFile] !== file) {
try {
Expand Down
21 changes: 13 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ class ConfigAPI {
*
* @param {string} [key=''] the key to get the value from
* @param {string} [source] 'global', 'local', or 'env'. Defaults to searching the consolidated config.
* @returns {string|object} the config value
*/
get(key, source) {
get (key, source) {
return config.get(key, source)
}

Expand All @@ -36,8 +37,9 @@ class ConfigAPI {
* @param {string} key the key to set the value to
* @param {string} value the value to save for the key
* @param {boolean} [local=false] Set to true to save the value in the local config. Defaults to false (save to global config).
* @returns {object} the Config object itself
*/
set(key, value, local) {
set (key, value, local) {
return config.set(key, value, local) && this
}

Expand All @@ -46,35 +48,38 @@ class ConfigAPI {
*
* @param {string} key the key to delete the value from
* @param {boolean} [local=false] Set to true to delete the value in the local config. Defaults to false (save to global config).
* @returns {object} the Config object itself
*/
delete(key, local) {
delete (key, local) {
return config.set(key, null, local) && this
}

/**
* Reload the Config from all the config file(s)
*
* @returns {object} the Config object itself, if reload was successful
*/
reload() {
reload () {
return config.reload() && this
}

/**
* Pipe data from stdin.
*
* @function
* @return {Promise<string>}
* @returns {Promise<string>} tje pipe
*/
get getPipedData() {
get getPipedData () {
return pipe
}

/**
* Hoists variables in the ./.env file to process.env
*
* @function
* @param {Object} the dotenv object
* @returns {object} the dotenv object
*/
get dotenv() {
get dotenv () {
return dotenv
}
}
Expand Down
52 changes: 28 additions & 24 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const deepmerge = require('deepmerge')
/**
* Support for mkdir -p.
*
* @param {String} dir the folder to create
* @param {string} dir the folder to create
*/
const mkdirp = dir => {
dir = dir || ''
Expand All @@ -33,18 +33,18 @@ const mkdirp = dir => {
/**
* Get property from object with case insensitivity.
*
* @param {Object} obj
* @param {String} key
* @param {object} obj
* @param {string} key
* @private
*/
const getProp = (obj, key) => obj[Object.keys(obj).find(k => k.toLowerCase() === key.toLowerCase())]

/**
* Get a value in an object by dot notation.
*
* @param {String} key
* @param {Object} obj
*
* @return {Object}
* @param {object} obj the object to get the value for the key from
* @param {string} key the key
* @returns {object} the value
*/
const getValue = (obj, key) => {
const keys = (key || '').toString().split('.')
Expand All @@ -54,11 +54,10 @@ const getValue = (obj, key) => {
/**
* Set a value by dot notation.
*
* @param {String} key
* @param {String} value
* @param {Object} [obj]
*
* @return {Object}
* @param {string} key the key
* @param {string} value the value to set
* @param {object} [obj] the object to set the value for the key to
* @returns {object} the transformed object
*/
const setValue = (key, value, obj) => {
const parts = (key || '').split('.').filter(o => o.trim())
Expand All @@ -79,8 +78,7 @@ const setValue = (key, value, obj) => {
* Deep merge a collection of objs returning a new object.
*
* @param {Array} objs array of objects
*
* @return {Object}
* @returns {object} the merged object
*/
const merge = (...objs) => {
// array merge strategy (replace)
Expand All @@ -94,9 +92,8 @@ const merge = (...objs) => {
/**
* Remove empty leaves from an object.
*
* @param {Object} obj
*
* @return {Object}
* @param {object} obj the object to shake
* @returns {object} the object with empty leaves removed
*/
const shake = obj => {
const shakeObject = o => {
Expand All @@ -119,9 +116,8 @@ const shake = obj => {
/**
* Deserialise from a file.
*
* @param {String} file
*
* @return {Object}
* @param {string} file the file to load
* @returns {object} object containing the file contents and format
*/
const loadFile = (file) => {
const contents = fs.readFileSync(file, 'utf-8').trim()
Expand All @@ -147,9 +143,10 @@ const loadFile = (file) => {
/**
* yaml serialise an object to a file.
*
* @param {String} file
* @param {Object} obj
* @param {String} format
* @param {string} file the file to save to
* @param {object} obj the object to save
* @param {string} format the format of the file to save
* @returns {object} true if the file was written successfully
*/
const saveFile = (file, obj, format) => {
obj = obj || {}
Expand All @@ -170,4 +167,11 @@ const saveFile = (file, obj, format) => {
return true
}

module.exports = { mkdirp, getValue, setValue, merge, loadFile, saveFile }
module.exports = {
mkdirp,
getValue,
setValue,
merge,
loadFile,
saveFile
}

0 comments on commit fe94de6

Please sign in to comment.