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

willson-smith-es2015-small-data-store

v1.0.0

Published

A basic JavaScript flux-y store written in ES6

Downloads

4

Readme

ES6 Flux-ish store

or es2015 - whatever you want to call it

Sample code

You can create grouped stores under one smallDataStore() by using the .new() method:

let groceryStore = smallDataStore();

let fruitGroceryStore = groceryStore.new({
  'apples': 5,
  'oranges': 10,
  'bananas': 2,
  'purchased': false
});

let meatGroceryStore = groceryStore.new({
  'steak': {
    'hanger': 1
  },
  'porkchop': 5,
  'sausage': 3,
  'purchased': false
});

The .new() method can be either called with a base object, or with no object as a parameter. In the case no object is passed, it will use an empty object. You can get() and set() values for your store

let sausageNumber = meatGroceryStore.get('sausage');
console.log(sausageNumber); //3

meatGroceryStore.set('bacon', 7);
console.log(meatGroceryStore.get('bacon')); // 7

Alternatively you can update() something on your store. Update takes a function which will transform the value you are accessing.

meatGroceryStore.update('steak', (grocery) => grocery.tenderloin = 1);
console.log(meatGroceryStore.get('steak')); // {hanger: 1, tenderloin: 1}

With grouped stores, they are held in an array that can be accessed with .storeGroup() on your original smallDataStore(), in this case: groceryStore. This allows you to loop through all of them and perform group operations on related stores.

console.log(groceryStore.storeGroup()); // [fruitStore, meatStore]
groceryStore.storeGroup().forEach((store) => store.set('purchased', true));

console.log(meatGroceryStore.get('purchased')); // true
console.log(fruitGroceryStore.get('purchased')); // true

You can also call smallDataStore() directly. Unlike using .new(), you must pass an object, otherwise it will expect you to call .new()

let carStore = smallDataStore({
  'ford': 15,
  'honda': 12,
  'toyota': 16
});

console.log(carStore.keys()); // ['ford', 'honda', 'toyota'];
console.log(carStore.get('ford')); // 15

Running tests

npm test will build and run the tests. You will need to have already built smallDataStore.js with npm run babel.