{"id":15042823,"url":"https://github.com/sindresorhus/map-obj","last_synced_at":"2025-04-14T15:47:26.916Z","repository":{"id":21795232,"uuid":"25117742","full_name":"sindresorhus/map-obj","owner":"sindresorhus","description":"Map object keys and values into a new object","archived":false,"fork":false,"pushed_at":"2023-10-16T18:47:08.000Z","size":36,"stargazers_count":212,"open_issues_count":4,"forks_count":42,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-14T07:22:03.283Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/sindresorhus.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/funding.yml","license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/security.md","support":null,"governance":null},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2014-10-12T11:42:51.000Z","updated_at":"2025-04-10T09:32:01.000Z","dependencies_parsed_at":"2022-07-12T05:18:32.500Z","dependency_job_id":"ce349d03-e646-4268-b3b8-cf1643c22382","html_url":"https://github.com/sindresorhus/map-obj","commit_stats":{"total_commits":47,"total_committers":11,"mean_commits":"4.2727272727272725","dds":0.276595744680851,"last_synced_commit":"4257d4dd8564efa2372c6964eb16463cb3af898d"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fmap-obj","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fmap-obj/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fmap-obj/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fmap-obj/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/map-obj/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248908783,"owners_count":21181594,"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-09-24T20:48:02.781Z","updated_at":"2025-04-14T15:47:26.880Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","readme":"# map-obj\n\n\u003e Map object keys and values into a new object\n\n## Install\n\n```sh\nnpm install map-obj\n```\n\n## Usage\n\n```js\nimport mapObject, {mapObjectSkip} from 'map-obj';\n\nconst newObject = mapObject({foo: 'bar'}, (key, value) =\u003e [value, key]);\n//=\u003e {bar: 'foo'}\n\nconst newObject = mapObject({FOO: true, bAr: {bAz: true}}, (key, value) =\u003e [key.toLowerCase(), value]);\n//=\u003e {foo: true, bar: {bAz: true}}\n\nconst newObject = mapObject({FOO: true, bAr: {bAz: true}}, (key, value) =\u003e [key.toLowerCase(), value], {deep: true});\n//=\u003e {foo: true, bar: {baz: true}}\n\nconst newObject = mapObject({one: 1, two: 2}, (key, value) =\u003e value === 1 ? [key, value] : mapObjectSkip);\n//=\u003e {one: 1}\n```\n\n## API\n\n### mapObject(source, mapper, options?)\n\n#### source\n\nType: `object`\n\nThe source object to copy properties from.\n\n#### mapper\n\nType: `(sourceKey, sourceValue, source) =\u003e [targetKey, targetValue, mapperOptions?] | mapObjectSkip`\n\nA mapping function.\n\n##### mapperOptions\n\nType: `object`\n\n###### shouldRecurse\n\nType: `boolean`\\\nDefault: `true`\n\nWhether `targetValue` should be recursed.\n\nRequires `deep: true`.\n\n#### options\n\nType: `object`\n\n##### deep\n\nType: `boolean`\\\nDefault: `false`\n\nRecurse nested objects and objects in arrays.\n\n##### target\n\nType: `object`\\\nDefault: `{}`\n\nThe target object to map properties on to.\n\n### mapObjectSkip\n\nReturn this value from a `mapper` function to exclude the key from the new object.\n\n```js\nimport mapObject, {mapObjectSkip} from 'map-obj';\n\nconst object = {one: 1, two: 2}\nconst mapper = (key, value) =\u003e value === 1 ? [key, value] : mapObjectSkip\nconst result = mapObject(object, mapper);\n\nconsole.log(result);\n//=\u003e {one: 1}\n```\n\n## Related\n\n- [filter-obj](https://github.com/sindresorhus/filter-obj) - Filter object keys and values into a new object\n\n---\n\n\u003cdiv align=\"center\"\u003e\n\t\u003cb\u003e\n\t\t\u003ca href=\"https://tidelift.com/subscription/pkg/npm-map-obj?utm_source=npm-map-obj\u0026utm_medium=referral\u0026utm_campaign=readme\"\u003eGet professional support for this package with a Tidelift subscription\u003c/a\u003e\n\t\u003c/b\u003e\n\t\u003cbr\u003e\n\t\u003csub\u003e\n\t\tTidelift helps make open source sustainable for maintainers while giving companies\u003cbr\u003eassurances about security, maintenance, and licensing for their dependencies.\n\t\u003c/sub\u003e\n\u003c/div\u003e\n","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://sindresorhus.com/donate","https://tidelift.com/subscription/pkg/npm-map-obj?utm_source=npm-map-obj\u0026utm_medium=referral\u0026utm_campaign=readme"],"categories":["Modules","模块"],"sub_categories":["Object","对象"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fmap-obj","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fmap-obj","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fmap-obj/lists"}