oneday-core
Advanced tools
Comparing version 1.0.1 to 1.0.2
41
index.js
@@ -118,9 +118,32 @@ 'use strict'; | ||
function hasProperties(obj, props) { | ||
var missingProps = []; | ||
var objKeys = Object.keys(obj); | ||
const missingProps = []; | ||
if (!isArray(props) || !isObject(obj)) { | ||
return { | ||
status: false, | ||
props: props | ||
}; | ||
} | ||
for (const each in props) { | ||
if (objKeys.indexOf(props[each]) < 0) { | ||
missingProps.push(props[each]); | ||
const property = props[each]; | ||
let splitProperty = []; | ||
if (property.toString().indexOf('.') > 0) { | ||
splitProperty = property.split('.'); | ||
} else { | ||
splitProperty = property; | ||
} | ||
let currentObj = obj; | ||
for (const sEach in splitProperty) { | ||
const currentProp = splitProperty[sEach]; | ||
if (Object.keys(currentObj).indexOf(currentProp) > -1) { | ||
currentObj = currentObj[currentProp]; | ||
} else { | ||
missingProps.push(property); | ||
break; | ||
} | ||
} | ||
} | ||
@@ -140,3 +163,13 @@ if (missingProps.length !== 0) { | ||
function isArray(a) { | ||
return (!!a) && (a.constructor === Array); | ||
} | ||
function isObject(a) { | ||
return (!!a) && (a.constructor === Object); | ||
} | ||
module.exports.hasProperties = hasProperties; | ||
module.exports.isArray = isArray; | ||
module.exports.isObject = isObject; | ||
module.exports.postToDb = postToDb; | ||
@@ -143,0 +176,0 @@ module.exports.saveEvent = saveEvent; |
{ | ||
"name": "oneday-core", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Basic AWS util functions to ease development.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "mocha" | ||
}, | ||
@@ -13,4 +13,8 @@ "license": "ISC", | ||
"aws-sdk": "^2.493.0", | ||
"chai": "^4.2.0", | ||
"uuid": "^3.3.2" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^6.1.4" | ||
} | ||
} |
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
9275
4
244
1
3
1
+ Addedchai@^4.2.0
+ Addedassertion-error@1.1.0(transitive)
+ Addedchai@4.5.0(transitive)
+ Addedcheck-error@1.0.3(transitive)
+ Addeddeep-eql@4.1.4(transitive)
+ Addedget-func-name@2.0.2(transitive)
+ Addedloupe@2.3.7(transitive)
+ Addedpathval@1.1.1(transitive)
+ Addedtype-detect@4.1.0(transitive)