Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/aleclarson/weak-map
- Owner: aleclarson
- License: mit
- Created: 2015-04-10T10:01:27.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-12-05T16:53:37.000Z (almost 6 years ago)
- Last Synced: 2024-10-13T04:06:01.429Z (24 days ago)
- Language: CoffeeScript
- Homepage:
- Size: 10.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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
```