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

lri

v1.0.0

Published

A collection (backed by an array) that evicts the least recently inserted (lri) element from of the collection once it has reached a defined capacity. It is similar to an lru cache except that it uses insertion position to determine eviction rather than w

Downloads

3

Readme

lri

lri, which stands for least recently inserted, is a simple collection (backed by an array) that can be used to store up to N number of elements without having to manage the removal of elements once the size of the collection has reached N. This can be useful in a number of situations where you only care about tracking a limited number of elements. Some examples include:

  1. A collection that tracks the user's last 20 operations so they can be undone/redone.
  2. A collection that tracks the last 50 price stock price changes (ie. last 50 ticks) so you can run calculations against the collection.

Once the max capacity of the collection has been reached, adding another element to the collection will evict the oldest element in the collection.

Install

$ npm install lri

Conventions

Given that this essentially a glorified array wrapper with some added functionality, the naming conventions and functionality mimic Array closely.

Interface

lri(maxSize)

The constructor that, when invoked, initializes a new lri collection that's bound by the maxSize parameter. The maxSize parameter must be a valid integer greater than zero.

shift()

Removes and returns the first element of the collection. If the collection is empty, undefined is returned.

unshift(el)

Adds the parameter el to the front of the collection. If the collection has reached its capacity, the last (oldest) element of the collection is removed and returned.

size()

Returns the current size of the collection (ie. the current number of elements).

slice([begin[, end]])

An array (shallow copy) that represents the elements in the collection from the begin index to the end index. Leaving the indexes blank with result in the entire collection being returned. See [Array#slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice] for additional details.

peek()

The element most recently inserted into the collection, or undefined if the collection is empty.

Tests

lri has complete code coverage. To run the tests, do the following:

$ npm install
$ npm test

To view the coverage report (via Istanbul), do the following:

$ npm install
$ npm run coverage