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

santas-de-roy

v1.1.0

Published

A secret santa API and CLI that takes into account past iterations to avoid re-assignations as much as possible.

Downloads

18

Readme

Santas-De-Roy

NPM Build Status codecov dependencies Status devDependencies Status renovate badge

A secret Santa API and CLI that takes into account past iterations to avoid re-assignations as much as possible.

History

It is tradition in my family to run a secret Santa every Christmases. Assignations used to be purely random. Which is good. But there is an issue.

After some years, it happens that I've already got the same Santa a few times while some people never gave me any gifts. I mean, I have nothing against the hand-made sweaters of grand-aunty Josette, but you know, change doesn't hurt...

Grand aunty's sweater

Alright, that is an assignment problem. We humans are very bad at that but clever algorithms can solve it. Grand-aunty, I love you. But from now on, let the computer magic takes care of who is my Santa!

Installation

npm install santas-de-roy

Original.

If you're only using the CLI and have internet access, you may not need to install it permanently and may want to use npx (installed by default with node >= 5.2).

CLI

Santa-De-Roy comes with a Command Line Interface: santas-de-roy.

Simple usage

If you do not care about history, you can just write down the names of all participants as arguments. For example:

> santas-de-roy Tintin Snowy Haddock Dupond Dupont
receivers:
  Tintin: Snowy
  Snowy: Dupond
  Haddock: Bianca
  Dupond: Haddock
  Dupont: Tintin
  Bianca: Dupont

They keys are the santas, and the value the receivers.

That's randomized by default, so if you run it again there is fair chance that nobody is going to have the same Santa again. But there is no guarantee it will not happen. Eventually it will.

History

But here comes the interesting part. If you provide a data path (YAML or JSON), it will be used to save the results. And next time, will be re-used to ensure that nobody will get the same santa twice (as much as possible).

> santas-de-roy --data history.yaml Tintin Snowy Haddock Dupond Dupont
2 past christmases found.
receivers:
  Tintin: Dupont
  Snowy: Bianca
  Haddock: Dupond
  Dupond: Tintin
  Dupont: Haddock
  Bianca: Snowy
New data written in history.yaml.

Blacklists and config file

Because it can be annoying and error prone to type each year the participants of you secret santa. You may use a config file using the --config argument. Here is an example of config file.

# Define the participants.
participants:
  - Tintin
  - Snowy
  - Haddock
  - Dupond
  - Dupont
  - Bianca

# Defines blacklist. In the example below, Haddock will not become Bianca's
# Santa, and Bianca will not become the Santa of Dupond or Dupont.
blackLists:
  Haddock:
    - Bianca
  Bianca:
    - Dupond
    - Dupont

# Exclusion groups are another way of defining blacklists. Participants
# part of the same exclusion group cannot be the santa of each others.
exclusionGroups:
  - - Dupond
    - Dupont

# Set up the path toward the history file.
data: history.yaml

# Set up an id for this particular santa assignations. Ids must be unique in the
# history.
id: chistmas2018

# Other available options (same as CLI options, see below).
random: true
dryRun: false
logLevel: info
ignoreHistory: false
quiet: false

Config files can be YAML or JSON.

Other CLI options

> santas-de-roy --help

Usage: cli [options] [participants ...]

An application to assign secret santas, optionally taking history into account.


Options:

  -V, --version        output the version number
  -c, --config [path]  set the config path (JSON or YAML)
  -d, --data [path]    set the history path (to be loaded and written, JSON or YAML)
  -d, --dry-run        do not write in the history file
  --ignore-history     ignore the history when computing the new assignations
  --log-level [level]  set the log level
  --no-random          do not randomize the assignations
  -q, --quiet          do not output results
  -i, --id [id]        give an identifier for this christmas to write in the data
  -h, --help           output usage information

API

santas-de-roy is also a library that exports a single function.

santasDeRoy(options) ⇒ Object.<string, string>

Returns: Object.<string, string> - The new assignations.

| Param | Type | Default | Description | | ------------------------- | ---------------------------------------------------------------------------- | ----------------- | --------------------------------------------------------------------------------------------------------------------------------- | | options | Object | Array.<string> | | Options for the generation. Alternatively, an array of participants can be directly provided. | | [options.participants] | Array.<string> | | The list of all participants. If omitted, then the participants appearing in exclusionGroups or as a blackLists key will be used. | | [options.history] | List.<Object.<string, string|List.<string>>> | | An array containing the previous attributions (dictionaries whose keys are the santas, and values their receiver). | | [options.blackLists] | Object.<string, Array.<string>> | | A dictionary whose keys are participants and values a list of participants they cannot be the santa of. | | [options.exclusionGroups] | Array.<Array.<string>> | | Exclusion groups of participants. A participant cannot be the santa of someone who is in his exclusion group. | | [options.randomize] | boolean | true | If true (default), randomizes the assignation algorithm. Makes the output non deterministic. |