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

client-history

v1.0.6

Published

Store your items in localStorage as JSON string.

Downloads

2

Readme

Client History - lightweight library to store items in localStorage as JSON.

Need to store user actions, but your database would be too big for every user's actions? Store them in localStorage. This library can help you with it.

Feel free to use, check JSDoc for more information.

Wanna see in action? Check this page

Installation

  npm i client-history

Usage

Import library or add to page as ordinary script

NPM

  const ClientHistory = require('client-history');

ES6

  import ClientHistory from 'client-history';

Standalone script

Just copy lib.min.js from directory lib to one of your site folders, then add script on page.

  <script type="text/javascript" src="path/to/lib.min.js"></script>

Use in your code

constructor(initObj)

  let clientHistory = new ClientHistory({
    name: 'login',
    defaults: {
      limit: 10
    },
    checkFields: ['ip']
  })
Fields description:

name: Mandatory, array of items will be saved as JSON string to localHistory with this name.

defaults: Optional, settings object. By now you can only set the limit of items to save in array. Thus if you will push an item to the array that exceeding items limit, first element in array will be removed, and your item added at the very end of it.

checkFields: Optional, if set - your pushing item will be compared to all items in localStorage. If your item's fields described in checkFields will match item in localStorage array, that item will be removed from array, your item will be added at the end. It is useful if you want to keep some order in your stored items and don't want duplicates in it.

getItems()

Gets array saved as JSON string in localStorage, parses and returns it.

  clientHistory.getItems()

push(item)

Pushes item to array, saves array to localStorage as JSON string.

Your item can be anything you like to save, just make sure it's an object.

Example:

  clientHistory.push({
      date: new Date(),
      ip: yourIpMethod()
  })

drop()

Removes your array(saved as JSON string) from localStorage, so that you can start from scratch.

  clientHistory.drop()