{"id":17448334,"url":"https://github.com/mesqueeb/map-anything","last_synced_at":"2025-04-13T18:34:04.122Z","repository":{"id":36943686,"uuid":"232455480","full_name":"mesqueeb/map-anything","owner":"mesqueeb","description":"Array.map but for objects with good TypeScript support. A small and simple integration.","archived":false,"fork":false,"pushed_at":"2025-02-24T21:26:26.000Z","size":1555,"stargazers_count":11,"open_issues_count":9,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T23:18:52.527Z","etag":null,"topics":["compose","map-object","map-reduce","mapping","object-map","object-mapper","object-to-object","transform"],"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/mesqueeb.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":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"mesqueeb","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2020-01-08T01:58:29.000Z","updated_at":"2025-02-24T21:26:30.000Z","dependencies_parsed_at":"2023-12-22T17:26:32.015Z","dependency_job_id":"c32f66e3-6652-49f4-8eac-12551faca956","html_url":"https://github.com/mesqueeb/map-anything","commit_stats":{"total_commits":37,"total_committers":3,"mean_commits":"12.333333333333334","dds":0.4054054054054054,"last_synced_commit":"102c5403a967197f768248208a1f9cf3ddbb5b60"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mesqueeb%2Fmap-anything","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mesqueeb%2Fmap-anything/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mesqueeb%2Fmap-anything/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mesqueeb%2Fmap-anything/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mesqueeb","download_url":"https://codeload.github.com/mesqueeb/map-anything/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248760608,"owners_count":21157391,"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":["compose","map-object","map-reduce","mapping","object-map","object-mapper","object-to-object","transform"],"created_at":"2024-10-17T20:07:05.327Z","updated_at":"2025-04-13T18:34:04.100Z","avatar_url":"https://github.com/mesqueeb.png","language":"TypeScript","funding_links":["https://github.com/sponsors/mesqueeb"],"categories":[],"sub_categories":[],"readme":"# Map anything 🗺\n\n\u003ca href=\"https://www.npmjs.com/package/map-anything\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/map-anything.svg\" alt=\"Total Downloads\"\u003e\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/package/map-anything\"\u003e\u003cimg src=\"https://img.shields.io/npm/dw/map-anything.svg\" alt=\"Latest Stable Version\"\u003e\u003c/a\u003e\n\n```\nnpm i map-anything\n```\n\nArray.map but for objects with good TypeScript support. A small and simple integration.\n\n## Motivation\n\nI always want to do:\n\n```js\nsomeObject.map((val) =\u003e someFunction)\n```\n\nBut this doesn't exist for objects, you need to do this instead:\n\n```js\nObject.entries(someObject).reduce((carry, [key, value], index, array) =\u003e {\n  carry[key] = someFunction(value, key, array)\n  return carry\n}, {})\n```\n\nSo I made a wrapper function for that. 😃\n\n`map-anything` has very good [#TypeScript](#typescript) support as well.\n\n## Usage\n\nProvided Functions:\n\n- `mapObject` takes an object and maps over the values of each key\n- `mapObjectAsync` takes an object and maps a promise over the values of each key, after which you can just do a single await\n- `mapMap` takes a map and maps over the values of each key\n\n### Basic Usage\n\n```js\nimport { mapObject } from 'map-anything'\n\nconst pokemon = {\n  '001': { name: 'Bulbasaur', level: 10 },\n  '004': { name: 'Charmander', level: 8 },\n  '007': { name: 'Squirtle', level: 11 },\n}\n\nconst levelUp = mapObject(pokemon, (pkmn) =\u003e {\n  return { ...pkmn, level: pkmn.level + 1 }\n})\n\n// results in:\nlevelUp ===\n  {\n    '001': { name: 'Bulbasaur', level: 11 },\n    '004': { name: 'Charmander', level: 9 },\n    '007': { name: 'Squirtle', level: 12 },\n  }\n```\n\n### Access the propName in the map function\n\nA function passed to `Array.map` will get the value as first argument and an **index** as second. With `mapObject` you will get the **propName** as second argument.\n\n```js\nimport { mapObject } from 'map-anything'\n\nconst pokemon = {\n  '001': { name: 'Bulbasaur', level: 10 },\n  '004': { name: 'Charmander', level: 8 },\n  '007': { name: 'Squirtle', level: 11 },\n}\n\nconst addIds = mapObject(pokemon, (pkmn, propName) =\u003e {\n  const id = propName\n  return { ...pkmn, id }\n})\n\n// results in:\naddIds ===\n  {\n    '001': { name: 'Bulbasaur', level: 10, id: '001' },\n    '004': { name: 'Charmander', level: 8, id: '004' },\n    '007': { name: 'Squirtle', level: 11, id: '007' },\n  }\n```\n\n### Map Object Async\n\n```ts\nconst pokemon = {\n  '001': { name: 'Bulbasaur', level: 10 },\n  '004': { name: 'Charmander', level: 8 },\n  '007': { name: 'Squirtle', level: 11 },\n}\n\nconst result = await mapObjectAsync(pokemon, async (pkmn, propName) =\u003e {\n  const id = propName\n  const data = await fetchData(id) // hypothetical API call\n  return { ...pkmn, data }\n})\n\n// results in:\nresult ===\n  {\n    '001': { name: 'Bulbasaur', level: 10, data: '...' }, // some fetched data\n    '004': { name: 'Charmander', level: 8, data: '...' },\n    '007': { name: 'Squirtle', level: 11, data: '...' },\n  }\n```\n\n## TypeScript\n\nWithout having to specify the return type in the reducer, I've set `map-anything` up so it automatically detects that type for you!\n\n![typescript support](https://raw.githubusercontent.com/mesqueeb/map-anything/master/.github/typescript-support.png)\n\n## Meet the family (more tiny utils with TS support)\n\n- [is-what 🙉](https://github.com/mesqueeb/is-what)\n- [is-where 🙈](https://github.com/mesqueeb/is-where)\n- [merge-anything 🥡](https://github.com/mesqueeb/merge-anything)\n- [check-anything 👁](https://github.com/mesqueeb/check-anything)\n- [remove-anything ✂️](https://github.com/mesqueeb/remove-anything)\n- [getorset-anything 🐊](https://github.com/mesqueeb/getorset-anything)\n- [map-anything 🗺](https://github.com/mesqueeb/map-anything)\n- [filter-anything ⚔️](https://github.com/mesqueeb/filter-anything)\n- [copy-anything 🎭](https://github.com/mesqueeb/copy-anything)\n- [case-anything 🐫](https://github.com/mesqueeb/case-anything)\n- [flatten-anything 🏏](https://github.com/mesqueeb/flatten-anything)\n- [nestify-anything 🧅](https://github.com/mesqueeb/nestify-anything)\n\n## Source code\n\nThe source code is rather simple, it's doing something like the snippet show here below.\n\u003cbr /\u003eHowever, it's adding amazing typescript.\n\n```JavaScript\nfunction mapObject (object, fn) {\n  return Object.entries(object)\n    .reduce((carry, [key, value], index, array) =\u003e {\n      carry[key] = fn(value, key, array)\n      return carry\n    }, {})\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmesqueeb%2Fmap-anything","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmesqueeb%2Fmap-anything","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmesqueeb%2Fmap-anything/lists"}