More utils in GunSmith/misc

This commit is contained in:
Daniel Lugo 2021-09-15 11:02:20 -04:00
parent 10d309a8d6
commit 792c3e160e

View file

@ -40,6 +40,39 @@ const mergePuts = values => {
return finalResult return finalResult
} }
module.exports = { /**
mergePuts * @param {any} data
* @returns {any}
*/
const removeBuiltInGunProps = data => {
if (typeof data === 'object' && data !== null) {
const o = { ...data }
delete o._
delete o['#']
return o
}
console.log(data)
throw new TypeError(
'Non object passed to removeBuiltInGunProps: ' + JSON.stringify(data)
)
}
/**
* @param {GunT.ListenerData} data
*/
const isPopulated = data => {
if (data === null || typeof data === 'undefined') {
return false
}
if (typeof data === 'object') {
return Object.keys(removeBuiltInGunProps(data)).length > 0
}
return true
}
module.exports = {
mergePuts,
removeBuiltInGunProps,
isPopulated
} }