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

ts-local-storage-manager

v0.11.0

Published

TypeScript wrappers and implementations for javascript 'Storage' (i.e. localStorage/sessionStorage) type objects

Downloads

2

Readme

TypeScript Local Storage Manager

Dependencies: none

TypeScript wrappers for treating 'Storage' instances (i.e. 'localStorage' type objects in browsers) like collections.

The Goal:

Provide an easy to setup wrapper for 'localStorage' which can be used throughout a project in place of localStorage and also:

  • (work in progress) exposes changes to the underlying 'localStorage' object seamlessly (i.e. if a 3rd party library modifies 'localStorage', the objects/classes in this library should reflect those changes)
  • provides meta-data tracking, such as:
    • the total size of the data in 'localStorage'
    • whether local storage is currently full
    • history of added/removed items
    • whether an item is a string or a stringified object
  • callbacks to track when old items are removed due to local storage being full, useful for archiving old data

Example:

import MemoryStore = require("ts-local-storage-manager/local-store/MemoryStore");
import LocalStorageStore = require("ts-local-storage-manager/local-store/LocalStorageStore");

var store = LocalStorageStore.newTimestampInst(typeof window !== "undefined" ? localStorage : new MemoryStore(5000000));

var doJsonEncode = true; // supports objects as 'data', if false only strings, numbers, and booleans can be properly stored in the 'store'
var data = ...;

store.setItem("key-1234", data, doJsonEncode);

var result = store.getItem("key-1234", doJsonEncode);

store.removeItem("key-1234");

API:

LocalStoreByCategory

A class which contains a group of other LocalStores and allows you to treat 'localStorage' like a group of collections.

LocalStorageStore and LocalStoreWrapper

Provide additional validation on top of existing 'StorageLike' or 'LocalStore' objects.

MemoryStore

Provides a pure in-memory implementation of the interface exposed by 'localStorage' (i.e. lib.d.ts 'Storage').

LocalStoreEntry

Wrappers for accessing a strongly typed LocalStore key-value without having to retype the key each time you access it.

See the test/ directory for example usage of the functions in this project.