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

expire-array

v1.1.0

Published

An array-like structure that removes each element after a given timeout

Downloads

4,535

Readme

expire-array

An array-like structure that removes each element after a given timeout. Or think of it as a rolling window on top of an array which only contains the most recent elements.

Build status

js-standard-style

Installation

npm install expire-array

Example Usage

// Initialize with a timeout of 10 seconds
var arr = require('expire-array')(1000 * 10)

// Add elements to the array using .push()
arr.push(1)

// Retrive all elements from the array using .all()
arr.all() // => [1]

setTimeout(function () {
  // after 5 seconds
  arr.push(2)
  console.log(arr.all()) // outputs: [1, 2]
}, 1000 * 5)

setTimeout(function () {
  // after 11 seconds
  console.log(arr.all()) // outputs: [2]
}, 1000 * 11)

setTimeout(function () {
  // after 16 seconds
  console.log(arr.all()) // outputs: []
}, 1000 * 16)

API

Constructor

Initialize expire-array with a timeout in milliseconds:

var ExpireArray = require('expire-array')

var arr = ExpireArray(1000 * 60) // one minute

arr.push(elm)

Add an element to the end of the array.

arr.pop()

Removes the last element from an array and returns that element.

arr.shift()

Removes the first element from an array and returns that element.

arr.all()

Returns all the elements in the array that have not expired. The returned array is a clone and none of its elements will ever expire.

arr.forEach(callback[, thisArg]) (wrapper method)

Just like the equivalent Array.prototype.forEach() method, this forEach() method executes a provided function once per array element.

Parameters
  • callback - Function that produces an element of the new Array, taking two arguments
  • thisArg - Optional. Value to use as this when executing callback

Callback arguments:

  • currentValue - The current element being processed in the array
  • index - The index of the current element being processed in the array

arr.map(callback[, thisArg]) (wrapper method)

Just like the equivalent Array.prototype.map() method, this map() method creates a new array with the results of calling a provided function on every element in this array.

Parameters
  • callback - Function that produces an element of the new Array, taking two arguments
  • thisArg - Optional. Value to use as this when executing callback

Callback arguments:

  • currentValue - The current element being processed in the array
  • index - The index of the current element being processed in the array

arr.every(callback[, thisArg]) (wrapper method)

Just like the equivalent Array.prototype.every() method, this every() method tests whether all elements in the array pass the test implemented by the provided function.

Parameters
  • callback - Function to test for each element, taking two arguments
  • thisArg - Optional. Value to use as this when executing callback

Callback arguments:

  • currentValue - The current element being processed in the array
  • index - The index of the current element being processed in the array

arr.some(callback[, thisArg]) (wrapper method)

Just like the equivalent Array.prototype.some() method, this some() method tests whether some element in the array passes the test implemented by the provided function.

Parameters
  • callback - Function to test for each element, taking two arguments
  • thisArg - Optional. Value to use as this when executing callback

Callback arguments:

  • currentValue - The current element being processed in the array
  • index - The index of the current element being processed in the array

License

MIT