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

uniqueue

v1.0.0

Published

only queue unique items and retrieve them only once

Downloads

12

Readme

uniqueue NPM version Build Status Dependency Status Coverage percentage

only queue unique items and retrieve them only once

Installation

$ npm install --save uniqueue

Usage

'use strict';

const Uniqueue = require('uniqueue');

const { push, pop, remaining, queued, processed, clear } = new Uniqueue();

const urls = [
  'https://google.com',
  'https://google.com',
  'https://google.com/',
  'https://www.google.com'
];

// Only add unique items to the queue
urls.forEach(url => {
  push(url);
});
console.log('=>', queued.size, processed.size, remaining());
// => 3 0 3

// Extract items from queue
while (remaining() > 0) {
  console.log('=> remaining:', remaining());
  console.log('=>', pop());
  console.log('=> processed:', processed.size);
  console.log();
}
// => remaining: 3
// => https://google.com
// => processed: 1
//
// => remaining: 2
// => https://google.com/
// => processed: 2
//
// => remaining: 1
// => https://www.google.com
// => processed: 3

// Clear the queue
clear();
console.log('=>', queued.size, processed.size, remaining());
// => 0 0 0

// Use a custom matcher function to prevent similar duplicates
const matcher = (a, b) => {
  return (
    a.replace(/[^a-z]/gi, '') === b.replace(/[^a-z]/gi, '') ||
    a.replace(/:\/\/www\./i, '://') === b.replace(/:\/\/www\./i, '://')
  );
};
urls.forEach(url => {
  push(url, matcher);
});
console.log('=>', [...queued]);
// => [ 'https://google.com' ]

// * Use a custom matcher function during initialization
const queue = new Uniqueue(matcher);
// ...

API

Uniqueue([matcher])

Returns a new queue instance.

  • matcher

    • Optional : Function is evaluated on every attempt to add an item to the queue.

      • Overrides the default Set value equality check

      • e.g. (a, b) => a.name.toUpperCase() === b.name.toUpperCase() will prevent { name: "Bob" } from being added if { name: "BOB" } is already in the queue.

queue

Uniqueue instance.

  • .push(item [, matcher])

    Adds an item of Any type to the queue.

    • matcher

      Optional : Function overrides the matcher function provided during initialization (if it was provided).

  • .pop()

    Returns the next available item from the queue or null if no items are available.

  • .remaining()

    Returns the Number of available items from the queue.

  • .queued

    The Set holding all unique items added to the queue.

  • .processed

    The Set holding all items that have been pop()'d from the queue.

  • .clear()

    Clears the queue, including .queued and .processed.

License

ISC © Buster Collings