reference-map
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -1,1 +0,1 @@ | ||
{"/home/null/code/referenceMap/index.js":{"path":"/home/null/code/referenceMap/index.js","statementMap":{"0":{"start":{"line":1,"column":0},"end":{"line":64,"column":1}},"1":{"start":{"line":6,"column":4},"end":{"line":6,"column":18}},"2":{"start":{"line":16,"column":4},"end":{"line":16,"column":34}},"3":{"start":{"line":25,"column":16},"end":{"line":25,"column":30}},"4":{"start":{"line":26,"column":4},"end":{"line":28,"column":5}},"5":{"start":{"line":27,"column":6},"end":{"line":27,"column":42}},"6":{"start":{"line":29,"column":4},"end":{"line":29,"column":14}},"7":{"start":{"line":38,"column":4},"end":{"line":38,"column":25}},"8":{"start":{"line":45,"column":4},"end":{"line":45,"column":18}},"9":{"start":{"line":53,"column":4},"end":{"line":53,"column":27}},"10":{"start":{"line":61,"column":16},"end":{"line":61,"column":30}},"11":{"start":{"line":62,"column":4},"end":{"line":62,"column":28}}},"fnMap":{"0":{"name":"(anonymous_0)","decl":{"start":{"line":5,"column":2},"end":{"line":5,"column":3}},"loc":{"start":{"line":5,"column":17},"end":{"line":7,"column":3}},"line":5},"1":{"name":"(anonymous_1)","decl":{"start":{"line":15,"column":2},"end":{"line":15,"column":3}},"loc":{"start":{"line":15,"column":12},"end":{"line":17,"column":3}},"line":15},"2":{"name":"(anonymous_2)","decl":{"start":{"line":24,"column":2},"end":{"line":24,"column":3}},"loc":{"start":{"line":24,"column":12},"end":{"line":30,"column":3}},"line":24},"3":{"name":"(anonymous_3)","decl":{"start":{"line":37,"column":2},"end":{"line":37,"column":3}},"loc":{"start":{"line":37,"column":15},"end":{"line":39,"column":3}},"line":37},"4":{"name":"(anonymous_4)","decl":{"start":{"line":44,"column":2},"end":{"line":44,"column":3}},"loc":{"start":{"line":44,"column":11},"end":{"line":46,"column":3}},"line":44},"5":{"name":"(anonymous_5)","decl":{"start":{"line":52,"column":2},"end":{"line":52,"column":3}},"loc":{"start":{"line":52,"column":14},"end":{"line":54,"column":3}},"line":52},"6":{"name":"(anonymous_6)","decl":{"start":{"line":60,"column":2},"end":{"line":60,"column":3}},"loc":{"start":{"line":60,"column":12},"end":{"line":63,"column":3}},"line":60}},"branchMap":{"0":{"loc":{"start":{"line":26,"column":4},"end":{"line":28,"column":5}},"type":"if","locations":[{"start":{"line":26,"column":4},"end":{"line":28,"column":5}},{"start":{"line":26,"column":4},"end":{"line":28,"column":5}}],"line":26}},"s":{"0":1,"1":1,"2":2,"3":4,"4":4,"5":2,"6":2,"7":1,"8":1,"9":1,"10":2,"11":2},"f":{"0":1,"1":2,"2":4,"3":1,"4":1,"5":1,"6":2},"b":{"0":[2,2]},"_coverageSchema":"332fd63041d2c1bcb487cc26dd0d5f7d97098a6c","hash":"dc2c534631bc44935676d095c93dedca20a26eff"}} | ||
{"/home/null/code/referenceMap/index.js":{"path":"/home/null/code/referenceMap/index.js","statementMap":{"0":{"start":{"line":1,"column":0},"end":{"line":65,"column":1}},"1":{"start":{"line":6,"column":4},"end":{"line":6,"column":18}},"2":{"start":{"line":16,"column":4},"end":{"line":16,"column":34}},"3":{"start":{"line":26,"column":16},"end":{"line":26,"column":30}},"4":{"start":{"line":27,"column":4},"end":{"line":29,"column":5}},"5":{"start":{"line":28,"column":6},"end":{"line":28,"column":42}},"6":{"start":{"line":30,"column":4},"end":{"line":30,"column":14}},"7":{"start":{"line":39,"column":4},"end":{"line":39,"column":25}},"8":{"start":{"line":46,"column":4},"end":{"line":46,"column":18}},"9":{"start":{"line":54,"column":4},"end":{"line":54,"column":27}},"10":{"start":{"line":62,"column":16},"end":{"line":62,"column":30}},"11":{"start":{"line":63,"column":4},"end":{"line":63,"column":28}}},"fnMap":{"0":{"name":"(anonymous_0)","decl":{"start":{"line":5,"column":2},"end":{"line":5,"column":3}},"loc":{"start":{"line":5,"column":17},"end":{"line":7,"column":3}},"line":5},"1":{"name":"(anonymous_1)","decl":{"start":{"line":15,"column":2},"end":{"line":15,"column":3}},"loc":{"start":{"line":15,"column":18},"end":{"line":17,"column":3}},"line":15},"2":{"name":"(anonymous_2)","decl":{"start":{"line":25,"column":2},"end":{"line":25,"column":3}},"loc":{"start":{"line":25,"column":18},"end":{"line":31,"column":3}},"line":25},"3":{"name":"(anonymous_3)","decl":{"start":{"line":38,"column":2},"end":{"line":38,"column":3}},"loc":{"start":{"line":38,"column":15},"end":{"line":40,"column":3}},"line":38},"4":{"name":"(anonymous_4)","decl":{"start":{"line":45,"column":2},"end":{"line":45,"column":3}},"loc":{"start":{"line":45,"column":11},"end":{"line":47,"column":3}},"line":45},"5":{"name":"(anonymous_5)","decl":{"start":{"line":53,"column":2},"end":{"line":53,"column":3}},"loc":{"start":{"line":53,"column":14},"end":{"line":55,"column":3}},"line":53},"6":{"name":"(anonymous_6)","decl":{"start":{"line":61,"column":2},"end":{"line":61,"column":3}},"loc":{"start":{"line":61,"column":12},"end":{"line":64,"column":3}},"line":61}},"branchMap":{"0":{"loc":{"start":{"line":27,"column":4},"end":{"line":29,"column":5}},"type":"if","locations":[{"start":{"line":27,"column":4},"end":{"line":29,"column":5}},{"start":{"line":27,"column":4},"end":{"line":29,"column":5}}],"line":27},"1":{"loc":{"start":{"line":27,"column":8},"end":{"line":27,"column":63}},"type":"binary-expr","locations":[{"start":{"line":27,"column":8},"end":{"line":27,"column":25}},{"start":{"line":27,"column":30},"end":{"line":27,"column":34}},{"start":{"line":27,"column":38},"end":{"line":27,"column":62}}],"line":27}},"s":{"0":1,"1":1,"2":3,"3":6,"4":6,"5":3,"6":3,"7":1,"8":1,"9":1,"10":2,"11":2},"f":{"0":1,"1":3,"2":6,"3":1,"4":1,"5":1,"6":2},"b":{"0":[3,3],"1":[6,4,2]},"_coverageSchema":"332fd63041d2c1bcb487cc26dd0d5f7d97098a6c","hash":"127e509bcbcb68b344bd7eb04e5b31a45fb6c777"}} |
@@ -15,3 +15,3 @@ module.exports = class ReferanceMap { | ||
*/ | ||
add (obj) { | ||
add (obj, type) { | ||
return this._map.push(obj) - 1 | ||
@@ -23,7 +23,8 @@ } | ||
* @param {integer} ref | ||
* @param {Object} type - optional, a contructor that the retreived object should be an instance of | ||
* @return {*} | ||
*/ | ||
get (ref) { | ||
get (ref, type) { | ||
const obj = this._map[ref] | ||
if (obj === undefined) { | ||
if (obj === undefined || (type && type !== obj.constructor)) { | ||
throw new Error('invalid referance') | ||
@@ -30,0 +31,0 @@ } |
{ | ||
"name": "reference-map", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "This is a simple determinstic map that maps POJOs to an integer", | ||
@@ -30,3 +30,3 @@ "main": "index.js", | ||
"devDependencies": { | ||
"coveralls": "^2.13.1", | ||
"coveralls": "^3.0.0", | ||
"istanbul": "^1.1.0-alpha.1", | ||
@@ -33,0 +33,0 @@ "standard": "^10.0.0", |
@@ -7,3 +7,3 @@ [![NPM Package](https://img.shields.io/npm/v/reference-map.svg?style=flat-square)](https://www.npmjs.org/package/reference-map) | ||
# install | ||
# install | ||
`npm install referanceMap` | ||
@@ -10,0 +10,0 @@ |
@@ -5,3 +5,3 @@ const tape = require('tape') | ||
tape('referance mapping', t => { | ||
t.plan(9) | ||
t.plan(11) | ||
const referanceMap = new ReferanceMap() | ||
@@ -40,2 +40,11 @@ const obj1 = {} | ||
} | ||
const aMap = new Map() | ||
const ref3 = referanceMap.add(aMap) | ||
t.equals(referanceMap.get(ref3, Map), aMap) | ||
try { | ||
referanceMap.get(ref3, Set) | ||
} catch (e) { | ||
t.true(true, 'should throw if wrong type') | ||
} | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51232
513