{"id":21304956,"url":"https://github.com/maximilianmairinger/keyindex","last_synced_at":"2025-03-15T19:26:33.279Z","repository":{"id":57147989,"uuid":"276113670","full_name":"maximilianMairinger/keyIndex","owner":"maximilianMairinger","description":"Memoize on demand map","archived":false,"fork":false,"pushed_at":"2024-03-06T14:10:27.000Z","size":41,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-22T18:06:28.219Z","etag":null,"topics":["index","key","map","memoize"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/key-index","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maximilianMairinger.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2020-06-30T13:54:43.000Z","updated_at":"2023-06-10T18:25:39.000Z","dependencies_parsed_at":"2023-10-11T01:29:14.239Z","dependency_job_id":"7633b911-e0ad-4775-9405-7eaf8deed0e2","html_url":"https://github.com/maximilianMairinger/keyIndex","commit_stats":{"total_commits":80,"total_committers":1,"mean_commits":80.0,"dds":0.0,"last_synced_commit":"f13da393b289f1c60e89eacbe9f4694dfd7ef234"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximilianMairinger%2FkeyIndex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximilianMairinger%2FkeyIndex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximilianMairinger%2FkeyIndex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximilianMairinger%2FkeyIndex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maximilianMairinger","download_url":"https://codeload.github.com/maximilianMairinger/keyIndex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243779619,"owners_count":20346745,"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":["index","key","map","memoize"],"created_at":"2024-11-21T16:16:28.142Z","updated_at":"2025-03-15T19:26:33.251Z","avatar_url":"https://github.com/maximilianMairinger.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Key Index\r\n\r\nKey based index store.\r\n\r\n## Installation\r\n\r\n```shell\r\n $ npm i key-index\r\n```\r\n\r\n## Usage\r\n\r\n### Create an index\r\n\r\nImport\r\n\r\n```ts\r\nimport keyIndex from \"key-index\"\r\n```\r\n\r\nCreate an instance\r\n\r\n```ts\r\nlet initer = (pointer: string) =\u003e {\r\n  return {name: pointer}\r\n}\r\n\r\nlet index = keyIndex(initer)\r\n```\r\n\r\n### Query\r\n\r\nWhen querying a key that is not assigned to a value yet, one is automatically created via the given `initer` function.\r\n\r\n```ts\r\nlet a = index(\"keyA\")     // {name: \"keyA\"}\r\na.prop = \"val\"\r\nindex(\"keyA\")             // {name: \"keyA\", prop: \"val\"}\r\n```\r\n\r\n(Mostly for debugging purposes) you can also query the whole document\r\n\r\n```ts\r\nlet a = index()    // Map: {\r\n                   //   \"keyA\": {\r\n                   //     \"name\": \"keyA\"\r\n                   //     \"prop\": \"val\"\r\n                   //   }\r\n                   // }\r\n```\r\n\r\nThe index is stored in a Map by default. If youd like to use a regular object as index instead use\r\n\r\n```ts\r\nimport { constructObjectIndex as keyIndex } from \"key-index\"\r\n```\r\n\r\nAll functionality is the same here. The only difference is the underlying technology used. \r\n\r\n\u003e Note: that native objects do only support strings | number | symbol as indices!\r\n\r\n### Using other initers\r\n\r\nThis is the default initer\r\n\r\n```ts\r\nkeyIndex(/* () =\u003e {return {}} */)\r\n```\r\n\r\n#### Using values directly\r\n\r\nYou can use values directly. If your use case does only need one value.\r\n\r\n```ts\r\nlet valueIndex = keyIndex((key) =\u003e key)\r\nvalueIndex(\"keyA\")                 // \"keyA\"\r\n```\r\n\r\nIn that (and every other) case you can change the value like so: \r\n\r\n```ts\r\nvalueIndex(\"keyA\", \"keyAValue\")    // \"keyAValue\"\r\nvalueIndex(\"keyA\")                 // \"keyAValue\"\r\n```\r\n\r\n#### Nested indices\r\n\r\nIf using your use case requires nested indices consider this\r\n\r\n```ts\r\nlet nestedIndex = keyIndex(() =\u003e keyIndex(/* () =\u003e {return {}} */))\r\nnestedIndex(\"keyA\")(\"keyB\")         // {}\r\n```\r\n\r\nQuerying the whole document does also work here\r\n\r\n```ts\r\nnestedIndex(\"keyA\")(\"keyB\").key = \"val\"\r\nnestedIndex(\"keyA\")(\"keyC\").key = \"val\"\r\nnestedIndex(\"keyD\")(\"keyE\").key1 = \"val1\"\r\nnestedIndex(\"keyD\")(\"keyE\").key2 = \"val2\"\r\n\r\n\r\nnestedIndex()                      // Map {\r\n                                   //   \"keyA\": Map {\r\n                                   //     \"keyB\": { key: \"val\" }\r\n                                   //     \"keyC\": { key: \"val\" }\r\n                                   //   }\r\n                                   //   \"keyD\": Map {\r\n                                   //     \"keyE\": { key1: \"val1\", key2: \"val2\" }\r\n                                   //   }\r\n                                   // }\r\n```\r\n\r\n\u003e Note: Depending on the underlying technology (maps / objects) this may yield slightly different results (all maps would be regular objects).\r\n\r\n\r\n## Contribute\r\n\r\nAll feedback is appreciated. Create a pull request or write an issue.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaximilianmairinger%2Fkeyindex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaximilianmairinger%2Fkeyindex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaximilianmairinger%2Fkeyindex/lists"}