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

kiper

v1.0.0

Published

Keep objects available everywhere in nodejs application

Downloads

6

Readme

kiper

Keep objects available everywhere in nodejs application

npm version Travis

How to use

First you need to install kiper using npm:

npm install kiper --save

Then, use kiper in your project:

const kiper = require('kiper');

// somewhere keep an asset
kiper.keep('foo', 'bar');

// somewhere you got it back
let value = kiper.get('foo');
console.log(value);

API Usage

Method: .keep(key: string, value: object)

Keep an object in kiper
Added in: v0.0.1
Alias: set

kiper.keep('foo', 'bar');

Method: .keep(key: string, value: object, ttl: int, timeout: function)

Keep an object for a period of time
Added in: v0.1.0
Alias: set

kiper.keep('foo', 'bar', 1000, console.log);
// output: bar foor

Method: .get(key: string)

Get an object from kiper
Added in: v0.0.1

kiper.get('foo');
// returns: bar

Method: .get(validator: function)

Get an object from kiper by pass a validator function
Added in: v0.0.2

kiper.get((value, key) => value === 'bar');
// returns: bar

Method: .remove(key: string)

Remove an object out of kiper
Added in: v0.1.0

kiper.remove('foo');
// returns: bar

Method: .retire()

Stop interval checking, free memory and release objects
Added in: v0.1.0

kiper.retire();

Method: .touch(key)

Repair the last time usage
Added in: v1.0.0

kiper.touch('foo');

Method: .watch(key, callback)

Watch a key, if its value changes then a callback will be called
Added in: v1.0.0

// keep an asset and return an obserable object 
let baz = kiper.keep('baz', {
    gold: 1000
});

// watch the key
kiper.watch('baz', (obj, oldVal, propkey, type) => {
    console.log('change info:', obj, oldVal, propkey, type);
});

// baz lost one gold
baz.gold = 999
// baz has new silvers
baz.silver = 1000
// baz lost all golds
delete baz.gold

Method: .on(event, listener)

Listen an event which emit from kiper
Added in: v1.0.0

kiper.keep('foo', 'bar', 1000);
kiper.on('expired', (value, key) => {
    console.log('A timeout on key has expired', value, key);
})

Method: .once(event, listener)

Listen an event once which emit from kiper
Added in: v1.0.0

kiper.keep('foo', 'bar', 1000);
kiper.once('expired', (value, key) => {
    console.log('A timeout on key has expired', value, key);
})

License

MIT