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

exerslide-plugin-javascriptexercise-layout

v1.1.0

Published

A JavaScript exercise layout for exerslide.

Downloads

8

Readme

JavaScriptExercise layout

This layout is intended for interactive JavaScript exercises. It shows a text editor to let the visitor input JavaScript and allows to specify validation logic to verify the solution.

+-----------------------+
|                       |
|   Description         |
|   +---------------+   |
|   |               |   |
|   |Editor         |   |
|   |               |   |
|   +---------------+   |
|   +------+ +-----+    |
|   |Submit| |Reset|    |
|   +------+ +-----+    |
+-----------------------+

Code that is inputted in the text editor can be executed and verified. The layout makes a special function available to the code in the editor: log.
log is a wrapper around console.log which also records the values that have been passed to it. These values can later be used to validate solutions.

Layout data

  • description: Free form text that will be shown above the text editor. Can be used to introduce the question / problem.

  • assertion: JavaScript code to validate the solution. The code has access to three variables:

    • assert, which is the assertion function. It takes a condition as first argument and a message as second argument.
    • source: The text editor input.
    • output: An array of values which have been passed to the log function.

With this you can perform simple checks against the input source and logged output.

Note: If assertion is not present, no "Submit" button is rendered. In that case the layout can used as interactive demo.

Layout content

The content of the slide is expected to be JavaScript and is used as the initial input of the text editor.

Example:

---
title: Exercise
layout_data:
  description: |
    Create a local variable with name `foo` and value `42`.
    Use `log(foo)` to log the value of `foo`.
  assertion: |
    assert(
      /var foo\s*=.+;?$/m.test(source),
      "It doesn't look like you have declared a variable (hint: var)."
    );
    assert(output[0] === 42, "Don't forget to log the value");
---
// Create variable

//
log(foo);