All Projects β†’ ankurk91 β†’ vue-web-storage

ankurk91 / vue-web-storage

Licence: MIT License
Vue.js plugin for local storage and session storage (1.8 kb min+gz) πŸ’Ύ

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to vue-web-storage

Vue Ls
πŸ’₯ Vue plugin for work with local storage, session storage and memory storage from Vue context
Stars: ✭ 468 (+450.59%)
Mutual labels:  storage, localstorage, sessionstorage, vue-plugin
Angular Locker
πŸ—„οΈ A simple & configurable abstraction for local/session storage in angular js projects
Stars: ✭ 318 (+274.12%)
Mutual labels:  storage, localstorage, sessionstorage
persistence
πŸ’Ύ Persistence provides a pretty easy API to handle Storage's implementations.
Stars: ✭ 18 (-78.82%)
Mutual labels:  storage, localstorage, sessionstorage
ng2-storage
A local and session storage wrapper for angular 2.
Stars: ✭ 14 (-83.53%)
Mutual labels:  storage, localstorage, sessionstorage
Brownies
🍫 Tastier cookies, local, session, and db storage in a tiny package. Includes subscribe() events for changes.
Stars: ✭ 2,386 (+2707.06%)
Mutual labels:  storage, localstorage, sessionstorage
Immortaldb
πŸ”© A relentless key-value store for the browser.
Stars: ✭ 2,962 (+3384.71%)
Mutual labels:  storage, localstorage, sessionstorage
Proxy Storage
Provides an adapter for storage mechanisms (cookies, localStorage, sessionStorage, memoryStorage) and implements the Web Storage interface
Stars: ✭ 10 (-88.24%)
Mutual labels:  storage, localstorage, sessionstorage
stoor
Storage wrapper with support for namespacing, timeouts and multi get/set and remove.
Stars: ✭ 26 (-69.41%)
Mutual labels:  storage, localstorage, sessionstorage
h5webstorage
Web Storage for Angular 2
Stars: ✭ 38 (-55.29%)
Mutual labels:  storage, localstorage, sessionstorage
Recoil Persist
Package for recoil state manager to persist and rehydrate store
Stars: ✭ 66 (-22.35%)
Mutual labels:  storage, localstorage, sessionstorage
React Storage Hooks
React hooks for persistent state
Stars: ✭ 146 (+71.76%)
Mutual labels:  storage, localstorage, sessionstorage
Store
A better way to use localStorage and sessionStorage
Stars: ✭ 1,646 (+1836.47%)
Mutual labels:  storage, localstorage, sessionstorage
Vue Warehouse
A Cross-browser storage for Vue.js and Nuxt.js, with plugins support and easy extensibility based on Store.js.
Stars: ✭ 161 (+89.41%)
Mutual labels:  storage, localstorage, vue-plugin
mst-persist
Persist and hydrate MobX-state-tree stores (in < 100 LoC)
Stars: ✭ 75 (-11.76%)
Mutual labels:  localstorage, sessionstorage
Depot.js
πŸ“¦ depot.js is a storage library with a simple API
Stars: ✭ 247 (+190.59%)
Mutual labels:  storage, localstorage
cache-bucket
Light Cache for nodeJs and browserJs with TTL.
Stars: ✭ 14 (-83.53%)
Mutual labels:  localstorage, sessionstorage
vue-storage-watcher
a reactive storage plugin for vue πŸ‘€πŸ”­
Stars: ✭ 60 (-29.41%)
Mutual labels:  localstorage, sessionstorage
local-storage-fallback
Check and use appropriate storage adapter for browser (localStorage, sessionStorage, cookies, memory)
Stars: ✭ 103 (+21.18%)
Mutual labels:  localstorage, sessionstorage
ngx-localstorage
An Angular wrapper for localstorage/sessionstorage access.
Stars: ✭ 27 (-68.24%)
Mutual labels:  localstorage, sessionstorage
Flutter localstorage
πŸ“¦flutter localstorage for ios/android/desktop/web
Stars: ✭ 206 (+142.35%)
Mutual labels:  storage, localstorage

Vue Web Storage

downloads npm-version github-tag license tests codecov ts

A minimalistic Vue.js plugin for web storage

Version matrix

Vue.js version Package version Branch
2.x 5.x 5.x
3.x 6.x master

Features

  • Choose either localStorage or sessionStorage or both
  • Prefix all of your stored keys
  • Auto JSON.stringify and JSON.parse
  • Events for cross tab communication

Installation

# yarn
yarn add vue-web-storage

# npm
npm install vue-web-storage

Usage

import {createApp} from 'vue';
import StoragePlugin from 'vue-web-storage';

const app = createApp({}).mount('#app')
app.use(StoragePlugin);
// Use in your components
// this.$localStorage

Configuration (optional)

app.use(StoragePlugin, {
    prefix: 'your_app_slug_',// default `app_`
    drivers: ['session', 'local'], // default 'local'
});

// It will register two different instances
// this.$sessionStorage
// this.$localStorage

Methods

All methods take care of prefix in key name, so you no need to specify the prefix when using them.

set(key,value)

Stores the value under specified key in storage. Convert value to JSON before saving. This method throws error on failure.

this.$localStorage.set('name', 'john')
this.$localStorage.set('isAdmin', true)
this.$localStorage.set('roles', ['admin', 'sub-admin'])
this.$localStorage.set('permission', {id: 2, slug: 'edit_post'})

get(key, ?defaultValue = null)

Retrieves given key value from storage, parse the value from JSON before returning. If parsing failed then throws error.

this.$localStorage.get('name')
this.$localStorage.get('doesNotExistsInStorage', 'defaultValue')

remove(key)

Removes the individual key from storage.

this.$localStorage.remove('name')

clear(?force = false)

Removes all keys from storage. Passing true will clear whole storage without taking prefix into consideration.

this.$localStorage.clear()

keys(?withPrefix = false)

Returns array of keys stored in storage. Passing true will return prefixed key names.

this.$localStorage.keys()

hasKey(key)

Returns true if key exists in storage regardless of its value.

this.$localStorage.hasKey('name')

length()

Returns the number of keys stored in storage.

this.$localStorage.length()

Events

  • πŸ’‘ These are not regular Vue.js events, these events to be used for cross tab communication.

on(key,fn)

Attaches a listener method to the given key. You can attach multiple methods on the same key.

const onChangeName = (newValue, OldValue, originUrl) => {
    // do something when `name` value gets changed
};
this.$localStorage.on('name', onChangeName);
this.$localStorage.on('name', this.anotherMethod)

off(key,fn)

Removes specified listener method form the given key.

this.$localStorage.off('name', this.onChangeName)

clearEvents(?key)

  • Removes all listeners for the given key otherwise clears the listeners pool when key not specified.
this.$localStorage.clearEvents('name');
this.$localStorage.clearEvents()

Install in non-module environments (without webpack)

<!-- Vue js -->
<script src="https://cdn.jsdelivr.net/npm/vue@3"></script>
<!-- Lastly add this package -->
<script src="https://cdn.jsdelivr.net/npm/vue-web-storage@6"></script>
<!-- Init the plugin -->
<script>
    yourApp.use(VueWebStorage.default)
</script>

Testing

  • This package is using Jest for testing
  • Tests can be found in __test__ folder.
  • Execute tests with this command yarn test

Resources

Changelog

Please see CHANGELOG for more information what has changed recently.

License

MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].