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
const collection = Fifo({ namespace: 'tasks' });
collection.set('task-1', 'close two tickets');
var storedTask = collection.get('task-1');
var tasks = collection.get();
collection.remove('task-1');
collection.empty();
collection.set('task:2', { due: 'sunday', task: 'go to church' });
collection.set('whatevz', [1,2,3]);
collection.keys();
collection.has('key');
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
npm run report
License
MIT-Style license
Originally forked from rpflorence to fix some issues.