-
-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Description
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:
Line 15 in 6995474
for (let key of Object.keys(value)) { |
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).
Metadata
Metadata
Assignees
Labels
No labels