{"id":20513892,"url":"https://github.com/webreflection/not-so-weak","last_synced_at":"2025-04-14T00:03:07.829Z","repository":{"id":65507971,"uuid":"593556043","full_name":"WebReflection/not-so-weak","owner":"WebReflection","description":"Iterable WeakMap, WeakSet and WeakValue","archived":false,"fork":false,"pushed_at":"2023-07-14T13:52:47.000Z","size":55,"stargazers_count":37,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-27T14:11:17.155Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","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":"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}},"created_at":"2023-01-26T09:54:54.000Z","updated_at":"2024-11-04T06:19:28.000Z","dependencies_parsed_at":"2024-02-01T16:45:16.500Z","dependency_job_id":null,"html_url":"https://github.com/WebReflection/not-so-weak","commit_stats":{"total_commits":12,"total_committers":1,"mean_commits":12.0,"dds":0.0,"last_synced_commit":"f84bf6bd9ec6e85bbf3f31141a165018add806ab"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fnot-so-weak","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fnot-so-weak/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fnot-so-weak/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fnot-so-weak/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WebReflection","download_url":"https://codeload.github.com/WebReflection/not-so-weak/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248799936,"owners_count":21163404,"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-15T21:13:44.988Z","updated_at":"2025-04-14T00:03:07.785Z","avatar_url":"https://github.com/WebReflection.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Not So Weak\n\n[![build status](https://github.com/WebReflection/not-so-weak/actions/workflows/node.js.yml/badge.svg)](https://github.com/WebReflection/not-so-weak/actions) [![Coverage Status](https://coveralls.io/repos/github/WebReflection/not-so-weak/badge.svg?branch=main)](https://coveralls.io/github/WebReflection/not-so-weak?branch=main)\n\n\u003csup\u003e**Social Media Photo by [Pete Nuij](https://unsplash.com/@pete_nuij) on [Unsplash](https://unsplash.com/)**\u003c/sup\u003e\n\nIterable [WeakMap](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap) (*WKey*) and [WeakSet](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet) (*WSet*) through [FinalizationRegistry](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry) and [WeakRef](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef) primitives, reimplementing also the [WeakValue](https://github.com/WebReflection/weak-value#readme) (*WValue*) module, including the optional *callback* for collected values.\n\n```js\n// const {WSet, WKey, WValue} = require('not-so-weak');\nimport {WSet, WKey, WValue} from 'not-so-weak';\n\n// class WSet\u003cT extends object\u003e extends WeakSet implements Set {}\n// class WKey\u003cK extends object, V\u003e extends WeakMap implements Map {}\n// class WValue\u003cK, V extends object\u003e extends Map {}\n\n// node --expose-gc example\nconst ws = new WSet([{}]);\nconst wm = new WKey([[{}, 'value']]);\n\nconst wv = new WValue;\nwv.set('value', {}, function (key) {\n  console.assert(this === wv);\n  console.assert(key === 'value');\n  console.log(key, 'value collected');\n});\n\nconsole.assert(ws.size === 1);\nconsole.assert(wm.size === 1);\nconsole.assert([...wm.values()][0] === 'value');\nconsole.assert([...wv.keys()][0] === 'value');\n\nsetTimeout(() =\u003e {\n  gc();\n  console.assert(ws.size === 0);\n  console.assert(wm.size === 0);\n  console.assert(wv.size === 0);\n});\n```\n\n### Suitable For\n\n  * Weak key/value based state/store\n  * Server Side related tasks that can't bother with manual removal of weakly referenced entries\n  * every case where you end up swapping to `Map` or `Set` because you realize you cannot iterate over their *Weak* counterpart\n  * every case where you think there's a memory leak due possibly missing `weakThing.delete(ref)` operations\n\n### Not Suitable For\n\n  * raw performance or benchmarks against `Map` or `Set`\n  * every case where `weakThing.delete(ref)` is already handled by the library or framework logic\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebreflection%2Fnot-so-weak","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebreflection%2Fnot-so-weak","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebreflection%2Fnot-so-weak/lists"}