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

localstorage-encrypt

v1.1.0

Published

A library to help you encrypt data before storing in local storage

Downloads

24

Readme

localstorage-encrypt

Make your web application more secure by encrypting your client-side data before storing it in the local storage.

Installation

Using npm:

npm i localstorage-encrypt

Using yarn:

yarn add localstorage-encrypt

Getting started

The library is initialized with 3 parameters:

| name | Description | default | | ----------------- | ---------------------------------------------------------------------------- | ------------ | | name: string | What you want to use as a key in the browser's local localstorage | localStorage | | secretKey: string | The personal secret key for encrypting your data.required. | null | | expire: number | How long you want the data saved before it is deleted. The unit is in hours. | 12 |

import localstorageEncrypt from "localstorage-encrypt"
const ls = localstorageEncrypt.init("storage", "my-secret-key", 12)

Saving data

To save your data in the localStorage object you created when initializing the library.

It takes 2 parameters: the key and the value. The key has to be of string type and the data you're storing can be any data type.

const userData = { name: "Dotun", occupation: "developer" }
const authToken = eyghghfyheuehuhuoheouihih

ls.save("user", userData)
ls.save("token", authToken)
// has no return value

Get saved data

To get the saved data.

It takes a single parameter: the key you used to store the data. The key has to be of string type.

If you pass in a key that doesn't exist, it returns undefined.

ls.get("user")
// returns { name: "Dotun", occupation: "developer" }

Get all saved data

To get all data that has been saved.

It takes no parameters and returns an object containing everything you have saved so far in key-value pairs.

ls.getAll()
// returns { userData: { name: "Dotun", occupation: "developer" }, authToken: eyghghfyheuehuhuoheouihih }

Delete saved data

To delete a particular saved data.

It takes a single parameter: the key you used to store the data. The key is of type string.

ls.remove("authToken")
// removes authToken from saved data. only userData is left.
// has no return value

Delete all saved data

To delete every data that has been saved so far. This could be useful in a case where you want to completely reset your project state. For example, after a user has finished shopping and checked out but still remains logged in.

ls.clear()
// clears every data from the storage. only an empty object {} remains.
// Has no return value

Deactivate

Unlike the clear method that resets the saved data into an empty object, the deactivate method completely removes the saved data from the local storage and also removes the event listener that was implemented to check for the expiry of the saved data.

This could be very useful in the implementation of a logout feature for your project.

ls.deactivate()
// Completely removes the encrypted string from the local storage
// Has no return value