# privates

> Set and get private variables with weak maps

Latest version **1.0.1** (published 2016-01-22) · CC0-1.0 license · 0 weekly downloads

## Install

```sh
npm install privates
pnpm add privates
yarn add privates
bun add privates
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2016-01-22 |
| First published | 2016-01-22 |
| Weekly downloads | 0 |
| License | CC0-1.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Shawn Allen |
| Maintainers | shawnbot |
| Keywords | private, weak, map |

## Links

- npm: https://www.npmjs.com/package/privates
- Repository: https://github.com/shawnbot/privates
- Homepage: https://github.com/shawnbot/privates#readme
- Issues: https://github.com/shawnbot/privates/issues
- npm.io page: https://npm.io/package/privates

## Dependencies (1)

- [weakmap](https://npm.io/package/weakmap.md) 0.0.6

## Recent versions

- 1.0.1 (latest) — 2016-01-22

## README

# privates
JavaScript doesn't provide any language-level means to make object properties
private. This Node module:

1. Allows you to associate _pseudo-private_ arbitrary key/value pairs with any
   object without polluting its properties.
1. Minimizes memory overhead by using [WeakMap]s, which allow keys to be garbage
   collected once they're no longer referenced.

```js
var privates = require('privates');

var obj = {x: 1};
privates.set(obj, 'y', 2);

assert.equal(obj.y, undefined);
assert.equal(privates.get(obj, 'y'), 2);
```

## Usage
Install it with [npm](https://npmjs.org):


```sh
npm install privates
```

Then require it like so:

```js
var privates = require('privates');
```

The module exports the following methods:

### <a name="set"></a> `set(owner, key, value)`
Creates a private key/value pair associated with the `owner` object.

**Note:** The `key` will always be coerced to a string, because the internal
map for each `owner` object is simply an `Object` literal.

```js
privates.set(obj, 1, 'foo');
privates.get(obj, '1'); // === 'foo'
```

### <a name="get"></a> `get(owner, key)`
Returns the value of named `key` associated with the `owner` object by calling
[set(owner, key)](#set).

### <a name="delete"></a> `delete(owner, key)`
Deletes the value of named `key` associated with the `owner` object.

### <a name="deleteAll"></a> `deleteAll(owner)`
Removes all of the values associated with the `owner` object.


[WeakMap]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap

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