@trap_stevo/legendarybuilderpronodejs-utilities
Version:
The legendary computational utility API that makes your application a legendary application. ~ Created by Steven Compton
63 lines (48 loc) • 1.13 kB
JavaScript
class OmniMap
{
constructor()
{
this.map = new Map();
}
set(key, value, args = {})
{
this.map.set(key, { value, reverseKey : key, ...args });
this.map.set(value, { value : key, reverseKey : value, ...args });
}
getData(key)
{
return this.map.get(key);
}
getKey(value)
{
const entry = this.map.get(value);
return entry ? entry.value : undefined;
}
get(key)
{
const entry = this.map.get(key);
return entry ? entry.value : undefined;
}
contains(keyOrValue)
{
return this.map.has(keyOrValue);
}
contents()
{
return this.map.entries();
}
get length()
{
return this.map.size / 2;
}
delete(key)
{
const entry = this.map.get(key);
if (entry)
{
this.map.delete(key);
this.map.delete(entry.value);
}
}
};
module.exports = OmniMap;