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

rpsls

v0.9.0

Published

The canonical rock-paper-scissors-lizard-spock library.

Downloads

9

Readme

rpsls

Build Status Coverage Status npm

The canonical rock-paper-scissors-lizard-spock library.

Installation

npm i --save rpsls

Usage

Import library

The default export is a class with only static members.

import R from 'rpsls'

static members

The class will contain the following static members. See the explanation for each member in the sections below.

  • TIE
  • PLAYER1
  • PLAYER2
  • ROCK
  • PAPER
  • SCISSORS
  • LIZARD
  • SPOCK
  • getMoveName
  • play

Moves

The five moves in the game are accessed via static getters. They are aliases for the number 0 through 4.

console.log(
  R.ROCK,     //0
  R.PAPER,    //1
  R.SCISSORS, //2
  R.LIZARD,   //3
  R.SPOCK     //4  
);

Outcomes

The three outcomes of the game are static getters. They are aliases for the numbers 0, 1, and 2.

console.log(
  R.TIE,     //0
  R.PLAYER1, //1
  R.PLAYER2  //2
);

play

The static play method requires two parameters that represent the moves for player 1 and player 2 respectively. An object will be returned with the details of the game. The structure of the return object varies slightly depending upon whether the game is a tie or not.

Returned object for a TIE

let game = R.play(R.ROCK, R.ROCK);

//game will look like this
{
  outcome: 0,  //TIE
  result: "rock vs rock is a tie"
}

Returned object for a NON-TIE

let game = R.play(R.SPOCK, R.LIZARD);

//game will look like this
{
  outcome: 2,  //PLAYER2
  winner: 3,   //LIZARD
  loser: 4,    //SPOCK
  method: 'poisons'
  result: 'lizard poisons spock'
}

getMoveName

The static getMoveName method takes a single parameter that represents a move. A string will be returned that is the readable name of the given move.

R.getMoveName(R.SPOCK);  //'spock'
R.getMoveName(4);        //'spock'

Error Handling

Both play and getMoveName with throw an error if anything besides the integer numeric values of 0, 1, 2, 3, 4 are passed to them.

R.play(R.ROCK, 'foo');  //error
R.play(R.ROCK, '2');    //error
R.play(R.ROCK, 1.1);    //error
R.play(R.ROCK, 5);      //error
R.getMoveName('bar');   //error
R.getMoveName('2');     //error
R.getMoveName(1.1);     //error
R.getMoveName(5);       //error

Dev Process

This serves as a reminder to myself of how to develop this project.

  • clone repo
  • npm i
  • npm run typings
  • edit .ts/.spec.ts
  • npm run build
  • npm test
  • update npm version
  • commit