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

@mewters/smart-storage

v1.0.0

Published

A JavaScript/TypeScript library designed to simplify working with localStorage, sessionStorage, and cookies by offering automatic object conversion and consistent API.

Downloads

4

Readme

Smart Storage

Smart Storage is a simple and easy-to-use library to manage local storage, session storage, and cookies with a consistent API, TypeScript support and object serialization.

Features

  • Simple API: The API is simple and easy to use.
  • TypeScript Support: The library is written in TypeScript and has type definitions.
  • Object Serialization: The library serializes and deserializes objects automatically. It means you can store and retrieve objects without any extra work.
  • Consistent API: The API is consistent across local storage, session storage, and cookies.
  • Safe Retrieval: The library provides a safe retrieval by always providing a default value.
  • Cookie Expiration: The library allows you to set the number of days the cookie will expire.
  • Lightweight: The library is lightweight and has no dependencies.
  • Tested: The library is well tested with 100% code coverage.

npm package Build Status Downloads Issues Code Coverage Commitizen Friendly Semantic Release

Install

npm install @mewters/smart-storage

Usage

import {
  LocalStorage,
  SessionStorage,
  CookieStorage,
} from '@mewters/smart-storage';

API

LocalStorage, SessionStorage, and CookieStorage have the same API.

Let's use LocalStorage as an example.

.get

Use the get method to retrieve a value from storage.

The key is an unique identifier for the value. The defaultValue is the value to return if the key does not exist.

If the key does not exist, it will return the default value. For a safe retrieval, always provide a default value.

LocalStorage.get('key1', 'defaultValue');
LocalStorage.get('key2', 5);
LocalStorage.get('key3', { defaultValue: 'value' });

.set

Use the set method to store a value in storage.

The key is an unique identifier for the value. The value is the value to store. It has to be a string, number, or object.

LocalStorage.set('key1', 'value');
LocalStorage.set('key2', 5);
LocalStorage.set('key3', { value: 'value' });

Note: The CookieStorage has an additional days parameter to set the number of days the cookie will expire. By default, the value is 365 days.

CookieStorage.set('key1', 'value');
CookieStorage.set('key2', 5, 30); // 30 days
CookieStorage.set('key3', { value: 'value' }, 7); // 7 days

.remove

Use the remove method to remove a value from storage.

The key is an unique identifier for the value to remove.

LocalStorage.remove('key1');

.removeItems

Use the removeItems method to remove multiple values from storage.

The keys is an array of unique identifiers for the values to remove.

LocalStorage.removeItems(['key1', 'key2']);

.clear

Use the clear method to remove all values from storage.

LocalStorage.clear();

smart-storage

smart-storage