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-next-localstore

v0.0.5

Published

A tiny plugin for vue localstorage with version control & prefixed keys for vue3

Downloads

8

Readme

VueLocalStore

vue localStorage plugin with prefix, unique id injectable for vue3.x which can control version by version_name feature.

Install

VueLocalStore is an umd module, you can easily use by cdn or es6 module

$ npm install vue-next-localstore

Basic Introduction

create instance

Same as vue-router, create localStore instance

// localStore.js
import Vue from 'vue';
import { createLocalStore } from 'vue-next-localstore';

const localStore = createLocalStore({
  versionName: 'test_v0.0.1',
  versionNameKey: 'version_name', // default
  eventDataKey: 'event_data', // default
  prefix: '', // default
  uid: 'anonymous', // default: can be changed later by `setUid`
});

export default localStore;

inject to vue intance

// main.js
import { createApp } from 'vue';
import App from './App.vue';
import localStore from './localStore';

createApp(App).use(localStore).mount('#app');

access in option API component

// App.vue
export default {
  mounted() {
    console.log(this.$localStore);
  },
};

access in composition API component

import { useLocalStore } from 'vue-next-localstore';

export default {
  setup() {
    const localStore = useLocalStore();
    localStore.set('name', 'johnny');
    return {
      ls: localStore,
    };
  },
};

bind to template

<template>
  <div>
    {{ ls.get('name') }}
  </div>
</template>

API Introduction

setUid(uid)

set prefixed uid content, uid will be concat as bellow:

params

  1. uid
  • type: string
  • default: anonymous
const prefixedKey = `${prefix}${uid}_${key}`;

demo

export default {
  created() {
    this.$localStore.setUid('good_uid_30678444');
  },
};

setRoot(key, value)

set localstorage to root key(real localstorage)

params

  1. key
  • type: string
  1. value
  • type: any

demo

export default {
  created() {
    this.$localStore.setRoot('name', 'Johnny');
  },
};

getRoot(key)

get localStorage root key's value

params

  1. key
  • type: string

demo

export default {
  created() {
    this.$localStore.getRoot('name');
  },
};

removeRoot(key)

remove localStorage root key

params

  1. key
  • type: string

demo

export default {
  created() {
    this.$localStore.removeRoot('name');
  },
};

set(key, value)

set event data key with value, the key will be prefixed.

params

  1. key
  • type: string
  • desc: will be auto prefixed before editing
  1. value
  • type: any

demo

export default {
  created() {
    this.$localStore.set('name', 'Johnny');
  },
};

get(key)

get event data key's value, the key will be prefixed.

params

  1. key
  • type: string
  • desc: will be auto prefixed before editing

demo

export default {
  created() {
    this.$localStore.set('name', 'Johnny');
  },
};

remove(key)

remove event data key, the key will be prefixed.

params

  1. key
  • type: string
  • desc: will be auto prefixed before editing

demo

export default {
  created() {
    this.$localStore.remove('name');
  },
};

Configs

versionName(required)

version_name for this content

versionNameKey(optional, default: 'version_name')

localStorage key name for storing version_name

eventDataKey(optional, default: 'event_data')

localStorage key name for storing event_data

prefix(optional, default: '')

prefix value for event_data object's property

uid(optional, default: 'anonymous')

inject uid to seperate user or other usage, can be modified later by setUid api.