npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-web-storage

v6.1.0

Published

Vue.js plugin for localStorage and sessionStorage

Downloads

3,894

Readme

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 as
// 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

  • :bulb: 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