{"id":20514007,"url":"https://github.com/webreflection/indexed-values","last_synced_at":"2025-04-14T00:05:20.002Z","repository":{"id":57273434,"uuid":"403904095","full_name":"WebReflection/indexed-values","owner":"WebReflection","description":"An ever growing Set based utility to optimize JSON, IndexedDB, or postMessage.","archived":false,"fork":false,"pushed_at":"2021-09-22T08:55:24.000Z","size":60,"stargazers_count":21,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-12-31T15:24:57.258Z","etag":null,"topics":["indexeddb","json","postmessage"],"latest_commit_sha":null,"homepage":"https://webreflection.medium.com/optimizing-json-indexeddb-or-postmessage-698112860899","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/WebReflection.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}},"created_at":"2021-09-07T08:40:01.000Z","updated_at":"2024-11-03T10:16:46.000Z","dependencies_parsed_at":"2022-09-17T02:23:00.475Z","dependency_job_id":null,"html_url":"https://github.com/WebReflection/indexed-values","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Findexed-values","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Findexed-values/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Findexed-values/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Findexed-values/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WebReflection","download_url":"https://codeload.github.com/WebReflection/indexed-values/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232797486,"owners_count":18577981,"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":["indexeddb","json","postmessage"],"created_at":"2024-11-15T21:14:19.332Z","updated_at":"2025-01-06T23:13:05.845Z","avatar_url":"https://github.com/WebReflection.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# indexed-values\n\n[![build status](https://github.com/WebReflection/indexed-values/actions/workflows/node.js.yml/badge.svg)](https://github.com/WebReflection/indexed-values/actions) [![Coverage Status](https://coveralls.io/repos/github/WebReflection/indexed-values/badge.svg?branch=main)](https://coveralls.io/github/WebReflection/indexed-values?branch=main)\n\n\u003csup\u003e**Social Media Photo by [Alexander Sinn](https://unsplash.com/@swimstaralex) on [Unsplash](https://unsplash.com/)**\u003c/sup\u003e\n\n[Related Blog Post](https://webreflection.medium.com/optimizing-json-indexeddb-or-postmessage-698112860899).\n\n### Example\n\n```js\nimport {IndexedValues} from 'indexed-values';\n\n// create a Set of unique values\nconst main = new IndexedValues;\n\n// derive a set\nconst sub1 = main.bindValues([\"a\", \"b\", \"c\"]);\nconst sub2 = main.bindValues([\"a\"]);\n\n// derived sets can make the main Set grow\nif (!sub2.has(\"d\"))\n  sub2.add(\"d\");\n\n// {\"main\":[\"a\",\"b\",\"c\",\"d\"],\"data\":[[0,1,2],[0,3]]}\nconsole.log(JSON.stringify({\n  main,\n  data: [sub1, sub2]\n}));\n```\n\n## API\n\nThe `IndexedValues` constructor extends the `Set` class, but it's a facade with the following peculiarities:\n\n  * it is not posible to `delete` a single value, or `clear` the instance. `IndexedValues` instances are ever-growing\n  * `.toJSON()` method returns an array of values held internally\n  * `.valueOf()` method returns a real `Set` that can resist `postMessage`, or be stored directly as `IndexedDB`\n  * `.bindValues(values = [])` returns a `Set` that can contain, add, or remove, any value. Added values will be reflected in the `IndexedValues` instance that created the bound `Set`.\n  * `.bindIndexes(indexes = [])` is like `.bindValues()` but uses indexes instead, to initialize the derived `Set`. This is mostly useful for revival.\n  * `.mapKeys(entries = [])` returns a `Map` where *keys* are derived from the `IndexedValues`. Added keys that are not known in the `IndexedValues` source, will be automatically added as part of the `Set`. Once serialized as *JSON*, these maps will represent all keys as indexes, because indeed these maps never hold keys as values, these hold keys as indexes.\n  * `.mapEntries(entries = [])` is the revival counter-part of `.mapKeys()`. It returns a *map* with keys revived from the `IndexedValues` instance.\n  * `.fromIndexes(indexes)` can revive right away `Set` instances, upgrading their prototype. This is a *quick and dirty* `.bindIndexes()` equivalent, available for performance reasons.\n  * `.fromEntries(entries)` can revive right away `Map` instances, upgrading their prototype. This is a *quick and dirty* `.mapEntries()` equivalent, available for performance reasons.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebreflection%2Findexed-values","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebreflection%2Findexed-values","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebreflection%2Findexed-values/lists"}