Coder Social home page Coder Social logo

mazipan / nuxt-storage Goto Github PK

View Code? Open in Web Editor NEW
126.0 2.0 8.0 1.33 MB

๐Ÿ›ข Utilities for easy read and write browser's storage in Nuxt.js project

License: MIT License

JavaScript 12.00% TypeScript 88.00%
nuxt nuxt-storage browser-storage localstorage sessionstorage

nuxt-storage's Introduction

๐Ÿ›ข Nuxt-Storage

All Contributors version downloads Travis codecov Dependencies

Utilities for easy read and write browser's storage in Nuxt.js project

Why I need this package?

In Nuxt, it's hard to play with browser's storage like sessionStorage and localStorage. This package will help you handle client side storage with a simple API and with various useful additional features such as expiry.

How to install and use

Install using NPM or Yarn

# NPM
$ npm i nuxt-storage

# Yarn
$ yarn add nuxt-storage

Sample using this package

Set data
import nuxtStorage from 'nuxt-storage';

nuxtStorage.localStorage.setData('key', 'value');
nuxtStorage.sessionStorage.setData('key', 'value');

//Set data with expiry time

// default time is 5 minutes, set it to 15
nuxtStorage.localStorage.setData('key', 'value', 15);

// default time unit is minutes , set it to hours, so type 'h'
nuxtStorage.localStorage.setData('key', 'value', 1, 'h');
Get data by value
nuxtStorage.localStorage.getData('key');
nuxtStorage.sessionStorage.getData('key');
Remove or clear storage (localStorage/sessionStorage)
// Remove single item by **key**
nuxtStorage.localStorage.removeItem('key');
nuxtStorage.sessionStorage.removeItem('key');

// Clear entire storage
nuxtStorage.localStorage.clear());
nuxtStorage.sessionStorage.clear();

API options

Method Name Parameter Default Value Available Options
getData key (type: String) Empty String
setData key (type: String) Empty String
value (type: any) Empty String
expiry (type: Number) 5
expiryUnit (type: String) m s = second, m = minutes, h = hour, d = day
removeItem key (type: String)
clear -

Support me


Copyright ยฉ 2018 by Irfan Maulana

Contributors โœจ

Thanks goes to these wonderful people (emoji key):

notjiam
notjiam

โš ๏ธ ๐Ÿ›
Irfan Maulana
Irfan Maulana

๐Ÿ› ๐Ÿšง โš ๏ธ ๐Ÿ’ป
Jakub Zomerfeld
Jakub Zomerfeld

๐Ÿ“

This project follows the all-contributors specification. Contributions of any kind welcome!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.