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 🙏

© 2026 – Pkg Stats / Ryan Hefner

useful-web-storage

v1.0.2

Published

Simple and powerful storage library.

Readme

English | 简体中文 | 正體中文

useful-web-storage

Simple and powerful storage library.

:sparkles: Features

  • :zap: Lightweight, only 1kb after minified and gzipped
  • :clock12: Support setting expiration time, the default expiration time is zero on the next day
  • 🛡 Written in TypeScript with predictable static types
  • :package: No package dependencies

:package: Installation

Using npm or yarn

$ npm install --save useful-web-storage
$ yarn add useful-web-storage

:pencil: Usage

Browser

Add script tags in your browser and use the global variable usefulWebStorage.

<script src="lib/useful-web-storage/index.min.js"></script>
<script>
  const storage = usefulWebStorage.storage;
  storage.clearExpiredStorage();
  storage.set('name', 'useful-web-storage', storage.permanent);
  storage.get('name');
</script>

Use with RequireJS

define(['useful-web-storage'], function(usefulWebStorage) {
  usefulWebStorage.storage.set('name', 'useful-web-storage');
});

Typescript

import { storage, session } from 'useful-web-storage';

interface IUserInfo {
  name: string;
  age: number;
  hasPermission: boolean;
  hobby: string[];
}

const userInfo: IUserInfo = {
  name: 'kingmui',
  age: 18,
  hasPermission: true,
  hobby: ['sleep', 'music'],
}

// localStorage
storage.set('userInfo', userInfo, storage.permanent);
const user = storage.get<IUserInfo>('userInfo');

// sessionStorage
storage.set('userInfo', userInfo);
session.get<IUserInfo>('userInfo');

:bulb: API

set: (key: string, val: any, exp?: number | Date) => any

When passed a key name and value, will add that key to the storage, or update that key's value if it already exists.

When exp is a number, it indicates how many days will expire. The default expiration time is zero on the next day. If you want permanent storage, please manually pass in storage.permanent.

get: <T>(key: string) => T | null

When the obtained value does not expire, return the value. In the TypeScript project, you can also specify the type of the return value.

has: (key: string) => boolean

Determine storage has the key.

touch: (key: string, exp: number | Date) => void

Set a new timeout for the stored value (not expired) based on the current time.

remove: (key: string) => void

When passed a key name, will remove that key from the storage.

clear: () => void

When invoked, will empty all keys out of the storage.

clearExpiredStorage: () => void;

Only clear expired storage.

getAll: () => Record<string, any> | undefined

Get all the storages.

forEach: (callback: (key: string, val: any) => void) => void

forEach the storages and call the callback function with each storage.

isSupported: () => boolean

Check if the browser supports localstorage. If not supported, nothing will be done.

length: () => number

Returns an integer representing the number of data items stored in the Storage object.

key: (n: number) => string | null

Get the name of the nth key in the storage.

permanent: Date

Permanently store constant.

:rocket: Download

Download the latest version of useful-web-storage at https://github.com/fe-useful-tools/useful-web-storage/releases

License

useful-web-storage is licensed under a MIT License.