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

storage-sync-lite

v1.1.19

Published

Easily store objects or any type of data to localStorage or sessionStorage.

Downloads

32

Readme

storage-sync-lite NPM Version Install Size Downloads License: MIT

Easily store objects or any type of data to localStorage or sessionStorage. Why this? When you store a JSON/object to localStorage or sessionStorage you need to stringify the data. After storing a number in localStorage when you will read it, you will get the number as a string. But storage-sync-lite allows storing and retrieving data without changing the type. If you store an object when you will read, it will return the object.

Table of Contents

Features

  • Set, get and delete localStorage or sessionStorage without stringifying or changing the data type.
  • Change/update objects in localStorage or sessionStorage.
  • Clear localStorage or sessionStorage.

Install

npm i storage-sync-lite

Usage

Set and get local:

import { setLocal, getLocal } from 'storage-sync-lite'

// Set/Store
setLocal('user', {
    email: '[email protected]',
    age: 25
})

// Get
let user = getLocal('user')
console.log(user) // Returns: { email: '[email protected]', age: 25 }

Change/update properties from local:

import { changeLocal, getLocal } from 'storage-sync-lite'

// Change/update properties
changeLocal('user', {
    name: 'Mr. User'
})

console.log(getLocal('user')) // Returns: { email: '[email protected]', age: 25, name: 'Mr. User' }

Delete data from local:

import { deleteLocal, clearLocal } from 'storage-sync-lite'

// Delete single data from local
deleteLocal('user')

// Clear / delete all data from local
clearLocal()

Set and get session:

import { setSession, getSession } from 'storage-sync-lite'

// Set/Store
setSession('user', {
    email: '[email protected]',
    age: 25
})

// Get
let user = getSession('user')
console.log(user) // Returns: { email: '[email protected]', age: 25 }

Change/update properties from session:

import { changeSession, getSession } from 'storage-sync-lite'

// Change/update properties
changeSession('user', {
    name: 'Mr. User'
})

console.log(getSession('user')) // Returns: { email: '[email protected]', age: 25, name: 'Mr. User' }

Delete data from session:

import { deleteSession, clearSession } from 'storage-sync-lite'

// Delete single data from session
deleteSession('user')

// Clear / delete all data from session
clearSession()

API Reference

setLocal(name, value, options)

Stores a value in local storage.

  • name (string): The name of the item to store.
  • value (*): The value to store.
  • options (object, optional): Optional configuration object.
    • options.expiration (string | number | Date): The expiration date/time for the item.
    • options.timeToLive (number): The time to live in milliseconds.

Returns the stored value.

getLocal(name)

Retrieves a value from local storage.

  • name (string): The name of the item to retrieve.

Returns the value stored in local storage, or undefined if the item does not exist or has expired.

changeLocal(name, changes)

Updates a value in local storage with the provided changes.

  • name (string): The name of the item to update.
  • changes (object): An object containing the changes to apply to the stored value.

Returns the updated value.

deleteLocal(name)

Deletes an item from local storage.

  • name (string): The name of the item to delete.

clearLocal()

Clears all items from local storage.

setSession(name, value, options)

Stores a value in session storage.

  • name (string): The name of the item to store.
  • value (*): The value to store.
  • options (object, optional): Optional configuration object.
    • options.expiration (string | number | Date): The expiration date/time for the item.
    • options.timeToLive (number): The time to live in milliseconds.

Returns the stored value.

getSession(name)

Retrieves a value from session storage.

  • name (string): The name of the item to retrieve.

Returns the value stored in session storage, or undefined if the item does not exist or has expired.

changeSession(name, changes)

Updates a value in session storage with the provided changes.

  • name (string): The name of the item to update.
  • changes (object): An object containing the changes to apply to the stored value.

Returns the updated value.

deleteSession(name)

Deletes an item from session storage.

  • name (string): The name of the item to delete.

clearSession()

Clears all items from session storage.

Contributing

You are welcome to contribute! If you are adding a feature or fixing a bug, please contribute to the GitHub repository.

License

storage-sync-lite is licensed under the MIT license.

Author

|@SheikhAminul| |:---:| |@SheikhAminul|