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.1.2 to 1.2.0

.eslintignore

22

package.json
{
"name": "bim",
"version": "1.1.2",
"version": "1.2.0",
"description": "A bidirectional map based on the ES6 Map & WeakMap objects",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "rm -rf lib && tsc",
"build-publish": "sh build/publish.sh"
"test": "jest --no-cache",
"lint": "eslint './src/**/*.ts'",
"build": "rm -rf dist && tsc",
"version": "npm run build",
"release": "np --yolo --no-publish"
},

@@ -26,4 +28,10 @@ "repository": {

"devDependencies": {
"typescript": "^2.6.1"
"@calipsa/eslint-config-typescript": "^1.6.0",
"@types/jest": "^25.2.1",
"eslint": "^6.8.0",
"jest": "^25.4.0",
"np": "^6.2.2",
"ts-jest": "^25.4.0",
"typescript": "^3.8.3"
}
}

@@ -51,2 +51,2 @@ # bim

[david-dm-dev-url]:https://david-dm.org/inker/bim#info=devDependencies
[david-dm-dev-image]:https://david-dm.org/inker/bim/dev-status.svg
[david-dm-dev-image]:https://david-dm.org/inker/bim/dev-status.svg
export default class BiMap<K, V> implements Map<K, V> {
private left: Map<K, V>
private right: Map<V, K>
#left: Map<K, V>
#right: Map<V, K>
constructor(iterable?: Iterable<[K, V]>) {
this.left = new Map<K, V>(iterable as Iterable<[K, V]>)
this.right = new Map<V, K>()
for (const [k, v] of this.left) {
this.right.set(v, k)
}
this.#left = new Map<K, V>(iterable as Iterable<[K, V]>)
this.#right = new Map<V, K>()
for (const [k, v] of this.#left) {
this.#right.set(v, k)
}
}
clear(): void {
this.left.clear()
this.right.clear()
this.#left.clear()
this.#right.clear()
}
delete(key: K): boolean {
const val = this.left.get(key) as V
if (!this.right.has(val)) {
return false
}
this.right.delete(val)
return this.left.delete(key)
const val = this.#left.get(key) as V
if (!this.#right.has(val)) {
return false
}
this.#right.delete(val)
return this.#left.delete(key)
}
entries(): IterableIterator<[K, V]> {
return this.left.entries()
return this.#left.entries()
}
forEach(callbackfn: (value: V, index: K, map: Map<K, V>) => void, thisArg?: any): void {
this.left.forEach(callbackfn, thisArg)
this.#left.forEach(callbackfn, thisArg)
}
get(key: K): V | undefined {
return this.left.get(key)
return this.#left.get(key)
}
has(key: K): boolean {
return this.left.has(key)
return this.#left.has(key)
}
keys(): IterableIterator<K> {
return this.left.keys()
return this.#left.keys()
}
set(key: K, value: V): this {
const { left, right } = this
const oldVal = left.get(key) as V
const oldKey = right.get(value) as K
if (left.has(key)) {
right.delete(oldVal)
}
if (right.has(value)) {
left.delete(oldKey)
}
left.set(key, value)
right.set(value, key)
return this
const left = this.#left
const right = this.#right
const oldVal = left.get(key) as V
const oldKey = right.get(value) as K
if (left.has(key)) {
right.delete(oldVal)
}
if (right.has(value)) {
left.delete(oldKey)
}
left.set(key, value)
right.set(value, key)
return this
}
get size(): number {
return this.left.size
return this.#left.size
}
values(): IterableIterator<V> {
return this.left.values()
return this.#left.values()
}
[Symbol.iterator]() {
return this.left[Symbol.iterator]()
return this.#left[Symbol.iterator]()
}
get [Symbol.toStringTag]() {
return this.left[Symbol.toStringTag]
return this.#left[Symbol.toStringTag]
}
deleteValue(value: V): boolean {
const key = this.right.get(value) as K
if (!this.left.has(key)) {
return false
}
this.left.delete(key)
return this.right.delete(value)
const key = this.#right.get(value) as K
if (!this.#left.has(key)) {
return false
}
this.#left.delete(key)
return this.#right.delete(value)
}
getKey(value: V): K | undefined {
return this.right.get(value)
return this.#right.get(value)
}
hasValue(value: V): boolean {
return this.right.has(value)
return this.#right.has(value)
}
}
export default class WeakBiMap<K extends object, V extends object> implements WeakMap<K, V> {
private left: WeakMap<K, V>
private right: WeakMap<V, K>
#left: WeakMap<K, V>
#right: WeakMap<V, K>
constructor(iterable?: Iterable<[K, V]>) {
this.left = new WeakMap<K, V>()
this.right = new WeakMap<V, K>()
if (iterable === undefined) {
return
}
for (let [k, v] of iterable) {
this.left.set(k, v)
this.right.set(v, k)
}
this.#left = new WeakMap<K, V>()
this.#right = new WeakMap<V, K>()
if (iterable === undefined) {
return
}
for (const [k, v] of iterable) {
this.#left.set(k, v)
this.#right.set(v, k)
}
}
// eslint-disable-next-line class-methods-use-this
clear(): void {
console.error('method clear is deprecated')
console.error('method clear is deprecated')
}
delete(key: K): boolean {
const val = this.left.get(key) as V
if (!this.right.has(val)) {
return false
}
this.right.delete(val)
return this.left.delete(key)
const val = this.#left.get(key) as V
if (!this.#right.has(val)) {
return false
}
this.#right.delete(val)
return this.#left.delete(key)
}
get(key: K): V | undefined {
return this.left.get(key)
return this.#left.get(key)
}
has(key: K): boolean {
return this.left.has(key)
return this.#left.has(key)
}
set(key: K, value: V): this {
const { left, right } = this
const oldVal = left.get(key) as V
const oldKey = right.get(value) as K
if (left.has(key)) {
right.delete(oldVal)
}
if (right.has(value)) {
left.delete(oldKey)
}
left.set(key, value)
right.set(value, key)
return this
const left = this.#left
const right = this.#right
const oldVal = left.get(key) as V
const oldKey = right.get(value) as K
if (left.has(key)) {
right.delete(oldVal)
}
if (right.has(value)) {
left.delete(oldKey)
}
left.set(key, value)
right.set(value, key)
return this
}
get [Symbol.toStringTag]() {
return this.left[Symbol.toStringTag]
return this.#left[Symbol.toStringTag]
}
deleteValue(value: V): boolean {
const key = this.right.get(value) as K
if (!this.left.has(key)) {
return false
}
this.left.delete(key)
return this.right.delete(value)
const key = this.#right.get(value) as K
if (!this.#left.has(key)) {
return false
}
this.#left.delete(key)
return this.#right.delete(value)
}
getKey(value: V): K | undefined {
return this.right.get(value)
return this.#right.get(value)
}
hasValue(value: V): boolean {
return this.right.has(value)
return this.#right.has(value)
}
}
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"sourceMap": true,
// "watch": true,
"pretty": true,
"lib": [ "dom", "es7" ],
"declaration": true,
"strictNullChecks": true,
"noUnusedLocals": true,
"downlevelIteration": true,
"alwaysStrict": true,
"outDir": "lib"
},
"exclude": [ "node_modules", "test" ]
"compilerOptions": {
"target": "ES2015",
"module": "CommonJS",
"sourceMap": true,
"moduleResolution": "node",
"pretty": true,
"declaration": true,
"alwaysStrict": true,
// "allowSyntheticDefaultImports": true,
"strictNullChecks": true,
"esModuleInterop": true,
"noImplicitThis": true,
"noImplicitAny": true,
"downlevelIteration": true,
"lib": [
"dom",
"esnext" // for URLSearchParams
],
"outDir": "dist"
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"text"
]
}
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