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

@fiddle-digital/string-storage

v0.0.1

Published

A lightweight and versatile JavaScript library for managing local and session storage in web applications. Offers automatic data persistence with expiry, seamless integration with form elements, and support for complex data structures. Ideal for enhancing

Downloads

30

Readme

Status

Overview

StringStorage is a TypeScript-based library that simplifies working with Web Storage (localStorage and sessionStorage), providing automatic handling of data persistence with expiration, seamless integration with HTML form elements, and support for complex data structures. It's crafted to enhance user experience by persisting form inputs and application states across sessions with minimal setup.

Features

  • Automatic Persistence: Effortlessly saves and restores form inputs and application state across page reloads and sessions.
  • Expiration Support: Allows setting expiration times for stored data, automatically removing expired data.
  • Easy Integration: Works out of the box with form elements for saving and restoring their values without additional coding.
  • Complex Data Handling: Supports saving not just string values but also complex data structures in a JSON-compatible format.
  • Session and Local Storage Management: Provides a unified API to interact with both localStorage and sessionStorage, simplifying their use.

Installation

npm install @fiddle-digital/string-storage

Then, import it in your project:

import StringStorage from '@fiddle-digital/string-storage';

Initialization

To start using StringStorage:

const storage = StringStorage.getInstance();

Working with Form Elements

StringStorage can automatically save and restore the values of form elements. Simply add the data-string-storage attribute to your form:

<form data-string-storage>
  <input type="text" data-string-id="username" />
  <textarea data-string-id="bio"></textarea>
  <select data-string-id="country">
    <option value="us">United States</option>
    <option value="ca">Canada</option>
  </select>
  <button type="submit">Submit</button>
</form>

Saving Data

To save data to localStorage:

storage.local.set('key', 'value', {days: 1});

To save data to sessionStorage:

storage.session.set('key', 'value');

Retrieving Data

To retrieve data from localStorage:

const value = storage.local.get('key', 'default');

Checking for Data Existence

const exists = storage.local.has('key');

Removing Data

To remove data from localStorage:

storage.local.delete('key');

Data Expiration

StringStorage allows setting expiration for stored data, which is automatically respected and cleaned up:

storage.local.set('temporary', 'data', {hours: 1});

After 1 hour, temporary will be automatically removed from storage.