diff --git a/src/deep-map-keys.ts b/src/deep-map-keys.ts index 7148b87..a149803 100644 --- a/src/deep-map-keys.ts +++ b/src/deep-map-keys.ts @@ -55,7 +55,7 @@ export class DeepMapKeys { this.cache.set(obj, result); for (let key in obj) { - if (obj.hasOwnProperty(key)) { + if (Object.hasOwnProperty.call(obj, key)) { result[mapFn.call(thisArg, key, obj[key])] = this.map(obj[key]); } } diff --git a/src/index.test.ts b/src/index.test.ts index d6ba49b..7135cc5 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -102,3 +102,12 @@ describe('deepMapKeys(object, mapFn, [options])', () => { }); }); + +it('handles null prototype objects', () => { + const caps = (key: string) => key.toUpperCase(); + + const nullProtoObj = Object.create(null); + nullProtoObj.foo = 'bar'; + + deepMapKeys(nullProtoObj, caps).should.deep.equal({ FOO: 'bar' }); +});