fix(core-extensions): Apply mapKeys only to plain objects

This commit is contained in:
T. R. Bernstein
2025-07-04 12:10:59 +02:00
parent 4ceefae94f
commit 0d52c33b57
2 changed files with 7 additions and 4 deletions

View File

@@ -3,8 +3,8 @@ import type { MappedKeys } from '@/internal/mapped-keys.type.js'
function isRecord(item: any): item is Record<string, any> {
const isNotNull = item != null
const isObject = typeof item === 'object'
const isNotAnArray = !Array.isArray(item)
return isNotNull && isNotAnArray && isObject
const isPlainObject = isNotNull && isObject && Object.getPrototypeOf(item) === Object.prototype
return isPlainObject
}
function mapKeysInArrayItems<T extends any[], R extends string>(arr: T, transform: (key: string) => R) {

View File

@@ -39,17 +39,20 @@ describe('mapKeys', () => {
it('maps keys with unusual values', async () => {
const func = () => 1
const date = new Date()
const obj = {
a: func,
b: undefined,
c: null
c: null,
d: date
}
const result = mapKeys(obj, (key) => `${key}_`)
expect(result).toEqual({
a_: func,
b_: undefined,
c_: null
c_: null,
d_: date
})
})
})