diff --git a/utils/GunSmith/misc.js b/utils/GunSmith/misc.js index 064b8387..ab3faaee 100644 --- a/utils/GunSmith/misc.js +++ b/utils/GunSmith/misc.js @@ -40,6 +40,39 @@ const mergePuts = values => { 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 }