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

hybrid-map

v0.1.0

Published

the half map, half weak, fully cross platform solution

Downloads

4

Readme

HybridMap

the half map, half weak, fully cross platform solution

Summary

The status of ES6 Collections is messy right now. The proposal is still under discussion, few browsers already expose them with partial implementation and few methods are not possible to polyfill on older browsers and even on top of native, partially implemented, prototypes.

I am the author of the es6-collection polyfill and I will try to maintain them as frequently as possible. However, when there are these kind of inconsistencies I realize that doesn't make much sense to force a shim over unshimmable implementations so here I am with an alternative to my own polyfill.

The HybridMap Concept

This no strings attached utility is based over these, if you want personal, considerations:

  • you don't want to constantly switch between Map and WeakMap. What can be weak should be weak so you focus on something else
  • you don't want to write m["delete"](key) every bloody time you want to delete a key in non ES5 yet browsers. m.del(key) is semantically equivalent and does not break old browsers/engines syntax parsers
  • you don't want a whole library or framework
  • you don't want to change code all the time until all collections will be definitive and widely/consistently adopted
  • you do want something that just works and you need it now
  • you also want a consistent behavior across browsers, client, and server, platforms
  • finally, you definitively want good performance!

Accordingly, methods are similar to those defined by ES6 Collections specifications but might be different. Same difference you might have as example between jQuery.each() and array.forEach() when it comes to callback parameters but as it is for each() you can always trust your code, rather than current browser version ... deal?

HybridMap API

In alphabetic order:

  • clear(void):HybridMap to remove all associated keys. Returns the instance itself
  • del(key:any):boolean to remove a key, if present. Returns true if it has been removed, false otherwise.
  • get(key:any):any to retrieve a previously stored key. Returns the associated value, if any, undefined otherwise
  • has(key:any):boolean to check if a generic key has been set before. Returns true in latter case, false otherwise
  • set(key:any, value:any):any to associate a generic value with a generic key. Overwrites the previously set value, if any. Returns the value that has been set

Being quite new, feel free to propose something more if you believe is that needed or some change if you think is a real code/world improvement, thanks.

Details

  • compatibility node.js, rhino, IE < 9, everything else .. it's probably easier if you tell me which browser is not supported
  • size around 0.6 Kb gzipped
  • license Mit Style

How To Include

  • in node simply via var HybridMap = require("../src/HybridMap.js").HybridMap;
  • in any browser simply including build/HybridMap.js script

How To Tests

  • node npm install wru then wru test/HybridMap.js
  • browsers simply open test.html but if your browser does not support XMLHttpRequest via file protocol then npm install polpetta and then polpetta you can go to http://localhost:1337/test.html now