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

@hooshid/local-store

v1.0.6

Published

localStorage with expire time

Downloads

13

Readme

local-store

Helpers to make local storage easier to use and just like cookie, having expire time.

Usage

import localStore from '@hooshid/local-store'

Methods

  • set — Add item to local storage.
  • get — Get item from local storage
  • remove — Remove item from local storage.
  • clearAll — Removes all or just Prefixed items from local storage.
  • has — Check item exist in local storage.
  • getExpireTime — Get item expire time.
  • getRemainTime — Get remaining TTL of a item.

Set

Set an item in local storage.

set(key: string, value: string, ttl?: number | string): void
  • key - The key of the item to set.
  • value - The value to set.
  • ttl - The time life in seconds format for living cache in localStorage.
  • ttl - The time life in default is one year, if you want set time life you should set in seconds or set like below format.
m for minute
h for hour
d for day

examples

  • 60m -> 60 minute
  • 1h -> 1 hour (equal to 60m)
  • 24h -> 24 hours (equal to 1d)
  • 1d -> 1 day
  • 30d -> 30 days

just use 1 above method and don't mixed (1d12h does not work -> 36h work fine!)

Get

Get an item from local storage.

get(key: string): string | null
  • key — The key of the item to get.

Remove

Remove item from local storage.

remove(key: string): void
  • key — The key of the item to remove.

Clear All

Removes all or just Prefixed items from local storage.

clearAll(prefix?: string): void
  • prefix — if prefix provided, only keys start with prefix cleared and if prefix undefined all keys cleared.

Has

Check key is exist

has(key: string): boolean
  • key — The key of the item.

Get Expire Time

Get item expire time.

getExpireTime(key: string): null|number
  • key — The key of the item.

Get Remain Time

Get remaining time of a item.

getRemainTime(key: string): null|number
  • key — The key of the item.

Todo

  • method for clear expired caches
  • output js script and define types separately