npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

svkc

v1.0.0

Published

JavaScript's keyed collections (Map & Set) with SameValue semantics!

Downloads

509

Readme

Features

  • Familiar: SameValueMap and SameValueSet extend JavaScript's built-in Map and Set
  • Compliant: maintains all the invariants of Map and Set including method return values and even iteration order!
  • Tiny: less than 350 bytes minzipped!

Install

$ npm i svkc

Huh?

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.

Usage

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

Contributing

Stars are always welcome!

For bugs and feature requests, please create an issue.

For pull requests, please read the contributing guidelines.

License

Apache License 2.0

This is not an official Google product.