
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
SameValueMap and SameValueSet extend JavaScript's built-in
Map and SetMap and Set including
method return values and even iteration order!$ npm i svkc
A key in a Map or a value in a Set can only occur once. But how is the key
or value's uniqueness determined? JavaScript's Map and Set use the
sameValueZero algorithm
when checking if two keys or values are equal. The algorithm considers +0 and -0
to be equal, but they are actually two different values due to how
IEEE floating point numbers
work. This means that both new Map([[0, 'zero'], [-0, 'negative zero']]).size
and new Set([0, -0]).size return 1 rather than 2.
This package provides SameValueMap and SameValueSet that behave identically
to Map and Set except they consider +0 and -0 to be different values.
Just use like a normal Map or Set!
import { SameValueMap, SameValueSet } from 'svkc'
const sameValueMap = new SameValueMap()
sameValueMap.set(1, `one`)
sameValueMap.set(0, `zero`)
sameValueMap.set(-0, `negative zero`)
sameValueMap.set(-1, `negative one`)
console.log(sameValueMap.get(0))
//=> zero
console.log(sameValueMap.get(-0))
//=> negative zero
console.log([...sameValueMap])
//=> [ [ 1, 'one' ], [ 0, 'zero' ], [ -0, 'negative zero' ], [ -1, 'negative one' ] ]
sameValueMap.delete(0)
console.log(sameValueMap.has(0))
//=> false
console.log(sameValueMap.has(-0))
//=> true
const sameValueSet = new SameValueSet()
sameValueSet.add(1)
sameValueSet.add(0)
sameValueSet.add(-0)
sameValueSet.add(-1)
console.log(sameValueSet.has(0))
//=> true
console.log(sameValueSet.has(-0))
//=> true
console.log([...sameValueSet])
//=> [ 1, 0, -0, -1 ]
sameValueSet.delete(0)
console.log(sameValueSet.has(0))
//=> false
console.log(sameValueSet.has(-0))
//=> true
Stars are always welcome!
For bugs and feature requests, please create an issue.
FAQs
JavaScript's keyed collections (Map & Set) with SameValue semantics!
We found that svkc demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.