{"id":22021600,"url":"https://github.com/lamansky/map-map","last_synced_at":"2025-03-23T10:19:33.064Z","repository":{"id":92612023,"uuid":"115612385","full_name":"lamansky/map-map","owner":"lamansky","description":"[Node.js] Applies a callback to each key-value pair of a Map or Object.","archived":false,"fork":false,"pushed_at":"2019-12-08T14:25:05.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-01T04:55:27.144Z","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/lamansky.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","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}},"created_at":"2017-12-28T10:27:07.000Z","updated_at":"2019-12-08T14:25:07.000Z","dependencies_parsed_at":"2023-04-12T04:02:41.949Z","dependency_job_id":null,"html_url":"https://github.com/lamansky/map-map","commit_stats":{"total_commits":12,"total_committers":1,"mean_commits":12.0,"dds":0.0,"last_synced_commit":"9ed32c822e5efa78a2daf33936854770d4218edb"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Fmap-map","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Fmap-map/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Fmap-map/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Fmap-map/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lamansky","download_url":"https://codeload.github.com/lamansky/map-map/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245085100,"owners_count":20558333,"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-30T06:13:11.546Z","updated_at":"2025-03-23T10:19:33.040Z","avatar_url":"https://github.com/lamansky.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# map-map\n\nApplies a callback to each key-value pair of a Map, Object, or other collection. The original collection is not modified; a copy is returned.\n\n## Installation\n\nRequires [Node.js](https://nodejs.org/) 7.0.0 or above.\n\n```bash\nnpm i map-map\n```\n\n## API\n\nThe module exports a single function.\n\n### Parameters\n\n1. `map` (Array, iterator, Object, Map, Set, string, or Typed Array)\n2. `mapper` (function): The callback which receives three arguments (key, value, and index) and which returns a two-element array containing the new key and value.\n3. Optional: Object argument:\n    * `recursive` (boolean, function, or array): Determines whether `mapper` should be applied to the values of nested maps or to the nested maps themselves.\n        * If set to `true`, recursive mapping will be applied to all collections that have the exact same object constructor as `map`.\n        * If set to a function, all values will be given to the function, and recursive mapping will be applied to those values for which the function returns `true`.\n        * If set to an array of classes or class name strings, recursive mapping will be applied to all objects that descend from those classes.\n        * If omitted or if set to a falsey value, recursive mapping will not be applied, and all values will be passed through `mapper` even if they are maps themselves.\n    * All other options are forwarded to [`entries-array`](https://github.com/lamansky/entries-array), a dependency of this module.\n\n### Return Value\n\nA copy of `map` which has had `mapper` applied to each of its key-value pairs, and optionally (depending on `recursive`) the key-value pairs of its child collections.\n\n## Examples\n\n### Maps\n\n```javascript\nconst mapMap = require('map-map')\n\nlet map = new Map([['key', 'value']])\nmap = mapMap(map, (key, value, index) =\u003e [key + '_mapped', value + '_mapped'])\nmap.get('key_mapped') // 'value_mapped'\n```\n\n### Objects\n\n```javascript\nconst mapMap = require('map-map')\n\nlet obj = {key: 'value'}\nobj = mapMap(obj, (key, value, index) =\u003e [key + '_mapped', value + '_mapped'])\nobj.key_mapped // 'value_mapped'\n```\n\n### Recursive mapping\n\n```javascript\nconst mapMap = require('map-map')\n\nconst obj = {\n  a: 1,\n  b: [2, 3],\n  c: {d: 4},\n}\n\n// Mapping function that doubles all numbers\nconst d = (k, v) =\u003e [k, typeof v === 'number' ? v * 2 : v]\n\n// Default behavior, without recursive mapping: only `a` is changed\nmapMap(obj, d) // {a: 2, b: [2, 3], c: {d: 4}}\n\n// Recursive mapping enabled for arrays only: numbers in `a` and `b` are changed\nmapMap(obj, d, {recursive: [Array]}) // {a: 2, b: [4, 6], c: {d: 4}}\n\n// Recursive mapping enabled for children of the same type as `obj`\n// (i.e. other Objects, but not Arrays): numbers in `a` and `c` are changed\nmapMap(obj, d, {recursive: true}) // {a: 2, b: [2, 3], c: {d: 8}}\n\n// Recursive mapping enabled for everything descending from Object\n// (which includes arrays): all numbers are doubled\nmapMap(obj, d, {recursive: [Object]}) // {a: 2, b: [4, 6], c: {d: 8}}\n```\n\n## Version Migration Guide\n\nHere are backward-incompatible changes you need to know about.\n\n### 3.2.0 ⇒ Master\n\n* To reduce overhead, support for the bind operator has been removed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flamansky%2Fmap-map","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flamansky%2Fmap-map","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flamansky%2Fmap-map/lists"}