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

family-store

v2.0.0

Published

A store that inherits values from its parent(s)

Downloads

6

Readme

family-store

A storage-agnostic store with parents. If the store doesn't have a key, it asks its parents, who ask their parents, et cetera (breadth-first). Circular dependencies are okay.

npm status node

example

const JSONStore = require('atomic-json-store')
const FamilyStore = require('family-store')

const one = new FamilyStore('one', JSONStore('one.json'))
const two = new FamilyStore('two', new Map)

one.inherit(two)
two.inherit(one)

two.set('host', 'two.com')
one.get('host') === 'two.com';
one.getOwn('host') === undefined;
one.getOwner('host').owner === two;

one.set('host', 'one.com')
one.set('port', 8080)

one.get('host') === 'one.com';
two.get('port') === 8080;

FamilyStore(name, storage, [options])

The storage should have the following synchronous interface:

  • get(key)
  • set(key, value)
  • delete(key) or remove(key)
  • keys() (array or iterable)
  • clear() (optional, falls back to delete() all keys())

Options:

  • inherit: array of parents to inherit() from

inherit(parent)

Add a parent store to inherit from. Returns false if it already inherits from parent or if parent is the store itself, otherwise true.

get(key) or getOwn(key)

Get a value with or without inheritance.

getOwner(key)

Returns an object with these properties:

  • owner: the first found store that has a value for key
  • value
  • depth: traversal depth (0 if owner is the store itself)

set(key, value)

Set own value of key.

delete(key) or remove(key)

Delete own value of key.

clear()

Delete all own values.

keys() or ownKeys()

Returns an array of keys with or without inheritance.

pairs() or ownPairs()

Returns an array of [key, value] pairs with or without inheritance.

toJSON()

Get an object with all values, own and inherited.

equals(familyStore)

a.equals(b) is true if a.toJSON() deep equals b.toJSON().

traverse(function)

Breadth-first traversal, starting with the store itself. The function is called once for every store with the arguments storage, store and depth until the function returns a value other than undefined.

const a = new FamilyStore('a', storage())
const b = new FamilyStore('b', storage())
const c = new FamilyStore('c', storage())
const d = new FamilyStore('d', storage())

a.inherit(b)
a.inherit(c)

b.inherit(a)
b.inherit(d)

a.traverse(function(storage, store, depth){
  console.log('%s: %d', store.name, depth)
})

Gives:

a: 0
b: 1
c: 1
d: 2

install

With npm do:

npm install family-store

license

MIT © ironSource.