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 🙏

© 2025 – Pkg Stats / Ryan Hefner

rpsjs

v1.5.2

Published

make your rock paper scissors project more easier and faster.

Downloads

8

Readme

RockPaperScissorsJS


Table of content

Introduction


RockPaperScissorsJS is a JavaScript library that simplifies the process of creating the popular rock paper scissors game. It's easy to use and is available in a JavaScript class format, where your Play instance will be considered an object.

To get started, you can create a new instance of Play like this:

  const player = new Play(); 

The Roll(choice) function is where most of the game logic happens. It takes an argument representing the user's guess, which can be one of three options: rock, paper, or scissors. Here's an example of how to use Roll():

console.log(player.Roll('paper'));  

The Roll() function generates a random guess for the computer and compares it to the user's guess. It then returns an object with three properties: user, computer, and won. The user property represents the user's guess, the computer property represents the computer's guess, and the won property is a Boolean value that indicates whether the user won (true), lost (false), or tied (draw).

Here's an example of what the output from Roll() might look like:

{
  user: 'paper',
  computer: 'scissors',
  won: false
}

getting started


getting started you will first require the library which can be done by using the script tags or imported on a node project

Browser or CDN

To use RockPaperScissorsJS in your browser, you can include it directly from a CDN. For example, you can use the following script tag in your HTML file:

   <script src="./path/to/rockPaperScissors.JS"> </script> // get the library from the path where it's located

or if you are using a CDN then you can use the following

   <script src="https://cdn.jsdelivr.net/npm/[email protected]/rockPaperScissors.min.js"></script> 

place the CDN link onto the header

Node.js

To use RockPaperScissorsJS in your Node.js project, you can install it via NPM. Simply run the following command in your project directory:

npm install rpsjs

Once installed, you can import the library into your Node.js module using either require() or import statements:

// Using require()
const { Play } = require('rpsjs');
// Using import statement
import { Play } from 'rpsjs';

Downloading the library

Alternatively, you can also download the library as a ZIP file from the GitHub repository and include it in your project directory. This can be useful if you want to modify the source code or use a specific version of the library.

After downloading the ZIP file, extract its contents into your project directory and include the rockPaperScissors.min.js file in your HTML file or require/import it into your Node.js project as shown above.

then crate an object to use

    const player = new Play();// you can name it anything other than player

you can find the demos here

API functions

there are 6 major functions;

       Roll(user)
       Compute()
       Won(user, computer)
       Multiplayer(user,computer)
       Scores() // get users scores
       Clear() // clear scores and plays

Note that the functions begin with a capital letter.

Roll

Roll(user) This function takes a user's guess as an argument and generates a random computer guess. It then returns an object containing the user's guess, computer's guess, and whether the user won or lost.

const player = new Play();

console.log(player.Roll('paper'));

/*
{
  user: 'rock',
  computer: 'scissors',
  won: true
}
*/

the computer guess is randomly made.

Compute

Compute() This function generates a random computer guess and returns it.

const player = new Play();

console.log(player.Compute()); // 'rock', 'paper', or 'scissors'

you can do a lot more with this just check the examples here

Multiplayer

Multiplayer(player1 = this.user, player2 = this.friend) This function allows you to play Rock Paper Scissors with another player. The function takes two arguments, player1 and player2, which represent the choices made by the two players. By default, the function uses the user and friend choices stored in the Play object.

player1: The choice made by the first player. This can be either 'rock', 'paper', or 'scissors'. player2: The choice made by the second player. This can also be either 'rock', 'paper', or 'scissors'. The function returns an object that contains the game result.

Here's an example of how to use the Multiplayer function with arguments:

const player = new Play();
this.user = 'rock';
this.player = 'paper'
console.log(player.Multiplayer('rock', 'paper'));
// or  player.Multiplayer()

/*
{
  user: 'rock',
  friend: 'paper',
  won: false
}
*/

won

Won(user, computer) This function takes a user's guess and computer's guess as arguments and determines whether the user won, lost, or tied. It also updates the user's score internally.

const player = new Play('rock');

console.log(player.Won('rock', 'paper')); // false
console.log(player.Won('rock', 'scissors')); // true
console.log(player.Scores()); // { user: 1, computer: 0 }

Score

Scores() This function returns an object containing the user's score and computer's score.

const player = new Play();

console.log(player.Scores()); // { user: 0, computer: 0 }

Clear

Clear() This function resets the user's score and computer's score.

const player = new Play(10);

player.Won('rock', 'scissors');
console.log(player.Scores()); // { user: 1, computer: 0 }

player.Clear();
console.log(player.Scores()); // { user: 0, computer: 0 }

extra


Here are some additional resources you may find helpful:

  • Demo page - See the library in action with this simple demo page.
  • Documentation - Learn more about the available functions and how to use them.
  • GitHub repository - Clone or fork the source code to modify or contribute to the project.

If you have any questions or issues, feel free to create a new issue on the GitHub repositoryor reach out to the creator bethropolis.

License


Licensed under my favourate License, MIT License.