Catalog npm
Back to packageRELEASE DETAILS

1.0.1

npm

2keys

Alternate and slightly faster implementation of [map2](https://www.npmjs.com/package/map2) and [set2](https://www.npmjs.com/package/set2) allowing you to use more than one key as the key

es6hashmaphashsetkeysmapmap2setset2tuple
Published21 Dec 2023
Direct dependencies0
Transitive dependenciesNot calculated

README

Current package documentation

Alternate and slightly faster implementation of map2 and set2 allowing you to use more than one key as the key

✅ Performance guarantee. Found a faster implementation? Make an issue on our github!

  • ES6 support
  • Available in global scope
  • Map2 & Set2
  • Can be used exactly like existing Set and Map
  • Support for .swap() and .pop()
import '2keys'

const map = new Map()
map.set([1, 2], 3)
map.get([1, 2])
// => undefined
// ES6 map is by reference, not value

const map = new Map2()
map.set(1, 2, 3)
map.get(1, 2)
// => 3
const x = {}, y = []
map.set(x, y, {a: 1})
map.get(x, y)
// => {a: 1}
map.has(x, y)
// true
map.delete(x, y)
map.get(x, y)
// => undefined

const map = new Map2([
	[1, 2, 3],
	[1, 5, 6],
	[2, 10, 12],
])
map.set(3, 4, 7).set(9, 9, 9)
map.size
// => 5

for(const [k1, k2, v] of map){
	console.log(k1, k2, v)
}
// 1 2 3
// 1 5 6
// 2 10 12
// 3 4 7
// 9 9 9

console.log([...map.values()])
// => [3, 6, 12, 7, 9]
console.log([...map.keys()])
// => [[1, 2], [1, 5], [2, 10], [3, 4], [9, 9]]
console.log(map.submap(1))
// => Map(2) { 2 => 3, 5 => 6 }
console.log(map)
// Map2(4) { (1, 2) => 3, (1, 5) => 6, (2, 10) => 12, (3, 4) => 7, (9, 9) => 9 }
map.clear()


const set = new Set2()

// Chaining works on both set and map
set.add(1, 2).add(3, 4)
set.swap(5, 5)
// => false
set
// Set2(3) { (1, 2), (3, 4), (5, 5) }
set.swap(5, 5)
// => true  (entry was present, set unchanged)

for(const [a, b] of set){
	console.log(a, b)
}
// 1 2
// 3 4
// 5 5

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 0

Native requirements
0 direct targetsNot calculated transitive count
No declared dependencies in this collected response

Declarations describe requirements; they are not a resolved dependency graph.

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "integrity": "sha512-D+2V2UScJ/TujzchYX0cbCSxEKSoQwVNT4dCEKKea0M3pNJg/FRGmCu4xAOrk4tvUQie2udkH2cOz1QIL12+cw==",
  "shasum": "33c11108891e4e1ca41b9051a2f22913e630925b",
  "tarball": "https://registry.npmjs.org/2keys/-/2keys-1.0.1.tgz",
  "fileCount": 3,
  "unpackedSize": 7347,
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEUCIHQDxFNLQnRN10aKMDnjSioA5+s8ADeZUUQhshs18zX3AiEAj0in1iK6U8i6gEiirtGtJkHEQ//cbzc9Tv2BqOpP/S4="
    }
  ]
}

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 19:14 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:1bc57db28a902fd8dbb60a4c9fc1fc9cf6ae824ca0ad31bc79f1b33426805b8a

Other collected versions

1.1.022 Dec1.0.322 Dec1.0.221 Dec1.0.021 DecView all collected versions →