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

birkin

v1.0.2

Published

immutable key/value store

Downloads

109

Readme

birkin

Build Status

simple and immutable key/value-bag for storing session and configuration data in client-side applications

Installation

$ npm install birkin --save

In ES5:

var Bag = require('birkin');
var sessionbag = new Bag();

Using Babel / ES6:

import Bag from 'birkin';
const sessionbag = new Bag();

API

Constructor(objects...)

The instance can be passed any number of objects on instantiation that will serve as base data:

var emptyBag = new Bag();
var prepopulated = new Bag({key: 'value'});
var numbers = new Bag({one: 1}, {two: 2}, {three: 3});
set(key, value)

Associates any value with the given key:

var sessionbag = new Bag();
sessionbag.set('some-string', 'Christ is risen');
sessionbag.set('some-array', ['foo', 'bar', 'baz']);
set(objects...)

Merges the given object into the store:

var sessionbag = new Bag();
sessionbag.set({a: 1, b: 2, c: 3});
sessionbag.set({d: 4}, {e: 5});
get(key)

Retrieves a value by the given key:

sessionbag.set('message', 'Christ is risen');
sessionbag.get('message'); // => 'Christ is risen'
sessionbag.get('notset'); // => undefined
get(keys...)

Retrieves a value inside a stored object:

var sessionbag = new Bag();
sessionbag.set('nested', { christ: { is: {risen: 'not too sure' } } });
sessionbag.get('nested', 'christ', 'is', 'risen'); // => 'not too sure'
get()

Retrieves the store as an object:

var sessionbag = new Bag();
sessionbag.set('foo', 'bar');
sessionbag.get(); // => {foo: 'bar'}
has(key)

Checks if the given key exists:

var sessionbag = new Bag();
sessionbag.set('foo', 'bar');
sessionbag.has('foo'); // => true
sessionbag.has('bar'); // => false
has()

Checks if the instance contains any keys:

var sessionbag = new Bag();
sessionbag.has(); // => false
sessionbag.set('foo', 'bar');
sessionbag.has(); // => true

Immutability

birkin is designed to be immutable. Keys cannot be overridden or unset. Returned values will be clones. This enforces well designed data structures and handling.

var sessionbag = new Bag();
sessionbag.set('foo', 'bar');
sessionbag.set('foo', 'baz');
sessionbag.set({ foo: 'qux', bar: 'foo'});
sessionbag.get(); // => {foo: 'bar', bar: 'foo'}
sessionbag.set('obj', {a: 'b'});
var obj = sessionbag.get('obj');
obj.a = 'c';
sessionbag.get('obj'); // => {a: 'b'}

If you are sure that mutating values is the right approach for your problem at hand, do so explicitly:

var sessionbag = new Bag({key: 'value'});
var data = sessionbag.get();
data.key = 'updated value';
sessionbag = new Bag(data);
sessionbag.get('key'); // => 'updated value'

License

MIT © Frederik Ring