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

keymit

v0.2.0

Published

An object store with event emitters that you can subscribe to

Downloads

7

Readme

Keymit (ALPHA)

What is it?

Keymit is an object store that allows you to subscribe to changes at any depth of the object store. You can subscribe to all changes in the store, changes to only certain branches, or subscribe to only when a single value changes.

Usage

Creating a keymit object

const Keymit = require('keymit');

let keymit = new Keymit();

Settings keys values

// Set/update values in the keysore with an object
keymit.set({
  canada: {
    ontario: {
      toronto: {
        population: 2615000,
        temperature: 27.8
      }
    }
  },
  usa: {
    texas: {
      huston: {
        population: 2196000,
        temperature: 30.2
      }
    }
  }
});

// Alternatively, you can set/update values with flat keys
// (default delimiter is a '.')
keymit.set({
  'canada.alberta.calgary': 'my string',
  'canada.alberta.edmonton': 123,
  'canada.ontario.london': [1, 2, 3],
  'usa.taxas.austin': 'my other string',
  'usa.texas.dalas': true
});

// If your keys values have been serialized from another language (such as C#),
// you can simply pass those too
keymit.set([
  { 'canada.alberta.calgary': 'my string' },
  { 'canada.alberta.edmonton': 123 },
  { 'canada.ontario.london': [1, 2, 3] },
  { 'usa.taxas.austin': 'my other string' },
  { 'usa.texas.dalas': true }
]);

Gettings key values

// Get a copy of all values
let all = keymit.get();

// Get a copy of only specific path
let ontario = keymit.get('canada.ontario');

Subscribing

function onChange(record) {
  console.log(record);
}

// Subscribe to all records
keymit.subscribe(onChange);

// Subscribe to only a portion of the records
keymit.subscribe('canada.ontario', onChange);

// Subsribe to only a single record
keymit.subscribe('canada.ontario.toronto', onChange);

Unsubscribing

function onChange(record) {
  console.log(record);
}

// Unsubscribe to all records
keymit.unsubscribe(onChange);

// Unsubscribe to only a portion of the records
keymit.unsubscribe('canada.ontario', onChange);

// Unsubscribe to only a single record
keymit.unsubscribe('canada.ontario.toronto', onChange);

Documentation

Methods
  • ()
    • Creates a new keymit instance.
    • Parameters
      • String: optional delimiter for all keys [default is '.']
  • Delete
    • Deletes a branch or value from the store.
    • Parameters
      • String: optional delimited path to delete [defaults to deleting all records]
  • set
    • Sets a branch or value in the store.
    • Parameters
      • String or Object: The key string or object of key values
      • *: value to use if previous parameter was a string
  • get
    • Gets a branch or value from the store.
    • Parameters
      • String: optional delimited path to filter by
  • subscribe
    • Adds a subscription.
    • Parameters
      • String: optional delimited path to subscribe to [defaults to all records]
      • Function: callback to run on change
      • Object: optional options
        • Boolean: flatten flatten the records with the delimiter before passing them back [default is false]
        • Boolean: triggerNow have the callback immediately execute with the current value [defaults is false]
        • Boolean: lean have only changes sent (excluding the initial triggerNow) [default is false]
  • unsubscribe
    • Remove a subscription.
    • Parameters
      • String: optional delimited path to unsubscribe to [defaults to all records]
      • Function: callback to unsubscribe
  • unsubscribeAll
    • Removes all subscriptions.
Properties
  • listenerCount (Number): Number of active subscriptions

Tests

Install npm mocha either local or globally and run mocha tests.