https://github.com/danrotaru/storage.js
Storage.js - lightweight javascript localstorage API library
https://github.com/danrotaru/storage.js
Last synced: 3 months ago
JSON representation
Storage.js - lightweight javascript localstorage API library
- Host: GitHub
- URL: https://github.com/danrotaru/storage.js
- Owner: DanRotaru
- Created: 2020-08-22T15:30:33.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-05-10T12:21:18.000Z (about 2 years ago)
- Last Synced: 2024-05-10T13:35:34.135Z (about 2 years ago)
- Language: JavaScript
- Size: 25.4 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Storage.js
Storage.js - the smallest, lightweight library to interactive with LocalStorage API.
## Init
All data's are stocked in one localStorage key. By default localStorage key name is storage.js
```javascript
storage.init("Storage name", "local");
// Seccond argument is optional (local || session), by default is local
```
## Get all data
```javascript
// In string format
storage.raw();
// In JSON format
storage.json();
```
## Set/update value
`value` (string) — data value
`key` (string) — key value.
```javascript
// Add some local data
storage.add(value, key);
// The same function
storage.update(value, key)
```
## Get value
`key` (string) — key value.
```javascript
storage.get(key);
```
## Remove data
`key` (string) — key value.
```javascript
storage.remove(key);
```
## Transfer data from sessionStorage to localStorage and conversely
`to` (string) — transfer data to ("local" || "session").
```javascript
storage.transfer(to);
```
In all functions, `key` can also contain multiple object location.
E.g. `someKey`, `user.name`, `user.settings.theme`
```javascript
storage.add("some value", "someKey");
storage.add("Dan", "user.name");
storage.add("dark", "user.settings.theme");
```

## P.S.
It is important to use storage, not Storage name, because it is used, or you can change object name storage to whatever you want.
## License
Released under the [MIT license](http://www.opensource.org/licenses/MIT).
Created by [DanRotaru](https://t.me/danrotaru).