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

@blocdigital/usescorm

v0.1.5

Published

React hook for communicating with the SCORM API.

Downloads

18

Readme

usescorm

React hook for communicating with the SCORM API.

I would recommend reading the the SCORM documentation to familiarise yourself with the syntax.

Install

npm install --save @blocdigital/usescorm

Usage

import { useState, useEffect } from 'react';

import useScorm from '@blocdigital/usescorm';

const Example = () => {
  // initiate the scorm session
  const scorm = useScorm({ version: '1.2' });

  const [state, setState] = useState(scorm?.storage || null);

  /**
   * toggle the pass status of a module
   *
   * @param {string} module which module to update
   * @param {number} item index of item
   */
  const handleToggle = (module, item) => {
    scorm.store((state) => {
      const newObj = structuredClone(state);

      newObj[module][item] = newObj[module][item] > 0 ? -1 : 1;

      return newObj;
    });
  };

  // set up listeners to keep state in sync with suspend data
  useEffect(() => {
    const onStateChange = (data) => setState(data);

    scorm.on('storage', onStateChange);

    // remember to tidy up your event listeners
    return () => scorm.off('storage', onStateChange);
  }, [scorm]);

  // initialise the suspend data
  useEffect(() => {
    scorm.store((state) => ({ module1: [0, 0, 0], module2: [0, 0, 0], ...state }));
  }, [scorm]);

  return (
    <>
      <h2>Module 1</h2>
      {state &&
        state.module1.map((pass, index) => (
          <p key={index}>
            Module 1, item {index + 1} is {pass === -1 ? 'failed' : pass === 1 ? 'passed' : 'not started'}
            <button onClick={() => handleToggle('module1', index)}>toggle</button>
          </p>
        ))}
      <h2>Module 2</h2>
      {state &&
        state.module2.map((pass, index) => (
          <p key={index}>
            Module 2, item {index + 1} is {pass === -1 ? 'failed' : pass === 1 ? 'passed' : 'not started'}
            <button onClick={() => handleToggle('module2', index)}>toggle</button>
          </p>
        ))}
    </>
  );
};

Properties

| Name | Type | Default | Description | | ---------------------- | ------- | ------- | ------------------------------------------------------------------------------------- | | version | string | '1.2' | Version of scorm used. | | debug | boolean | false | Whether or not debug mode is enabled. | | handleCompletionStatus | boolean | true | Whether or not the wrapper should automatically handle the initial completion status. | | handleExitMode | boolean | true | Whether or not the wrapper should automatically handle the exit mode. | | autoCommit | boolean | true | Whether or not the each action automatically saves. |

API

| Name | Type | Description | | ----------------------- | -------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | | version | string | Version of scorm used | | handleCompletionStatus | boolean | Whether or not the wrapper should automatically handle the initial completion status. | | handleExitMode | boolean | Whether or not the wrapper should automatically handle the exit mode. | | autoCommit | boolean | Whether or not the each action automatically saves. | | storage | unknown | Live version of data that is in suspend_data. | | API.handle | null | IScorm1_2 | IScorm2004 | Stored version of SCORM API. | | API.isFound | boolean | Whether the SCORM API has been detected or not. | | API.find | (win: Window) => null | IScorm1_2 | IScorm2004 | Find a copy of SCORM. | | API.get | () => null | IScorm1_2 | IScorm2004 | Find a copy of SCORM (using current window). | | API.getHandle | () => null | IScorm1_2 | IScorm2004 | Find a copy of SCORM (using current window + update handle). | | connection.isActive | boolean | Whether the connection to the SCORM API is active. | | data.completionStatus | lesson_status | Current Course completion status. | | data.exitStatus | boolean | Course Exit status. | | debug.isActive | boolean | Whether or not debug mode is enabled. | | debug.getCode | () => number | Returns the error code that resulted from the last API call. | | debug.getInfo | (error: number) => string | undefined | Returns a short string describing the specified error code. | | debug.getDiagnosticInfo | (error: number) => string | undefined | Returns detailed information about the last error that occurred. | | init | () => boolean | Begins a communication session with the LMS. | | terminate | () => boolean | Ends a communication session with the LMS. | | get | (parameter: CMIElement) => string | Retrieves a value from the LMS. | | set | (parameter: CMIElement, value: string) => boolean | Saves a value to the LMS | | store | (value: unknown | ((value: unknown) => unknown)) => boolean | Store data in suspense data | | save | () => boolean | Saves a value to the LMS. | | status | (action: 'get' | 'set', status?: lesson_status) => boolean | lesson_status | Update the lesson status. | | on | (event: 'init' | 'set' | 'storage', callback: (data: unknown) => void) => void | Add event listener for when this component is used. | | onAny | (callback: (data: unknown) => void) => void | Add event listener, for all events, for when this component is used. | | off | (event: 'init' | 'set' | 'storage', callback: (data: unknown) => void) => void | If you exactly match an on event you can remove it. | | offAny | (callback: (data: unknown) => void) => void | If you exactly match an onAny function you can remove it. |