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

indexed-values

v0.1.0

Published

An ever growing Set based utility to optimize JSON, IndexedDB, or postMessage

Downloads

824

Readme

indexed-values

build status Coverage Status

Related Blog Post.

Example

import {IndexedValues} from 'indexed-values';

// create a Set of unique values
const main = new IndexedValues;

// derive a set
const sub1 = main.bindValues(["a", "b", "c"]);
const sub2 = main.bindValues(["a"]);

// derived sets can make the main Set grow
if (!sub2.has("d"))
  sub2.add("d");

// {"main":["a","b","c","d"],"data":[[0,1,2],[0,3]]}
console.log(JSON.stringify({
  main,
  data: [sub1, sub2]
}));

API

The IndexedValues constructor extends the Set class, but it's a facade with the following peculiarities:

  • it is not posible to delete a single value, or clear the instance. IndexedValues instances are ever-growing
  • .toJSON() method returns an array of values held internally
  • .valueOf() method returns a real Set that can resist postMessage, or be stored as IndexedDB
  • .bindValues(values = []) returns a Set that can contain, add, or remove, any value. Added values will be reflected in the IndexedValues instance that created the bound Set.
  • .bindIndexes(indexes = []) is like .bindValues() but uses indexes instead, to initialize the derived Set. This is mostly useful for revival.
  • .mapKeys(entries = []) returns a Map where keys are derived from the IndexedValues. Added keys that are not known in the IndexedValues source, will be automatically added as part of the Set. Once serialized as JSON, these maps will represent all keys as indexes, because indeed these maps never hold keys as values, these hold keys as indexes.
  • .mapEntries(entries = []) is the revival counter-part of .mapKeys(). It returns a map with keys revived from the IndexedValues instance.
  • .fromIndexes(indexes) can revive right away Set instances, upgrading their prototype. This is a quick and dirty .bindIndexes() equivalent, available for performance reasons.
  • .fromEntries(entries) can revive right away Map instances, upgrading their prototype. This is a quick and dirty .mapEntries() equivalent, available for performance reasons.