Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

reference-map

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reference-map - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

.nyc_output/3cf4fc6cbcff155bcc6e427a9d63ca5e.json

43

API.md
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
# constructor
### Table of Contents
[index.js:5-7](https://github.com/wanderer/referanceMap/blob/e1f2c200e1e82a761064a31fb0aebf800a54e6ea/index.js#L5-L7 "Source code on GitHub")
- [constructor](#constructor)
- [add](#add)
- [get](#get)
- [delete](#delete)
- [clear](#clear)
- [size](#size)
- [has](#has)
## constructor
[index.js:5-7](https://github.com/wanderer/referanceMap/blob/be536d78f588a72a29acd71fb3ab0fa35b0789eb/index.js#L5-L7 "Source code on GitHub")
Handle mapping arbitary JS object to ints
# add
## add
[index.js:15-17](https://github.com/wanderer/referanceMap/blob/e1f2c200e1e82a761064a31fb0aebf800a54e6ea/index.js#L15-L17 "Source code on GitHub")
[index.js:16-18](https://github.com/wanderer/referanceMap/blob/be536d78f588a72a29acd71fb3ab0fa35b0789eb/index.js#L16-L18 "Source code on GitHub")

@@ -19,8 +29,9 @@ Adds an object to the referance map returning an int to be used as a

- `obj` **any**
- `type` **any** optional
Returns **integer**
# get
## get
[index.js:24-30](https://github.com/wanderer/referanceMap/blob/e1f2c200e1e82a761064a31fb0aebf800a54e6ea/index.js#L24-L30 "Source code on GitHub")
[index.js:26-32](https://github.com/wanderer/referanceMap/blob/be536d78f588a72a29acd71fb3ab0fa35b0789eb/index.js#L26-L32 "Source code on GitHub")

@@ -32,8 +43,10 @@ gets a POJO given a refernce as an int

- `ref` **integer**
- `typeCheck`
- `type` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** optional
Returns **any**
# delete
## delete
[index.js:37-39](https://github.com/wanderer/referanceMap/blob/e1f2c200e1e82a761064a31fb0aebf800a54e6ea/index.js#L37-L39 "Source code on GitHub")
[index.js:39-41](https://github.com/wanderer/referanceMap/blob/be536d78f588a72a29acd71fb3ab0fa35b0789eb/index.js#L39-L41 "Source code on GitHub")

@@ -44,16 +57,16 @@ deletes an object given a referance as an int

- `ref`
- `integer`
- `ref`
Returns **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** whether or not the object was deleted
# clear
## clear
[index.js:44-46](https://github.com/wanderer/referanceMap/blob/e1f2c200e1e82a761064a31fb0aebf800a54e6ea/index.js#L44-L46 "Source code on GitHub")
[index.js:46-48](https://github.com/wanderer/referanceMap/blob/be536d78f588a72a29acd71fb3ab0fa35b0789eb/index.js#L46-L48 "Source code on GitHub")
clears the referance map of a objects
# size
## size
[index.js:52-54](https://github.com/wanderer/referanceMap/blob/e1f2c200e1e82a761064a31fb0aebf800a54e6ea/index.js#L52-L54 "Source code on GitHub")
[index.js:54-56](https://github.com/wanderer/referanceMap/blob/be536d78f588a72a29acd71fb3ab0fa35b0789eb/index.js#L54-L56 "Source code on GitHub")

@@ -64,5 +77,5 @@ returns the number of items in the refernace map

# has
## has
[index.js:60-63](https://github.com/wanderer/referanceMap/blob/e1f2c200e1e82a761064a31fb0aebf800a54e6ea/index.js#L60-L63 "Source code on GitHub")
[index.js:62-65](https://github.com/wanderer/referanceMap/blob/be536d78f588a72a29acd71fb3ab0fa35b0789eb/index.js#L62-L65 "Source code on GitHub")

@@ -69,0 +82,0 @@ tests wether a given referance is valid or not

@@ -13,6 +13,7 @@ module.exports = class ReferanceMap {

* @param {*} obj
* @param {*} type - optional
* @return {integer}
*/
add (obj, type) {
return this._map.push(obj) - 1
return this._map.push({obj, type}) - 1
}

@@ -23,8 +24,8 @@

* @param {integer} ref
* @param {Object} type - optional, a contructor that the retreived object should be an instance of
* @param {Object} type - optional
* @return {*}
*/
get (ref, type) {
const obj = this._map[ref]
if (obj === undefined || (type && type !== obj.constructor)) {
get (ref, typeCheck) {
const {obj, type} = this._map[ref]
if (obj === undefined || (typeCheck && type !== typeCheck)) {
throw new Error('invalid referance')

@@ -31,0 +32,0 @@ }

{
"name": "reference-map",
"version": "1.1.0",
"version": "1.2.0",
"description": "This is a simple determinstic map that maps POJOs to an integer",
"main": "index.js",
"scripts": {
"coverage": "node --expose-wasm --harmony ./node_modules/istanbul/lib/cli.js cover ./tests/index.js",
"coveralls": "npm run coverage && coveralls <coverage/lcov.info",
"coveralls": "npm run coverage && nyc report --reporter=text-lcov | coveralls",
"coverage": "nyc npm test",
"lint": "standard",

@@ -31,6 +31,6 @@ "test": "node --expose-wasm --harmony ./tests/index.js"

"coveralls": "^3.0.0",
"istanbul": "^1.1.0-alpha.1",
"standard": "^10.0.0",
"tape": "^4.6.3"
"nyc": "^11.4.1",
"standard": "^10.0.3",
"tape": "^4.8.0"
}
}

@@ -17,3 +17,3 @@ [![NPM Package](https://img.shields.io/npm/v/reference-map.svg?style=flat-square)](https://www.npmjs.org/package/reference-map)

[index.js:5-7](https://github.com/wanderer/referanceMap/blob/e1f2c200e1e82a761064a31fb0aebf800a54e6ea/index.js#L5-L7 "Source code on GitHub")
[index.js:5-7](https://github.com/wanderer/referanceMap/blob/be536d78f588a72a29acd71fb3ab0fa35b0789eb/index.js#L5-L7 "Source code on GitHub")

@@ -24,3 +24,3 @@ Handle mapping arbitary JS object to ints

[index.js:15-17](https://github.com/wanderer/referanceMap/blob/e1f2c200e1e82a761064a31fb0aebf800a54e6ea/index.js#L15-L17 "Source code on GitHub")
[index.js:16-18](https://github.com/wanderer/referanceMap/blob/be536d78f588a72a29acd71fb3ab0fa35b0789eb/index.js#L16-L18 "Source code on GitHub")

@@ -33,2 +33,3 @@ Adds an object to the referance map returning an int to be used as a

- `obj` **any**
- `type` **any** optional

@@ -39,3 +40,3 @@ Returns **integer**

[index.js:24-30](https://github.com/wanderer/referanceMap/blob/e1f2c200e1e82a761064a31fb0aebf800a54e6ea/index.js#L24-L30 "Source code on GitHub")
[index.js:26-32](https://github.com/wanderer/referanceMap/blob/be536d78f588a72a29acd71fb3ab0fa35b0789eb/index.js#L26-L32 "Source code on GitHub")

@@ -47,2 +48,4 @@ gets a POJO given a refernce as an int

- `ref` **integer**
- `typeCheck`
- `type` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** optional

@@ -53,3 +56,3 @@ Returns **any**

[index.js:37-39](https://github.com/wanderer/referanceMap/blob/e1f2c200e1e82a761064a31fb0aebf800a54e6ea/index.js#L37-L39 "Source code on GitHub")
[index.js:39-41](https://github.com/wanderer/referanceMap/blob/be536d78f588a72a29acd71fb3ab0fa35b0789eb/index.js#L39-L41 "Source code on GitHub")

@@ -60,4 +63,4 @@ deletes an object given a referance as an int

- `ref`
- `integer`
- `ref`

@@ -68,3 +71,3 @@ Returns **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** whether or not the object was deleted

[index.js:44-46](https://github.com/wanderer/referanceMap/blob/e1f2c200e1e82a761064a31fb0aebf800a54e6ea/index.js#L44-L46 "Source code on GitHub")
[index.js:46-48](https://github.com/wanderer/referanceMap/blob/be536d78f588a72a29acd71fb3ab0fa35b0789eb/index.js#L46-L48 "Source code on GitHub")

@@ -75,3 +78,3 @@ clears the referance map of a objects

[index.js:52-54](https://github.com/wanderer/referanceMap/blob/e1f2c200e1e82a761064a31fb0aebf800a54e6ea/index.js#L52-L54 "Source code on GitHub")
[index.js:54-56](https://github.com/wanderer/referanceMap/blob/be536d78f588a72a29acd71fb3ab0fa35b0789eb/index.js#L54-L56 "Source code on GitHub")

@@ -84,3 +87,3 @@ returns the number of items in the refernace map

[index.js:60-63](https://github.com/wanderer/referanceMap/blob/e1f2c200e1e82a761064a31fb0aebf800a54e6ea/index.js#L60-L63 "Source code on GitHub")
[index.js:62-65](https://github.com/wanderer/referanceMap/blob/be536d78f588a72a29acd71fb3ab0fa35b0789eb/index.js#L62-L65 "Source code on GitHub")

@@ -96,2 +99,4 @@ tests wether a given referance is valid or not

# LICENSE
[MPL-2.0](https://tldrlegal.com/license/mozilla-public-license-2.0-(mpl-2))
[MPL-2.0][LICENSE]
[LICENSE]: https://tldrlegal.com/license/mozilla-public-license-2.0-(mpl-2)

@@ -41,6 +41,6 @@ const tape = require('tape')

const aMap = new Map()
const ref3 = referanceMap.add(aMap)
t.equals(referanceMap.get(ref3, Map), aMap)
const ref3 = referanceMap.add(aMap, 'set')
t.equals(referanceMap.get(ref3, 'set'), aMap)
try {
referanceMap.get(ref3, Set)
referanceMap.get(ref3, 'lol')
} catch (e) {

@@ -47,0 +47,0 @@ t.true(true, 'should throw if wrong type')

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc