# primitive-pool

> Pool of objects for primitives. (Make WeakMap accept primitive keys)

Latest version **2.0.0** (published 2022-11-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install primitive-pool
pnpm add primitive-pool
yarn add primitive-pool
bun add primitive-pool
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2022-11-23 |
| First published | 2018-06-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Dmitry Yv |
| Maintainers | dfcreative, dy |
| Keywords | primitive, primitives, weakmap, pool, keys, object, primitive-object, singleton |

## Links

- npm: https://www.npmjs.com/package/primitive-pool
- Repository: https://github.com/dy/primitive-pool
- Homepage: https://github.com/dy/primitive-pool#readme
- Issues: https://github.com/dy/primitive-pool/issues
- npm.io page: https://npm.io/package/primitive-pool

## Recent versions

- 2.0.0 (latest) — 2022-11-23
- 1.1.0 — 2018-10-25
- 1.0.0 — 2018-06-23

## README

# primitive-pool [![unstable](https://img.shields.io/badge/stability-unstable-green.svg)](http://github.com/badges/stability-badges) [![Build Status](https://img.shields.io/travis/dy/primitive-pool.svg)](https://travis-ci.org/dy/primitive-pool)

Get object for a primitive value. Useful to make WeakMap store strings/numbers and other primitives.

## Usage

[![npm install primitive-pool](https://nodei.co/npm/primitive-pool.png?mini=true)](https://npmjs.org/package/primitive-pool/)


```js
import p from 'primitive-pool'

let map = new WeakMap()

map.set(p('abc'), 123)
map.get(p('abc')) // 123

map.set(p(null), 789)
map.get(p(null)) // 789

map.set(p(123), 'abc')
map.get(p(123)) // 'abc'

// non-primitives are stored as is
let a = {}
map.set(p(a), 'xyz')
map.get(a) // 'xyz'
```

Alternative can be done via weak refs.

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