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

localstorage-ext

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

localstorage-ext

This library provides tools for localStorage in browsers.

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

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

Frontend localStorage Extension

This library provides tools on how to:

  • Check if localStorage is supported
  • Check if localStorage has an Item
  • Get the amount of space left in localStorage
  • Get the maximum amount of space in localStorage
  • Get the used space in localStorage
  • Get a Backup of localStorage
  • Apply a Backup to localStorage
  • Dump all information of localStorage in the console

Example

console.log('LocalStorage supported:', LocalStorage.isSupported)
// true https://caniuse.com/#search=localstorage (except Opera Mini)

if(LocalStorage.isSupported) {

    localStorage.setItem('asd', 'ASDASD')
    // sets or overwrites the item "asd"

    var backup = LocalStorage.getBackup()
    // creates an backup, we will need it later!

    console.log(JSON.stringify(backup))
    // this is how the backup looks like

    // The maximum storage-space possible in my tests: ~5MB
    //  - 5242880 Chrome, Firefox
    //  - 5000000 Edge, IE

    var usedSpace = LocalStorage.getUsedSpace()
    console.log('Used Space:', usedSpace)

    var maxSpace = LocalStorage.getMaximumSpace()
    console.log('Maximum Space:', maxSpace)

    var remSpace = LocalStorage.getRemainingSpace()
    console.log('Remaining Space:', remSpace)

    console.log('SpaceCheck', maxSpace === usedSpace + remSpace)
    // true 😉

    console.log('hasItem', LocalStorage.hasItem('nothis0ne'))
    // we don't have this one in our localStorage

    localStorage.clear()
    // oops, we deleted the localStorage!

    console.log('has asd', LocalStorage.hasItem('asd'))
    // item "asd" is lost 😒

    LocalStorage.applyBackup(backup)
    // but we have a backup, restore it!

    LocalStorage.consoleInfo()
    // show all the info we have, see the backup worked 😊
}

FAQ

  • [link] How to store Objects or Arrays in localStorage *
  • [link] How to store an Array in localStorage *
  • [link] How to save an Image in localStorage
  • [link] localStorage Tutorial (also covers storage events and things to remember)

* Spoiler: Use JSON.stringify() and JSON.parse()

Other

  • [link] General Information about Web Storage
  • [link] sessionStorage data stored gets cleared when the page session ends
  • [link] indexedDB a low-level API for client-side storage of structured data
  • [link] StackOverflow post

Keywords

FAQs

Package last updated on 03 Jun 2019

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