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

dwarves-days

v1.3.0

Published

Create lists of seven items in the style of xkcd #1417

Downloads

3

Readme

Dwarves Days

Dwarves Days is a simple package for creating random sets of seven items taken from other sets. It is inspired by the xkcd comic "Seven".

A demonstration site is available.

The source code is organized into two directories:

  • core: The package itself
  • site: The demonstration site

Installation

Node

The package is published on the npm registry as dwarves-days:

npm install --save dwarves-days

Browser

A UMD file (dwarves-days.umd.js) is provided in the package that can be used directly in the browser. This can be installed using a CDN such as jsDelivr: https://cdn.jsdelivr.net/npm/[email protected]/dwarves-days.umd.js

This file will export the module as CommonJS, AMD, or a dwarvesDays global variable.

(Note: Unbundled and unminified UMD modules [for CommonJS and AMD] are provided under the umd directory in the published package. These are deprecated in favor of the single UMD file mentioned previously.)

Usage

Simple example:

const dwarvesDays = require('dwarves-days');
console.log(dwarvesDays.getItems(dwarvesDays.SETS));

The getItems method takes an array of sets of seven and returns a random set of seven with items from different sets. The SETS variable is an array of sets based on the original comic, as analyzed by explain xkcd.

The input sets are represented as objects with a name and items. In TypeScript this is represented using the Set interface. For example:

import { Set } from 'dwarves-days';
const daysOfWeek: Set = {
	name: 'days of the week',
	items: [
		'Monday',
		'Tuesday',
		'Wednesday',
		'Thursday',
		'Friday',
		'Saturday',
		'Sunday',
	]
};

The result set is an array of objects each containing a setName and an itemName. In TypeScript each item is represented using the ResultItem interface. For example:

import { ResultItem } from 'dwarves-days';
const randomSet: ResultItem[] = [
	{ setName: 'Seven Seas', itemName: 'Gulf of Mexico' },
	{ setName: 'colors of the rainbow', itemName: 'green' },
	{ setName: 'seven seals', itemName: 'fifth seal' },
	{ setName: 'Seven Sisters', itemName: 'Barnard' },
	{ setName: 'days of the week', itemName: 'Sunday' },
	{ setName: 'layers of the OSI model', itemName: 'physical' },
	{ setName: 'Seven Wonders of the Ancient World', itemName: 'Lighthouse of Alexandria' },
];

To express this in the format of the original comic, one may use the first (actual) set as the prompt:

Can you name the Seven Seas?

Sure, there's...Gulf of Mexico, green, fifth seal, Barnard, Sunday, physical, Lighthouse of Alexandria.

License

The package and site are available under the MIT License. Refer to LICENSE.txt for details.