Function: deepMapKeys

deepMapKeys<T>(obj, fn): T

深层映射对象键

Type parameters

Name Type
T extends Record<string, any>

Parameters

Name Type Description
obj T 要转换键名的对象
fn (key: string) => string 键名转换函数

Returns

T

  • 转换后的新对象

Example

const obj = {
  foo: '1',
  nested: {
    child: {
      withArray: [
        {
          grandChild: ['hello']
        }
      ]
    }
  }
};

const upperKeysObj = deepMapKeys(obj, key => key.toUpperCase());
// =>
{
  "FOO":"1",
  "NESTED":{
    "CHILD":{
      "WITHARRAY":[
        {
          "GRANDCHILD":[ 'hello' ]
        }
      ]
    }
  }
}