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

missing-sock

v0.0.8

Published

**Missing Sock** is a developer-friendly library for building interactive quizzes and assessments in React applications. It provides a flexible and customizable framework to create, manage, and evaluate assessments with ease.

Downloads

13

Readme

Missing Sock

Missing Sock is a developer-friendly library for building interactive quizzes and assessments in React applications. It provides a flexible and customizable framework to create, manage, and evaluate assessments with ease.

Table of Contents

Installation

Install Missing Sock and its dependencies via npm or yarn:

npm install missing-sock
# or
yarn add missing-sock

Note: Ensure that your project has React and TypeScript configured, as Missing Sock is built with TypeScript support.

Getting Started

Import the Assessment component into your React application and define your assessment schema. Handle events such as start, completion, scoring, and metrics to integrate the assessment flow seamlessly.

Usage

Props and Events

The Assessment component accepts the following props:

  • questions (Schema): The assessment schema defining sections and questions.
  • onStart (() => void): Optional. Callback triggered when the assessment starts.
  • onComplete ((responses: Record<string, Response>) => void): Required. Callback triggered upon assessment completion with all user responses.
  • onScore ((responses: Record<string, Response>) => number): Optional. Callback to calculate the assessment score based on responses.
  • onMetrics ((metrics: { totalTime: number; timePerQuestion: Record<string, number> }) => void): Optional. Callback to capture metrics such as total time taken and time per question.

Example Question Schema

Below is an example of a Schema with a binary question:

import { Schema } from 'missing-sock'

const exampleSchema: Schema = {
  sections: [
    {
      title: 'General Knowledge',
      questions: [
        {
          id: 'q1',
          type: 'binary',
          prompt: 'Is the sky blue?',
          options: [
            { label: 'Yes', value: 'yes' },
            { label: 'No', value: 'no' },
          ],
        },
        // Add more questions here
      ],
    },
    // Add more sections here
  ],
}

Example

Here’s a complete example demonstrating how to use Missing Sock to create a simple assessment with a binary question:

import React from 'react'
import { Assessment, Schema, Response } from 'missing-sock'

const exampleSchema: Schema = {
  sections: [
    {
      title: 'General Knowledge',
      questions: [
        {
          id: 'q1',
          type: 'binary',
          prompt: 'Is the sky blue?',
          options: [
            { label: 'Yes', value: 'yes' },
            { label: 'No', value: 'no' },
          ],
        },
        // Add more questions as needed
      ],
    },
  ],
}

function App() {
  const handleStart = () => {
    console.log('Assessment started')
  }

  const handleComplete = (responses: Record<string, Response>) => {
    console.log('Assessment completed with responses:', responses)
  }

  const handleScore = (responses: Record<string, Response>): number => {
    let score = 0
    if (responses.q1 === 'yes') score += 1
    // Calculate score based on responses
    return score
  }

  const handleMetrics = (metrics: { totalTime: number; timePerQuestion: Record<string, number> }) => {
    console.log('Assessment metrics:', metrics)
  }

  return (
    <div>
      <h1>Quiz Time!</h1>
      <Assessment
        questions={exampleSchema}
        onStart={handleStart}
        onComplete={handleComplete}
        onScore={handleScore}
        onMetrics={handleMetrics}
      />
    </div>
  )
}

export default App

Explanation

  1. Define the Schema: Create a Schema object that outlines the sections and questions of your assessment. In the example, there's one section titled "General Knowledge" containing a binary question.

  2. Handle Events:

    • onStart: Logs a message when the assessment begins.
    • onComplete: Receives all user responses upon completion and logs them.
    • onScore: Calculates a simple score based on the user's response.
    • onMetrics: Logs metrics such as total time taken and time per question.
  3. Render the Assessment: Include the Assessment component in your JSX, passing the schema and event handlers as props.

API Reference

Assessment Component

Props

| Name | Type | Description | | ------------ | ----------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | | questions | Schema | Required. The assessment schema defining the sections and questions. | | onStart | () => void | Optional. Callback invoked when the assessment starts. | | onComplete | (responses: Record<string, Response>) => void | Required. Callback invoked upon assessment completion with all user responses. | | onScore | (responses: Record<string, Response>) => number | Optional. Callback to calculate the score based on user responses. | | onMetrics | (metrics: { totalTime: number; timePerQuestion: Record<string, number> }) => void | Optional. Callback to capture assessment metrics such as total time and time per question. |

Schema Type

Defines the structure of the assessment.

interface Schema {
  sections: Section[];
}

interface Section {
  title: string;
  questions: Question[];
}

type Question = BinaryQuestion | /* other question types */;

interface BinaryQuestion {
  id: string;
  type: "binary";
  prompt: string;
  options: { label: string; value: string }[];
}

Response Type

Represents a user's response to a question.

type Response = string // Modify based on question types

License

MIT