Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/aleclarson/weak-map

A weak map for the browser and Node.
https://github.com/aleclarson/weak-map

Last synced: 19 days ago
JSON representation

A weak map for the browser and Node.

Awesome Lists containing this project

README

        

# weak-map v1.0.1 [![frozen](http://badges.github.io/stability-badges/dist/frozen.svg)](http://github.com/badges/stability-badges)

A CoffeeScript version of [this `WeakMap` shim](https://github.com/webcomponents/webcomponentsjs/blob/master/src/WeakMap/WeakMap.js) + some wonderful tweaks by yours truly.

```sh
npm install --save aleclarson/weak-map#1.0.1
```

 

usage
-----

```CoffeeScript
WeakMap = require "weak-map"
map = WeakMap()
obj = {}
```

#### Get and set values

```CoffeeScript
map.set obj, "foo", true
map.get obj, "foo"
```

-

#### Get and set nested values

```CoffeeScript
map.set obj, "foo.bar.zen", true
map.get obj, "foo.bar.zen"
```

-

#### Get and set the whole storage object

```CoffeeScript
map.get obj
map.set obj, "any data type works fine"
```

-

#### Check if a value exists

```CoffeeScript
map.has obj
map.has obj, "foo"
map.has obj, "foo.bar"
```

-

#### Remove a value from existence

```CoffeeScript
map.remove obj
map.remove obj, "foo"
map.remove obj, "foo.bar"
```

 

changelog
---------

#### 1.0.1

  
**\+**
Support key arguments for all methods!

  
**\+**
Support keys with dot-syntax (eg: "foo.bar")!

#### 1.0.0

  
**\+**
Works in both the browser and Node!

  
**\+**
`module.exports` now equals `WeakMap`.

  
**\+**
`window.WeakMap` no longer equals `WeakMap` (if `window.WeakMap` doesn't already exist).

  
**\+**
The `new` keyword is no longer needed when constructing a `WeakMap`.

  
**\+**
`WeakMap::set` now returns the passed value (rather than the `WeakMap` instance).

  
**\+**
`WeakMap.name` now equals `"WeakMap"`.

 

tests
-----

All tests are passing! Find out for yourself:

```sh
npm install -g jasmine-node
npm test
```