@p9m/local-storage-service
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

Local Storage Service

localStorage wrapper for CRUD operations.

This library is useful for mocking API service, when learning a frontend framework.

Installation

$ npm install @p9m/local-storage-service --save
or
$ yarn add @p9m/local-storage-service

In browser:

<script src="https://unpkg.com/@p9m/local-storage-service@latest"></script>

<script>
const ls = new LocalStorageService('books');
</script>

Usage

import LocalStorageService from '@p9m/local-storage-service';

// Create instance with a namespace
const ls = new LocalStorageService('contacts');

// Create a record
ls.create({name: 'Reddy'});
// {name: 'Reddy', id: '6aa43c7c-69cf-df49-c927-6ba3db8d7ac1'}

// Get a record
ls.get('6aa43c7c-69cf-df49-c927-6ba3db8d7ac1');
// {name: 'Reddy', id: '6aa43c7c-69cf-df49-c927-6ba3db8d7ac1'}

// Update a record
ls.update({name: 'John Doe', id: '6aa43c7c-69cf-df49-c927-6ba3db8d7ac1'});
// {name: 'John Doe', id: '6aa43c7c-69cf-df49-c927-6ba3db8d7ac1'}

// Get all records within namespace (eg: contacts)
ls.getAll();

// Delete a record
ls.delete('6aa43c7c-69cf-df49-c927-6ba3db8d7ac1');

// Delete all record within namespace (eg: contacts)
ls.deleteAll();

Package Sidebar

Install

npm i @p9m/local-storage-service

Weekly Downloads

1

Version

1.0.3

License

MIT

Unpacked Size

11.4 kB

Total Files

10

Last publish

Collaborators

  • p9m