cleaner-node
Advanced tools
Comparing version 0.16.0 to 0.17.0
{ | ||
"name": "cleaner-node", | ||
"version": "0.16.0", | ||
"version": "0.17.0", | ||
"description": "Helpful utilities and scripts to make Node projects more legible and easier for the next developer to take over.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -60,1 +60,2 @@ # cleaner-node | ||
| 0.16.0 | 2021/08/29 | Add improved `objects.toDto`. | | ||
| 0.17.0 | 2021/09/15 | Add `express.getValue`. | |
@@ -0,1 +1,3 @@ | ||
const objects = require('./objects'); | ||
const asyncMiddleware = (fn) => { | ||
@@ -7,6 +9,30 @@ return (req, res, next) => { | ||
const getProperty = (obj, key, isCaseSensitive = false) => { | ||
if (!objects.isValid(obj)) { return undefined; } | ||
const keys = Object.keys(obj).filter(x => (x && | ||
((!isCaseSensitive && x.toLowerCase() === key.toLowerCase()) || | ||
(isCaseSensitive && x === key)))); | ||
return (keys.length === 0) | ||
? obj[keys[0]] | ||
: obj[key]; | ||
}; | ||
const getValueFromBody = (req, key, isCaseSensitive = false) => { | ||
return getProperty(req.body, key, isCaseSensitive); | ||
}; | ||
const getValueFromParams = (req, key, isCaseSensitive = false) => { | ||
return getProperty(req.body, key, isCaseSensitive); | ||
}; | ||
const getValue = (req, key, isCaseSensitive = false) => { | ||
return getValueFromBody(req, key, isCaseSensitive) || getValueFromParams(req, key, isCaseSensitive); | ||
}; | ||
module.exports = { | ||
asyncMiddleware, | ||
amw : asyncMiddleware, | ||
wrap : asyncMiddleware | ||
wrap : asyncMiddleware, | ||
getValue, | ||
getValueFromBody, | ||
getValueFromParams | ||
}; |
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
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
82114
2085
61