{"id":18824139,"url":"https://github.com/gastonpereyra/map-items-by-keys","last_synced_at":"2026-05-18T11:07:23.419Z","repository":{"id":46831349,"uuid":"299125784","full_name":"gastonpereyra/map-items-by-keys","owner":"gastonpereyra","description":"Create a dictonary-like object from a list of objects using an specfic value from each object","archived":false,"fork":false,"pushed_at":"2021-09-23T03:53:02.000Z","size":51,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-28T01:28:30.850Z","etag":null,"topics":["keys","list","node","object"],"latest_commit_sha":null,"homepage":"","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/gastonpereyra.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2020-09-27T21:52:28.000Z","updated_at":"2021-09-25T01:50:06.000Z","dependencies_parsed_at":"2022-08-21T03:10:34.778Z","dependency_job_id":null,"html_url":"https://github.com/gastonpereyra/map-items-by-keys","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":"gastonpereyra/npm-template","purl":"pkg:github/gastonpereyra/map-items-by-keys","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gastonpereyra%2Fmap-items-by-keys","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gastonpereyra%2Fmap-items-by-keys/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gastonpereyra%2Fmap-items-by-keys/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gastonpereyra%2Fmap-items-by-keys/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gastonpereyra","download_url":"https://codeload.github.com/gastonpereyra/map-items-by-keys/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gastonpereyra%2Fmap-items-by-keys/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33175909,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-18T09:27:30.708Z","status":"ssl_error","status_checked_at":"2026-05-18T09:27:28.300Z","response_time":71,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["keys","list","node","object"],"created_at":"2024-11-08T00:55:41.142Z","updated_at":"2026-05-18T11:07:23.403Z","avatar_url":"https://github.com/gastonpereyra.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Map Items by Keys\n\n## Code Quality Status\n![Build Status](https://github.com/gastonpereyra/map-items-by-keys/workflows/Build%20Status/badge.svg)\n[![Coverage Status](https://img.shields.io/coveralls/github/gastonpereyra/map-items-by-keys/master.svg)](https://coveralls.io/r/gastonpereyra/map-items-by-keys?branch=master)\n\n![Map-Items-By-Keys Banner](https://user-images.githubusercontent.com/39351850/94375239-ad9b9780-00e8-11eb-9e8a-dcedbf5418a7.png)\n\n## Description\nCreate a dictonary-like object from a list of objects using an specfic value from each object.\n\n## Installation\n\n```\nnpm i map-items-by-keys\n```\n\n## mapItemsBy(keys, items, isUnique)\n\n### Parameters\n\n#### keys\n\nThe name of the fields to use as Keys. Can be a Single Key or Multiple ones.\n\n- Type: _string_ or _Array of string_\n- Example:\n    - `'id'`\n    - `['id', 'name']`\n\n\u003e :warning: If some item hasn't the field will be ignored\n#### items\n\nThe list of items to be mapped.\n\n- Type: _Array of objects_\n- Example:\n\n```json\n[\n    { \"id\": 1, \"name\": \"Bruce Wayne\", \"hero\": \"Batman\" },\n    { \"id\": 2, \"name\": \"Tony Stark\", \"hero\": \"Ironman\" }\n]\n```\n\n#### isUnique\n\nThis refers if the values of the keys are unique. This indicate if the final map will save as an array (`false`) or an object (`false`).\n\n- Type: _Boolean_\n- Default: `true`\n\n### Examples\n\n#### Single and Unique Key\n\n```js\nconst mapItemsBy = require('map-items-by-keys');\n\nconst items = [\n    { id: 1, name: \"Bruce Wayne\", hero: \"Batman\" },\n    { id: 2, name: \"Tony Stark\", hero: \"Ironman\" }\n]\n\nconst itemsMapped = mapItemsBy(\"id\", items);\n\n/*\noutput: \n\n{\n    1: { id: 1, name: \"Bruce Wayne\", hero: \"Batman\" },\n    2: { id: 2, name: \"Tony Stark\", hero: \"Ironman\" }\n}\n*/\n```\n\n#### Single and not-unique Key\n\n```js\nconst mapItemsBy = require('map-items-by-keys');\n\nconst items = [\n    { id: 1, name: \"Bruce Wayne\", hero: \"Batman\" },\n    { id: 2, name: \"Tony Stark\", hero: \"Ironman\" },\n    { id: 3, name: \"Richard Grayson\", hero: \"Batman\" }\n]\n\nconst itemsMapped = mapItemsBy(\"hero\", items, false);\n\n/*\noutput: \n\n{\n    Batman: [\n        { id: 1, name: Bruce Wayne, hero: \"Batman\" },\n        { id: 3, name: \"Richard Grayson\", hero: \"Batman\" }\n    ],\n    Ironman: [\n        { id: 2, name: Tony Stark, hero: \"Ironman\" }\n    ]\n}\n*/\n```\n\n#### Multiple and Unique Key\n\n```js\nconst mapItemsBy = require('map-items-by-keys');\n\nconst items = [\n    { id: 1, name: \"Bruce Wayne\", hero: \"Batman\", brand: \"DC\" },\n    { id: 2, name: \"Tony Stark\", hero: \"Ironman\", brand: \"Marvel\" }\n]\n\nconst itemsMapped = mapItemsBy([\"brand\", \"id\"], items);\n\n/*\noutput: \n\n{\n    DC: {\n        1: { id: 1, name: \"Bruce Wayne\", hero: \"Batman\" }\n    },\n    Marvel: {\n        2: { id: 2, name: \"Tony Stark\", hero: \"Ironman\" }\n    }\n}\n*/\n```\n\n#### Multiple and not-unique Key\n\n```js\nconst mapItemsBy = require('map-items-by-keys');\n\nconst items = [\n    { id: 1, name: \"Bruce Wayne\", hero: \"Batman\", brand: \"DC\" },\n    { id: 2, name: \"Tony Stark\", hero: \"Ironman\", brand: \"Marvel\" },\n    { id: 3, name: \"Richard Grayson\", hero: \"Batman\", brand: \"DC\" }\n]\n\nconst itemsMapped = mapItemsBy([\"brand\", \"hero\"], items, false);\n\n/*\noutput: \n\n{\n     DC: {\n        Batman: [\n            { id: 1, name: \"Bruce Wayne\", hero: \"Batman\" },\n            { id: 3, name: \"Richard Grayson\", hero: \"Batman\", brand: \"DC\" }\n        ]\n    },\n    Marvel: {\n        Ironman: [\n            { id: 2, name: \"Tony Stark\", hero: \"Ironman\" }\n        ]\n    }\n}\n*/\n```\n## Bug :bug:\n\n[Report Here](https://github.com/gastonpereyra/map-items-by-keys/issues/new?assignees=gastonpereyra\u0026labels=bug\u0026template=bug.md\u0026title=[BUG])\n\n## Idea :bulb:\n\n[Tell me](https://github.com/gastonpereyra/map-items-by-keys/issues/new?assignees=gastonpereyra\u0026labels=enhancement\u0026title=%5BIDEA%5D+-)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgastonpereyra%2Fmap-items-by-keys","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgastonpereyra%2Fmap-items-by-keys","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgastonpereyra%2Fmap-items-by-keys/lists"}