Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@johnnywang/vue-localstore

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@johnnywang/vue-localstore

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

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

VueLocalStore

vue localStorage plugin with prefix, unique id injectable for vue2.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-localstore

Basic Introduction

create instance

Same as vue-router, create localStore instance

// localStore.js
import Vue from 'vue';
import VueLocalStore from 'vue-localstore';

Vue.use(VueLocalStore);

const localStore = new VueLocalStore({
  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 Vue from 'vue';
import localStore from './localStore';

new Vue({
  localStore,
}).$mount('#app');

access in component

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

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.

Keywords

FAQs

Package last updated on 13 Jan 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc