{"id":17347607,"url":"https://github.com/vicary/multidict","last_synced_at":"2025-03-27T11:20:35.648Z","repository":{"id":229292500,"uuid":"616772161","full_name":"vicary/multidict","owner":"vicary","description":"A TypeScript implementation of a key-value store that supports multiple keys and values.","archived":false,"fork":false,"pushed_at":"2024-03-23T10:42:05.000Z","size":18554,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-14T13:52:01.567Z","etag":null,"topics":["array-map","bidirectional-mapping","dictionary","graph","many-to-many-relationship","map","multiple-keys","multiple-values","object-map","two-way-association"],"latest_commit_sha":null,"homepage":"https://npmjs.org/package/multidict","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/vicary.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},"funding":{"github":["vicary"]}},"created_at":"2023-03-21T03:32:38.000Z","updated_at":"2024-04-20T08:37:44.228Z","dependencies_parsed_at":null,"dependency_job_id":"61570fe7-5058-48a2-aae2-eccd6ea04e6d","html_url":"https://github.com/vicary/multidict","commit_stats":null,"previous_names":["vicary/multidict"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vicary%2Fmultidict","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vicary%2Fmultidict/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vicary%2Fmultidict/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vicary%2Fmultidict/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vicary","download_url":"https://codeload.github.com/vicary/multidict/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245832747,"owners_count":20679702,"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":["array-map","bidirectional-mapping","dictionary","graph","many-to-many-relationship","map","multiple-keys","multiple-values","object-map","two-way-association"],"created_at":"2024-10-15T16:49:26.563Z","updated_at":"2025-03-27T11:20:35.603Z","avatar_url":"https://github.com/vicary.png","language":"TypeScript","funding_links":["https://github.com/sponsors/vicary"],"categories":[],"sub_categories":[],"readme":"# MultiDict\n\nMultiDict is an extension of Map that supports bidirectioal, many to many\nrelations amongst multiple keys and values.\n\n## Usage\n\n```ts\nimport { MultiDict } from \"multidict\";\n\nconst myMap = new MultiDict\u003cstring, number\u003e();\nmyMap.set(\"foo\", 1);\nmyMap.set(\"foo\", 2);\nmyMap.set(3, \"bar\"); // In a two-way reference model, key and value means the same thing.\n\nconsole.log(myMap.get(\"foo\")); // -\u003e Set { 1, 2 }\nconsole.log(myMap.get(1)); // -\u003e Set { \"foo\" }\n\nconsole.log(myMap.get(\"bar\")); // -\u003e Set { 3 }\nconsole.log(myMap.get(3)); // -\u003e Set { \"bar\" }\n```\n\nYou may also use it like an iterator:\n\n```ts\nfor (const [key, values] of myMap) {\n  for (const value of values) {\n    console.log(key, value);\n  }\n}\n```\n\nMultiDict supports all of the standard Map methods, but always return a Set of\nvalues.\n\nYou can easily deletes all values associated with a key with the `delete()`\nmethod, or only deletes one specific key-value pair by specifying the value as\nwell:\n\n```ts\nmyMap.set(\"foo\", 1);\nmyMap.set(2, \"foo\");\nmyMap.set(\"foo\", 3);\n\nmyMap.delete(\"foo\", 1);\nconsole.log(myMap.get(\"foo\")); // -\u003e Set { 2, 3 }\n\nmyMap.delete(\"foo\");\nconsole.log(myMap.get(\"foo\")); // -\u003e undefined\nconsole.log(myMap.get(2)); // -\u003e undefined\n```\n\n## API\n\n1. `clear()`: Clears all key-value pairs from the store.\n1. `delete(key: K, value?: V): boolean`: Deletes a key-value pair from the\n   store. If a value parameter is provided, only the specified key-value pair is\n   deleted. If no value parameter is provided, all key-value pairs associated\n   with the specified key are deleted. Returns true if the key-value pair(s)\n   were deleted, false otherwise.\n1. `entries()`: Returns an iterator of all key-value pairs in the store.\n1. `forEach(callbackfn: (value: Set\u003cK | V\u003e, key: K | V, map: Map\u003cK | V, Set\u003cK | V\u003e\u003e) =\u003e void, thisArg?: any)`:\n   Calls a provided function once for each key-value pair in the store, in\n   insertion order.\n1. `get(key: K): Set\u003cV\u003e | undefined`: Returns a Set of all values associated\n   with the specified key, or undefined if the key is not present in the store.\n1. `has(key: K | V): boolean`: Returns true if the specified key or value is\n   present in the store, false otherwise.\n1. `keys()`: Returns an iterator of all keys in the store.\n1. `set(key: K, value: V): this`: Associates a key with a value in the store.\n   Returns the same instance to allow for method chaining. If the key or value\n   already exists in the store, the existing values associated with the key or\n   value are preserved, and the new value is added to the existing set of\n   values.\n1. `size`: Returns the number of key-value pairs in the store.\n1. `values()`: Returns an iterator of all values in the store.\n\n## Contributing\n\nIf you find a bug or would like to suggest a new feature, please open an issue\nor submit a pull request on GitHub.\n\n## License\n\nMultiDict is licensed under the MIT License. See the LICENSE file for more\ninformation.\n\n## Funding\n\nIf you find this project useful, please consider supporting it by donating to\nthe author.\n\n[![Donate](https://img.shields.io/static/v1?label=Sponsor\u0026message=%E2%9D%A4\u0026logo=GitHub)](https://github.com/sponsors/vicary)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvicary%2Fmultidict","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvicary%2Fmultidict","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvicary%2Fmultidict/lists"}