fix(core-extensions): Apply mapKeys only to plain objects
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user