{"id":20311100,"url":"https://github.com/mcmath/deep-map-keys","last_synced_at":"2025-07-31T17:42:31.257Z","repository":{"id":62687804,"uuid":"61099253","full_name":"mcmath/deep-map-keys","owner":"mcmath","description":"Transforms nested keys of complex objects","archived":false,"fork":false,"pushed_at":"2022-10-21T23:04:04.000Z","size":40,"stargazers_count":21,"open_issues_count":6,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-25T12:11:04.525Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mcmath.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-14T06:55:19.000Z","updated_at":"2023-09-25T09:17:21.000Z","dependencies_parsed_at":"2022-11-04T13:33:01.658Z","dependency_job_id":null,"html_url":"https://github.com/mcmath/deep-map-keys","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcmath%2Fdeep-map-keys","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcmath%2Fdeep-map-keys/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcmath%2Fdeep-map-keys/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcmath%2Fdeep-map-keys/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mcmath","download_url":"https://codeload.github.com/mcmath/deep-map-keys/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248438498,"owners_count":21103409,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T17:36:09.924Z","updated_at":"2025-04-11T16:06:58.583Z","avatar_url":"https://github.com/mcmath.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Deep Map Keys\n\n[![Version][version-badge]][npm]\n[![License][license-badge]][license]\n[![Build][build-badge]][travis]\n[![Coverage][coverage-badge]][coveralls]\n\n[Install](#install) | [Usage](#usage) | [API](#api) | [TypeScript](#typescript) | [License](#license)\n\n**Deep Map Keys** recurses through an object and transforms its keys \u0026ndash; and\nthe keys of any nested objects \u0026ndash; according to some function. Circular\nreferences are supported.\n\nTo transform the *values* of an object rather than its keys, use\n[Deep Map][deep-map].\n\n## Install\n\nInstall Deep Map Keys via [npm][npm].\n\n```sh\nnpm install --save deep-map-keys\n```\n\n## Usage\n\nSuppose we want to change the keys of an object from [snake case][snake-case] to\n[camel case][camel-case]. We can do something like this:\n\n```js\nconst deepMapKeys = require('deep-map-keys');\n\nlet comment = {\n  comment_id: 42,\n  user_id: 1024,\n  user_name: 'Mufasa',\n  content: 'You deliberately disobeyed me.',\n  viewed_by: [\n    { user_id: 3820, user_name: 'Rafiki' },\n    { user_id: 8391, user_name: 'Zazu' }\n  ]\n};\n\nfunction snakeToCamel(key) {\n  return key.replace(/_(\\w)/g, (match, char) =\u003e char.toUpperCase());\n}\n\nlet result = deepMapKeys(comment, snakeToCamel);\n```\n\nAnd the result will look like this:\n\n```js\n{\n  commentId: 42,\n  userId: 1024,\n  userName: 'Mufasa',\n  content: 'You deliberately disobeyed me.',\n  viewedBy: [\n    { userId: 3820, userName: 'Rafiki' },\n    { userId: 8391, userName: 'Zazu' }\n  ]\n}\n```\n\n## API\n\n#### `deepMapKeys(object, mapFn, [options])`\n\n#### Parameters\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth align=\"left\"\u003eParam\u003c/th\u003e\n      \u003cth align=\"left\"\u003eType\u003c/th\u003e\n      \u003cth align=\"left\"\u003eDescription\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eobject\u003c/td\u003e\n      \u003ctd\u003e\u003ccode\u003eany\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003e\n        The object whose keys are to be transformed. Typically, this will be\n        a complex object containing other nested objects. This object may be an\n        \u003ca href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array\"\u003e\n        \u003ccode\u003eArray\u003c/code\u003e\u003c/a\u003e, in which case the keys of any objects it\n        contains will be transformed. The object may contain circular\n        references.\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003emapFn\u003c/td\u003e\n      \u003ctd\u003e\u003ccode\u003efunction\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003e\n        The function used to transform each key. The function is\n        called with two arguments:\n        \u003cul\u003e\n          \u003cli\u003e\n            \u003cstrong\u003ekey\u003c/strong\u003e \u0026lt;\u003ccode\u003estring\u003c/code\u003e\u0026gt;\n            The key being transformed\n          \u003c/li\u003e\n          \u003cli\u003e\n            \u003cstrong\u003evalue\u003c/strong\u003e \u0026lt;\u003ccode\u003eany\u003c/code\u003e\u0026gt;\n            The value of the node whose key is being transformed\n          \u003c/li\u003e\n        \u003c/ul\u003e\n        The return value determines the new name of the key, and must therefore\n        be a string.\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e[options]\u003c/td\u003e\n      \u003ctd\u003e\u003ccode\u003eobject\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003e\n        An optional options object. The following option is accepted:\n        \u003cul\u003e\n          \u003cli\u003e\n            \u003cstrong\u003ethisArg\u003c/strong\u003e \u0026lt;\u003ccode\u003eany=undefined\u003c/code\u003e\u0026gt;\n            Sets the value of\n            \u003ca href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this\"\u003e\u003ccode\u003ethis\u003c/code\u003e\u003c/a\u003e\n            within \u003ccode\u003emapFn()\u003c/code\u003e\n          \u003c/li\u003e\n        \u003c/ul\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n#### Returns\n\nReturns a new object.\n\n## TypeScript\n\n[TypeScript][typescript] declarations are included in the package. Just import\nthe module, and things will just work.\n\nThe shape of the returned object cannot be inferred from the inputs; however it\ncan be defined by passing a single type argument.\n\n```ts\ninterface Result {\n  userName: string;\n}\n\nlet result = deepMapKeys\u003cResult\u003e({user_name: 'Pumbaa'}, snakeToCamel);\n\nlet name = result.userName; // Everything is OK :)\n```\n\n## License\n\nCopyright \u0026copy; 2016–2019 Akim McMath. Licensed under the [MIT License][license].\n\n[version-badge]: https://img.shields.io/npm/v/deep-map-keys.svg?style=flat-square\n[license-badge]: https://img.shields.io/npm/l/deep-map-keys.svg?style=flat-square\n[build-badge]: https://img.shields.io/travis/mcmath/deep-map-keys/master.svg?style=flat-square\n[coverage-badge]: https://img.shields.io/coveralls/mcmath/deep-map-keys/master.svg?style=flat-square\u0026service=github\n[npm]: https://www.npmjs.com/package/deep-map-keys\n[license]: LICENSE\n[travis]: https://travis-ci.org/mcmath/deep-map-keys\n[coveralls]: https://coveralls.io/github/mcmath/deep-map-keys?branch=master\n[deep-map]: https://github.com/mcmath/deep-map\n[snake-case]: https://en.wikipedia.org/wiki/Snake_case\n[camel-case]: https://en.wikipedia.org/wiki/CamelCase\n[typescript]: http://www.typescriptlang.org/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcmath%2Fdeep-map-keys","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmcmath%2Fdeep-map-keys","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcmath%2Fdeep-map-keys/lists"}