omit-empty
omit-empty copied to clipboard
Doesn't keep Symbol properties
Hello! When omitEmpty is called with an object that has Symbols as property keys, those keys are missing from the result:
const omitEmpty = require('omit-empty')
const assert = require('assert')
let gte = Symbol('gte'),
lt = Symbol.for('lt')
test('should clean some symbols', () => {
let actual = omitEmpty({
userId: 1,
age: {
[gte]: null,
[lt]: 20
}
})
let expected = {
userId: 1,
age: {
[lt]: 2
}
}
// fails: the returned object is just { userId: 1 }
assert.deepEqual(actual, expected)
})
This happens because Object.keys() only sees string keys, in this line:
https://github.com/jonschlinkert/omit-empty/blob/69954742d6a8f5bdf3056c5f9fc6ad355595a6ae/index.js#L15
This could be fixed by using Object.getOwnPropertySymbols() in addition to Object.keys().
(The reason I'm using symbols as property keys is because of Sequelize's recommended query practices).
I'm just reporting this issue; I've already worked around it.
I'm hesitant to provide a PR because I'm unsure if getOwnPropertySymbols() might cause errors in old environments, or if it would be a breaking change.