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

socrative.js

v1.0.0-patch

Published

Socrative.JS is a Node.JS client for the quiz game 'Socrative'.

Downloads

5

Readme

Socrative.JS

Version 1.0.0

How To Install

To install Socrative.JS, run the command npm i socrative.js.

Once installed, you can import socrative.js into your program.

How To Import an ESM Module (like socrative.js)

Using ESM:

The recommanded way to import an ESM module is to switch your project to ESM as well. To do this, you to need to add the following like to your package.json file.

"type":"module"

Once your package type is set to module, you can add

import Socrative from "socrative.js"

to the top your script.

Using CommonJS:

You may also import Socrative trough CommonJS with the following statement:

var Socrative = (await import("socrative.js")).default;

How to use Socrative.JS

Socrative.JS is relatively easy to use compared to Blooket.JS and Quizlet.JS. The reason for this is that Socrative.JS does not use WebSockets.

Events

Socrative.JS contains 3 events.

  • question

The question event is emitted when it is time to answe a question. The question event returns 3 paramters. The first one is the question name (String), the second one is the question type (String), and the third one changes depending on the question.

  1. If the question is a True/False (type: TF) or Multiple Choice (type: MC), the third paramater is the choices (Array)
  2. If the question is a written question (type: FR), there is no third paramater

  • answer

The answer event is emitted when the client has sent the server your answer for a question. This event returns 3 parameters. The first one is if you were correct or not (Boolean), the second is the correct answers (Array). The third parameter is the explanation (String)


  • end

The end event is emitted when all questions have been answered. This event returns no parameters

Functions

Socrative.JS contains 2 functions and a constructor.

  • constructor(pin, name)

The constructor requires the room pin, and your name. This initalizes the class but does not join the game.


  • joinGame()

The joinGame function validates your PIN and joins the game. After joining, you will receive your first question event.


  • answer(a)

The answer(a) function takes your answer (String) and sends it to the server. You are supposed to use this function is conjuction with the question event.

Constants

Socrative.JS also has constants. I recommend not messing with them, but here they are.

  • name (String)

Your Name

  • pin (String)

The Room PIN/Code

  • currentQuestion (Object)

The current question data

  • questionData (Array)

The data for all the questions

  • sessionId (String)

The client's session ID.

Example

import Socrative from "socrative.js";

var game = new Socrative("P1NC0D3", "Socrative.JS Bot"); // Create a new instance
game.joinGame(); // Join the game
game.on("question", (q, t, o) => {
    if (t == "TF" || t == "MC") {
        game.answer(o[0]); // If the question is "True or False" or a "Multiple Choice" question
    } else {
        game.answer("Socrative.JS is awesome") // answer for Open Ended questions
    }
})
game.on("answer", (c, a, e) => {
    console.log(
        `You were ${c ? "correct" : "wrong"}, the correct answer was ${a[0] || "under review"}. The reason for that is ${e || "not listed"}`
    ) // Console.log details about your answer
})
game.on("end", () => {
    console.log("The game has ended") // The game is over
})