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

bim

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bim - npm Package Compare versions

Comparing version 1.3.0 to 1.3.1

8

dist/BiMap.js

@@ -21,5 +21,9 @@ "use strict";

_right.set(this, void 0);
__classPrivateFieldSet(this, _left, new Map(iterable));
__classPrivateFieldSet(this, _left, new Map());
__classPrivateFieldSet(this, _right, new Map());
for (const [k, v] of __classPrivateFieldGet(this, _left)) {
if (iterable === undefined) {
return;
}
for (const [k, v] of iterable) {
__classPrivateFieldGet(this, _left).set(k, v);
__classPrivateFieldGet(this, _right).set(v, k);

@@ -26,0 +30,0 @@ }

{
"name": "bim",
"version": "1.3.0",
"version": "1.3.1",
"description": "A bidirectional map based on the ES6 Map & WeakMap objects",

@@ -11,3 +11,2 @@ "main": "dist/index.js",

"build": "rm -rf dist && tsc",
"version": "npm run build",
"release": "np --yolo --no-publish"

@@ -14,0 +13,0 @@ },

@@ -8,5 +8,9 @@ import ReverseMap from './ReverseMap'

constructor(iterable?: Iterable<[K, V]>) {
this.#left = new Map<K, V>(iterable!)
this.#left = new Map<K, V>()
this.#right = new Map<V, K>()
for (const [k, v] of this.#left) {
if (iterable === undefined) {
return
}
for (const [k, v] of iterable) {
this.#left.set(k, v)
this.#right.set(v, k)

@@ -21,3 +25,3 @@ }

delete(key: K) {
delete(key: K): boolean {
const val = this.#left.get(key)!

@@ -31,23 +35,23 @@ if (!this.#right.has(val)) {

entries() {
entries(): IterableIterator<[K, V]> {
return this.#left.entries()
}
forEach(callbackfn: (value: V, index: K, map: Map<K, V>) => void, thisArg?: any) {
forEach(callbackfn: (value: V, index: K, map: Map<K, V>) => void, thisArg?: any): void {
this.#left.forEach(callbackfn, thisArg)
}
get(key: K) {
get(key: K): V | undefined {
return this.#left.get(key)
}
has(key: K) {
has(key: K): boolean {
return this.#left.has(key)
}
keys() {
keys(): IterableIterator<K> {
return this.#left.keys()
}
set(key: K, value: V) {
set(key: K, value: V): this {
const left = this.#left

@@ -68,7 +72,7 @@ const right = this.#right

get size() {
get size(): number {
return this.#left.size
}
values() {
values(): IterableIterator<V> {
return this.#left.values()

@@ -85,3 +89,3 @@ }

deleteValue(value: V) {
deleteValue(value: V): boolean {
const key = this.#right.get(value) as K

@@ -95,7 +99,7 @@ if (!this.#left.has(key)) {

getKey(value: V) {
getKey(value: V): K | undefined {
return this.#right.get(value)
}
hasValue(value: V) {
hasValue(value: V): boolean {
return this.#right.has(value)

@@ -102,0 +106,0 @@ }

@@ -19,3 +19,3 @@ import ReverseMap from './ReverseMap'

delete(key: K) {
delete(key: K): boolean {
const val = this.#left.get(key)!

@@ -29,11 +29,11 @@ if (!this.#right.has(val)) {

get(key: K) {
get(key: K): V | undefined {
return this.#left.get(key)
}
has(key: K) {
has(key: K): boolean {
return this.#left.has(key)
}
set(key: K, value: V) {
set(key: K, value: V): this {
const left = this.#left

@@ -58,3 +58,3 @@ const right = this.#right

deleteValue(value: V) {
deleteValue(value: V): boolean {
const key = this.#right.get(value)!

@@ -68,7 +68,7 @@ if (!this.#left.has(key)) {

getKey(value: V) {
getKey(value: V): K | undefined {
return this.#right.get(value)
}
hasValue(value: V) {
hasValue(value: V): boolean {
return this.#right.has(value)

@@ -75,0 +75,0 @@ }

@@ -9,2 +9,33 @@ import { WeakBiMap } from '../src'

it('should set correctly', () => {
const a = { a: 1 }
const b = { b: 2 }
const c = { c: 3 }
const d = { d: 4 }
const m = new WeakBiMap<{ [key: string]: number }, { [key: string]: number }>()
m.set(a, c)
m.set(b, d)
expect(m.get(a)).toBe(c)
expect(m.getKey(c)).toBe(a)
expect(m.get(b)).toBe(d)
expect(m.getKey(d)).toBe(b)
})
it('should accept array of entries', () => {
const a = { a: 1 }
const b = { b: 2 }
const c = { c: 3 }
const d = { d: 4 }
const m = new WeakBiMap<{ [key: string]: number }, { [key: string]: number }>([
[a, c],
[b, d],
])
expect(m.get(a)).toBe(c)
expect(m.getKey(c)).toBe(a)
expect(m.get(b)).toBe(d)
expect(m.getKey(d)).toBe(b)
})
it('should get & delete key correctly', () => {

@@ -11,0 +42,0 @@ const a = { a: 1 }

Sorry, the diff of this file is not supported yet

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