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

localstorage-plus

v0.2.3

Published

Simple helper extender class for the localStorage browser implementation

Downloads

3

Readme

Build Status Code Climate npm

localstorage-plus

Simple helper class that extends the localStorage implementation

Contents

Getting started

Download via npm.

npm install localstorage-plus --save-dev

You can also download the project and include the store.min.js file into your HTML-Document

<html>
    <head>
        ...
    </head>
    <body>
        ...

        <script src="/path/to/store.min.js" type="text/javascript"></script>
        <script src="/path/to/your/app.js" type="text/javascript"></script>
    </body>
</html>

Documentation

Initialize a Store

| param | type | flag | description | |:-------------|:--------|:--------|:----------------------------------| | name | string | | The name of the store | | flushExpired | boolean | optinal | run auto flush for expired values |

var Store = require('localstorage-plus');

var UserStore = new Store('user')

If you are using the <script> way, the Store will be applied to the window object.

Suppress auto expiredFlush on creation

When a new Store instace gets created, the constructor will run the flushExpired method automaticly, accept your provide a boolean as the second parameter like so:

var UserStore = new Store('UserStore', false);

Static methods

Store.flush

Removes all Store entries

return: void

var Store = require('localstorage-plus');

Store.flush();

Store.flushExpired

Removes all expired Store entries

return: void

Store.flushExpired();

Instance methods

Store#set

Set a key with the value to store

| param | type | flag | description | |:----------|:--------|:---------|:------------------------------| | key | string | | The name of the value | | data | mixed | | The data to store | | expiresAt | integer | optional | When should this value expire |

return: boolean

var Store = require('localstorage-plus');

var UserStore = new Store('user');

UserStore.set('name', 'John Doe');                   // -> true
UserStore.set('wife', 'Jane Doe');                   // -> true

// set a value with an expire date (2s)
UserStore.set('token', 'secret', Date.now() + 2000); // -> true

Store#isset

Check if the given key exists

| param | type | description | |:------|:-------|:--------------------------------------| | key | string | Key defined in Store.set |

return: boolean

var Store = require('localstorage-plus');

var UserStore = new Store('user');

UserStore.isset('user');  // -> true
UserStore.isset('age');   // -> false

Store#get

Get the value stored under the given key, or the whole store

| param | type | flag | description | |:------|:-------|:---------|:---------------------------------------| | key | string | optional | Key defined in Store.set |

return: object, mixed

var Store = require('localstorage-plus');

var UserStore = new Store('user');

UserStore.get('name');   // -> John Doe
UserStore.get();         // -> { name: 'John Doe', wife: 'Jane Doe' }

Store#remove

Remove an item

| param | type | description | |:------|:-------|:--------------------------------------| | key | string | Key defined in Store.set |

return: boolean

var Store = require('localstorage-plus');

var UserStore = new Store('user');

UserStore.remove('name') // -> true

Store#flush

Flush all values, that are stored in the Store instance

return: void

var Store = require('localstorage-plus');

var UserStore = new Store('user');

UserStore.flush();

Store#flushExpired

Flush expired values defined in this store

return: void

var Store = require('localstorage-plus');

var UserStore = new Store('user');

UserStore.flushExpired();

Test

To run a test just enter the following command

npm run test