Socket
Socket
Sign inDemoInstall

localstorage-configmanager

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    localstorage-configmanager

simple interface to manage/augment/increment javascript variables in localstorage with expiry.


Version published
Weekly downloads
2
decreased by-60%
Maintainers
1
Install size
40.8 kB
Created
Weekly downloads
 

Readme

Source

ConfigManager

ConfigManager is a simple interface on top of browsers' localStorage to handle expiry of data and easy storing of javascript objects.

This library uses localStorage and if localStorage is not present, it will throw errors. You can find a pollyfill for local storage on mdn

The tests are under the __tests__ folder and created using jest. You can launch them with npm test command.

Creating and modifying a config

These are the few operations you can make with ConfigManager to set-up a config (item stored in localStorage)

Install and use in your project

npm install --save localstorage-configmanager

Set a javascript variable into configuration:

let config = {name:"Guillaume Lebedel", age:99};
ConfigManager.setConfig("myConfig", config);

Get back the configuration data:

ConfigManager.getConfig("myConfig");
//Object {name: "Guillaume Lebedel", age: 99}

Augmenting or incrementing config data:

You can augment/assign your config with another javascript object

ConfigManager.assignToConfig("myConfig", {age:24});
ConfigManager.addToConfigProperties("myConfig", {age:1});
ConfigManager.getConfig("myConfig");
//Object {name: "Guillaume Lebedel", age: 25}

Remove the configuration

ConfigManager.removeConfig("myConfig");
ConfigManager.getConfig("myConfig");
//null

Expiry

You can set an expiry time in seconds to your configs upon creation or later on. When the config is required after it has expired, it will return null.

Create a config with an expiry time

ConfigManager.setConfig("myConfig", {a:1}, 5) //expires in 5 seconds

Or Set an expiry date after creating the store

ConfigManager.setExpiry("myConfig", 20) //expires in 20 seconds

Which you can get:

ConfigManager.getExpiry("myConfig");

You can also verify how many seconds are left until expiry

ConfigManager.getSecondsUntilExpiry("myConfig");
//20

Keywords

FAQs

Last updated on 02 Jan 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc