I just wrote a function and I'm not sure if it is a good idea.
The motivation is, I'd like to store some internal bookkeeping data along with my business data in one big happy javascript object. When that object is consumed, I would like to strip the internal variables. As a convention, my internal variables take the form _internalNotes
whereas my business variables don't start with an underscore.
Anyway, this is the function. It works as intended, but is this a terrible pattern?
export const stripInternals = (obj) => {
const props = {}
Object.keys(obj).forEach(key => {
if (key.slice(0,1) !== '_') props[key] = obj[key]
})
return props
}
shape
, then just delete it. But neither way seems very secure.