Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alik0211/tiny-storage
Tiny wrapper around localStorage and sessionStorage
https://github.com/alik0211/tiny-storage
localstorage sessionstorage storage tiny-library
Last synced: about 1 month ago
JSON representation
Tiny wrapper around localStorage and sessionStorage
- Host: GitHub
- URL: https://github.com/alik0211/tiny-storage
- Owner: alik0211
- License: mit
- Created: 2018-08-18T08:16:42.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-09-17T14:34:44.000Z (over 4 years ago)
- Last Synced: 2024-10-31T17:19:39.506Z (about 2 months ago)
- Topics: localstorage, sessionstorage, storage, tiny-library
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/tiny-storage
- Size: 12.7 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tiny-storage
[![NPM](https://img.shields.io/npm/v/tiny-storage.svg?style=flat-square)](https://www.npmjs.com/package/tiny-storage)
[![Travis](https://img.shields.io/travis/alik0211/tiny-storage/master.svg?style=flat-square)](https://travis-ci.com/alik0211/tiny-storage)
[![Coverage Status](https://img.shields.io/coveralls/github/alik0211/tiny-storage/master.svg?style=flat-square)](https://coveralls.io/github/alik0211/tiny-storage?branch=master)Tiny wrapper around localStorage and sessionStorage with reliable data storage.
## Description
The `tinyLocalStorage` is the wrapper over the `localStorage`.The `tinySessionStorage` is the wrapper over the `sessionStorage`.
## Quick start
### Module
#### Installation
```
npm install tiny-storage
```
#### Usage
```javascript
import { tinyLocalStorage, tinySessionStorage } from 'tiny-storage';
// Or as CommonJS
// const { tinyLocalStorage, tinySessionStorage } = require('tiny-storage');tinyLocalStorage.set('user', {
name: 'Ali',
surname: 'Gasymov'
});tinySessionStorage.set('user', {
name: 'Ali',
surname: 'Gasymov'
});
```### Browser
#### Installation
```html```
#### Usage
```htmltinyLocalStorage.set('user', {
name: 'Ali',
surname: 'Gasymov'
});tinySessionStorage.set('user', {
name: 'Ali',
surname: 'Gasymov'
});```
## Methods
### `key(index)`
When passed a number n, returns the name of the nth key in the storage. The order of keys is user-agent defined, so you should not rely on it.```javascript
tinyLocalStorage.key(0);tinySessionStorage.key(0);
```
### `get(keyName)`
When passed a key name, will return that key's value or null if the key does not exist.```javascript
tinyLocalStorage.get('user');tinySessionStorage.get('user');
```
### `set(keyName, keyValue)`
When passed a key name and value, will add that key to the storage, or update that key's value if it already exists.```javascript
tinyLocalStorage.set('user', {
name: 'Ali',
surname: 'Gasymov'
});tinySessionStorage.set('user', {
name: 'Ali',
surname: 'Gasymov'
});
```
### `remove(keyName)`
When passed a key name, will remove that key from the storage if it exists. If there is no item associated with the given key, this method will do nothing.```javascript
tinyLocalStorage.remove('user');tinySessionStorage.remove('user');
```
### `clear()`
When invoked, clears all stored keys.```javascript
tinyLocalStorage.clear();tinySessionStorage.clear();
```## Properties
### `length`
Returns an integer representing the number of data items stored in the storage.