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

@kogpsy/jspsych-overlay

v1.0.4

Published

A small library that helps you create arbitrary overlays during jsPsych trials or even whole experiments.

Downloads

2

Readme

jspsych-overlay

A small library that helps you create arbitrary overlays during jsPsych trials or even whole experiments.

npm version

How to use

Install the library, e.g. with Yarn:

$ yarn add @kogpsy/jspsych-overlay

Import the createOverlay() function in your experiment project:

import { createOverlay } from '@kogpsy/jspsych-overlay';

Define a function that gets run in each update cycle by the library interally. You can - obviously - do whatever you want in that function, you don't even have to define one if your overlay will be static.

The function is passed two properties, the time elapsed since the overlay is displayed in milliseconds, and a function which allows you to change the content of the overlay.

const updateOverlay = (millisElapsed, setHtml) => {
  const html = `<div class='overlay'>${millisElapsed}</div>`;
  setHtml(html);
};

To create the overlay and have it added to the DOM, call the createOverlay() function. Since this function accesses the DOM, it must be fully loaded when the function is called. To ensure this, you can call it from within a CallFunctionPlugin trial.

createOverlay() takes three arguments: the HTML element which the overlay should be added to (usually the body element), the inner HTML of the overlay and finally the function which gets called on each update cycle (the one we have defined above).

let overlay;

timeline.push({
  type: CallFunctionPlugin,
  func: () => {
    overlay = createOverlay(
      document.body,
      '<div class='overlay'>0</div>',
      updateOverlay
    );
  }
})

Et voilà - the overlay is created and added to the DOM, however, it is not yet visible. You might have noticed that we stored the return value of createOverlay() in a variable called overlay. This variable now contains an object with two fields: a function called startShowingOverlay() and a function called stopShowingOverlay(). With these you get fine-grained control over when the overlay should be displayed.

The overlay we now created simply displayes the elapsed time in milliseconds since we started showing the overlay. You can apply styles in your CSS would do normally.

Development

First, to be able to start development, install required dependencies:

$ yarn install

Then, to build a bundled version of your code, execute (your bundle will be created in the build directory):

$ yarn run build

Testing

Test cases for each file.ts are defined in file.test.ts which is located in the same directory. Testing is done using Jest.

To run tests:

$ yarn run test

Publish changes to npm

First, make sure you have built the project with the most recent changes. Then run yarn publish to upload the package to the NPM registry. It will ask you to bump the version number. Remember semantic versioning.