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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mgwalker/serializable-map

v1.0.1

Published

An extension of the native Map object that attempts to serialize to JSON

Readme

Serializable map

The native Javascript Map object does not have a toJSON() method. That's fine, but what if you need to serialize an object whose keys need to be dynamically computed? Eg.,

class TimedKey {
  toJSON() {
    return new Date().toISOString();
  }
}

const o = {
  [new TimedKey()]: "the current time",
};

Plain object keys must be strings. If you create an object key that is not a string, it is stringified immediately. As a result, in the above example, the key would be the time when the object was created, not the time when the object was serialized.

This is true for any key whose serialized value is computed. Is this a kind of niche use case? You betcha. But it's one that exists.

import SerializableMap from "@mgwalker/serializable-map";

class TimedKey {
  toJSON() {
    return new Date("2019-07-22T17:52:03Z").toISOString();
  }
}

const map = new SerializableMap();
map.set(new TimedKey(), "timed key");

console.log(JSON.stringify(map));
// {
//   "2019-07-22T17:52:03.000Z": "timed key",
// }

setTimeout(() => {
  console.log(JSON.stringify(map));
  // Notice that the seconds in the key have gone up
  // by thirty! Hooray!
  //
  // {
  //   "2019-07-22T17:52:33.000Z": "timed key",
  // }
}, 30_000);

And if you have an existing plain object that you want to treat like a map that you want to serialize later, there's a helper for that, too.

import SerializableMap from "@mgwalker/serializable-map";

const map = SerializableMap.fromObj({
  key: "value",
  list: [
    "yep",
    {
      these: "work",
    },
    "recursively",
  ],
});

Credit

I originally created this library for the National Weather Service.

Contributing

As an original work of the US Government, the initial code is not subject to copyright. In the spirit of public domain software, this repo also explicitly adopts the CC0 statement. Contributors agree that their contributions are committed to the public domain, and in jurisdictions that do not have public domain, are otherwise bound to the terms of the CC0 license.