Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mshaaban0/lokale
Simple robust API for localStorage management with usage info
https://github.com/mshaaban0/lokale
javascript localstorage
Last synced: 16 days ago
JSON representation
Simple robust API for localStorage management with usage info
- Host: GitHub
- URL: https://github.com/mshaaban0/lokale
- Owner: mshaaban0
- License: mit
- Created: 2018-07-24T14:09:46.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-08-10T19:03:12.000Z (over 3 years ago)
- Last Synced: 2024-12-28T04:39:07.433Z (about 2 months ago)
- Topics: javascript, localstorage
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/lokale
- Size: 22.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Lokale - Simple API for localStorage Management
Lokale is a simple yet reliable api for browser localStorage or sessionStorage management.### Install
Make sure you have the following installed
- [Node JS](https://nodejs.org/en/)
- [NPM](https://npmjs.com)Run the folling command to add the package to your project dependencies
```bash
npm install lokale
```### How to use
Lokale also supports typescripts, types declaration are included by default.**CommonJs**
```javascript
const Lokale = require('lokale');
```**ES6**
```javascript
import Lokale from 'lokale';
```**Usage**
```javascript
// Initiate an instance
// You can use localStorage or sessionStorage
const lokalStorage = new Lokale(window.localStorage);// Set item
lokalStorage.setItem('YourKey', 'YourData');
```### API
Available options| API | Arguments Type | Description | Returns |
|---------------------|----------------|--------------------------------------------------------------|-----------------------------------------------------------|
| lokale(**storage**) | Storage | Set the preferred storage `localStorage` or `sessionStorage` | |
| getItem(key) | String | Get item by key name | String - Value of the key |
| setItem(key, value) | String, String | Set item value to storage | |
| hasItem(key) | String | Check if item exists in the storage | Boolean |
| clear() | | Empty all keys and values in storage | |
| getSpaceUsage() | | Get detailed size/space infos about keys and remaining space | Object - Usage per key, `availableSpace`, and `usedSpace` |