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> {
|
function isRecord(item: any): item is Record<string, any> {
|
||||||
const isNotNull = item != null
|
const isNotNull = item != null
|
||||||
const isObject = typeof item === 'object'
|
const isObject = typeof item === 'object'
|
||||||
const isNotAnArray = !Array.isArray(item)
|
const isPlainObject = isNotNull && isObject && Object.getPrototypeOf(item) === Object.prototype
|
||||||
return isNotNull && isNotAnArray && isObject
|
return isPlainObject
|
||||||
}
|
}
|
||||||
|
|
||||||
function mapKeysInArrayItems<T extends any[], R extends string>(arr: T, transform: (key: string) => R) {
|
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 () => {
|
it('maps keys with unusual values', async () => {
|
||||||
const func = () => 1
|
const func = () => 1
|
||||||
|
const date = new Date()
|
||||||
const obj = {
|
const obj = {
|
||||||
a: func,
|
a: func,
|
||||||
b: undefined,
|
b: undefined,
|
||||||
c: null
|
c: null,
|
||||||
|
d: date
|
||||||
}
|
}
|
||||||
const result = mapKeys(obj, (key) => `${key}_`)
|
const result = mapKeys(obj, (key) => `${key}_`)
|
||||||
|
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
a_: func,
|
a_: func,
|
||||||
b_: undefined,
|
b_: undefined,
|
||||||
c_: null
|
c_: null,
|
||||||
|
d_: date
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user