https://github.com/matthewcallis/fifo
First In First Out accounting for JavaScript localStorage.
https://github.com/matthewcallis/fifo
fifo javascript localstorage
Last synced: 6 days ago
JSON representation
First In First Out accounting for JavaScript localStorage.
- Host: GitHub
- URL: https://github.com/matthewcallis/fifo
- Owner: MatthewCallis
- License: mit
- Created: 2016-06-14T20:00:44.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2022-02-22T20:00:57.000Z (about 3 years ago)
- Last Synced: 2025-04-11T23:38:23.457Z (17 days ago)
- Topics: fifo, javascript, localstorage
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/localstorage-fifo
- Size: 255 KB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [Fifo](https://github.com/MatthewCallis/fifo)
[](https://travis-ci.org/MatthewCallis/fifo)
[](https://codeclimate.com/github/MatthewCallis/fifo/coverage)
[](https://coveralls.io/github/MatthewCallis/fifo?branch=master)
[](https://david-dm.org/MatthewCallis/fifo#info=devDependencies)
[](https://www.npmjs.com/package/localstorage-fifo)
[](https://www.npmjs.com/package/localstorage-fifo)**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](http://jsperf.com/localstorage-string-size-retrieval).
## API
```javascript
// 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');
``````javascript
// 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
```shell
npm run lint
npm run make
npm run test
```## License
MIT-Style license
Originally forked from [rpflorence](https://github.com/rpflorence/fifo) to fix some issues.