Socket
Socket
Sign inDemoInstall

localstorage-fifo

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    localstorage-fifo

JavaScript library for interacting with localStorage safely.


Version published
Weekly downloads
57
decreased by-43.56%
Maintainers
1
Install size
27.0 kB
Created
Weekly downloads
 

Readme

Source

Fifo

Build Status Test Coverage Coverage Status devDependency Status npm version npm downloads

First In First Out accounting for JavaScript localStorage.

npm install --save localstorage-fifo

About

localStorage doesn't have an unlimited amount of space, and just throws an error when you try to save to it when its full. fifo gracefully handles saving data to localStorage: when you run out of room it simply removes the earliest item(s) saved.

Additionally, fifo also stores all of your key:value pairs on one key in localStorage for better performance.

API

// create a collection stored on `tasks` key in localStorage
const collection = new Fifo({ namespace: 'tasks' });

// set an item
collection.set('task-1', 'close two tickets');

// retrieve an item - preference for fixed items, then FIFO queue
var storedTask = collection.get('task-1'); //> 'close two tickets'

// retrieve all items by sending no arguments to get
var tasks = collection.get();

// remove an item - preference for fixed items, then FIFO queue
collection.remove('task-1');
// empty an entire FIFO queue
collection.empty();

// set any JavaScript object, don't have to JSON.parse or JSON.stringify() yourself when setting and getting.
collection.set('task:2', { due: 'sunday', task: 'go to church' });
collection.set('whatevz', [1,2,3]);

// get a list of all keys, both those in fifo and fixed localStorage
collection.keys(); /* Returns an array of key names */

// Check to see if a key exists in the FIFO queue or fixed localStorage
collection.has('key'); /* true or false */

Please see the source for more details.

Browser Support

fifo assumes the browser has localStorage and JSON. There is a localStorage shim but it will not persist.

Testing

npm run lint
npm run make
npm run test

License

MIT-Style license

Originally forked from rpflorence to fix some issues.

Keywords

FAQs

Last updated on 22 Feb 2022

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