# weak-id

> A utility to generate unique ids for weak references

Latest version **0.2.2** (published 2026-06-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install weak-id
pnpm add weak-id
yarn add weak-id
bun add weak-id
```

## Health

**Score 50/100 (C)** — status: active.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.2.2 |
| Published | 2026-06-19 |
| First published | 2025-12-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 4.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Andrea Giammarchi |
| Maintainers | webreflection |
| Keywords | weak, id, reference, finalization, registry |

## Links

- npm: https://www.npmjs.com/package/weak-id
- Repository: https://github.com/WebReflection/weak-id
- Homepage: https://github.com/WebReflection/weak-id#readme
- Issues: https://github.com/WebReflection/weak-id/issues
- npm.io page: https://npm.io/package/weak-id

## Dependencies (1)

- [@webreflection/utils](https://npm.io/package/@webreflection/utils.md) ^0.3.6

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.2.2 (latest) — 2026-06-19
- 0.2.1 — 2026-01-30
- 0.2.0 — 2026-01-07
- 0.1.1 — 2025-12-04
- 0.1.0 — 2025-12-04
- 0.0.1 — 2025-12-04
- 0.0.0 — 2025-12-04

## README

# weak-id

[![build status](https://github.com/WebReflection/weak-id/actions/workflows/node.js.yml/badge.svg)](https://github.com/WebReflection/weak-id/actions) [![Coverage Status](https://coveralls.io/repos/github/WebReflection/weak-id/badge.svg?branch=main)](https://coveralls.io/github/WebReflection/weak-id?branch=main)

<sup>**Social Media Photo by [Mario Amé](https://unsplash.com/@imperioame) on [Unsplash](https://unsplash.com/)**</sup>

A utility to generate unique ids for weak references.

```js
import weakID from 'weak-id';

const wid = weakID(id => {
  console.log(id, 'collected');
});

let obj = {};
let [id, unknown] = wid(obj);

console.assert(unknown);
console.assert(id === wid(obj)[0]);
console.assert(!wid(obj)[1]);

obj = null;
// the log will happen
```

To have a reliable `i32` value and ensure the next `id` will be actually a *32bit integer*, you can also directly import the `i32` variant:

```js
import i32 from 'weak-id/i32';

// initialize a function that
// will always return a 32bit integer
const next = i32();
// i32(42) to start from 42 as initial value

console.assert(next() === 0);
console.assert(next() === 1);
// ...
```

---
_Source: https://npm.io/package/weak-id · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
