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

ivoire-one-of

v1.0.0

Published

A plugin for the Ivoire random number generator framework.

Downloads

3

Readme

ivoire-one-of

Pick items out of a hat. A plugin for the Ivoire random number generator framework.

Installing

To install, use npm:

npm install ivoire-one-of

Alternately, you can find the source on Github.

Getting Started

ivoire-one-of extends the ivoire package. You can require it directly:

var Ivoire = require('ivoire-one-of');

Or you can require it alongside ivoire:

var Ivoire = require('ivoire');
require('ivoire-one-of');

Either way, instantiate and start rolling!

var ivoire = new Ivoire();
var one = ivoire.one_of('red', 'blue', 'orange', 'green');

// Cycle through the sequence, returning each item in order and wrapping
// back to the beginning:
one.cycling();

// Cycle through the sequence, returning each item in order until we reach
// the end of the sequence. Continue to return the last item forevermore
// after.
one.stopping();

// Return a random item from the sequence, never returning the
// same item twice in a row.
one.randomly();

// Return a random item from the sequence. May return the same item twice
// or more times in a row!
one.truly_at_random();

// Shuffle the sequence and iterate through, wrapping around to the
// beginning of the shuffled sequence.
one.in_random_order();

Reference

ivoire-one-of adds some methods to the Ivoire prototype object, making them available on all Ivoire instances.

#one_of()

Syntax

ivoire.one_of(item1[, item2, item3...])

Usage

Return an object with methods for picking items from the provided arguments. The object is cached based on the stringification of the sequence of arguments.

var Ivoire = require('ivoire-one-of');
var ivoire = new Ivoire();

// The returned object will be cached:
var one = ivoire.one_of('red', 'blue', 'green', 'orange');
one.cycling() === 'red';

// When we need the same sequence again (from the same Ivoire instance), the
// same invocation retrieves the cached object and its state.
var another = ivoire.one_of('red', 'blue', 'green', 'orange');
another.cycling() === 'blue';

// If we work off of another Ivoire instance, we get a new cycle.
var ivoire_2 = new Ivoire();
var one_more = ivoire_2.one_of('red', 'blue', 'green', 'orange');
one_more.cycling() === 'red';

The object returned by #one_of() has the following interface:

one.cycling()

Usage

Cycle through the sequence, returning each item in order and wrapping back to the beginning.

var ivoire = new require('ivoire-one-of');
var one = ivoire.one_of('red', 'blue', 'green', 'orange');
one.cycling();

one.stopping()

Usage

Cycle through the sequence, returning each item in order until we reach the end of the sequence. Continue to return the last item forevermore after.

var ivoire = new require('ivoire-one-of');
var one = ivoire.one_of('red', 'blue', 'green', 'orange');
one.cycling();

one.randomly()

Usage

Return a random item from the sequence, never returning the same item twice in a row.

var ivoire = new require('ivoire-one-of');
var one = ivoire.one_of('red', 'blue', 'green', 'orange');
one.randomly();

one.truly_at_random()

Usage

Return a random item from the sequence without filtering repeats. May return the same item twice or more times in a row!

var ivoire = new require('ivoire-one-of');
var one = ivoire.one_of('red', 'blue', 'green', 'orange');
one.truly_at_random();

one.in_random_order()

Usage

Shuffle the sequence of items and iterate through it, one at a time, wrapping around to the beginning of the shuffled sequence. The shuffled order is maintained throughout.

var ivoire = new require('ivoire-one-of');
var one = ivoire.one_of('red', 'blue', 'green', 'orange');
one.in_random_order();

Acknowledgements

The one-of algorithm is based on the implementation in Undum.