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

demoscript

v1.0.4

Published

The simplest way to demo your TS code

Downloads

2

Readme

DemoScript

This package allows you to create interactive demos for your projects. It automatically finds all demos and provides a menu to run them. You can ask user for input, show messages, and more.

Installation

Inside your project directory, run:

npm install demoscript -D

Usage

  • Make demos by creating files ending with .demo.ts.
  • Inside package.json scripts, add a script to run demoscript. Optional path to demo folder can be provided. By default, it looks for all .demo.ts files in the entire project directory (including node_modules).
{
  "scripts": {
    "demo": "demoscript"
    // or
    "demo": "demoscript --path src/demos"
  }
}
  • Now run the script using npm run demo (or whatever name you gave to the script). It will collect all demos and create a menu to run them.

Example

Create a file ending with .demo.ts in your project directory. For example, example.demo.ts:

import { group, demo, ask, say } from 'demoscript';

export default group('My Example Demos', 

  demo('Ask user to write', () => {
    const name = ask('What is your name?').read(String);
    const age = ask('What is your age?').read(parseInt);
    const yob = new Date().getFullYear() - age;
    say(`Hello, ${name}! You were born between ${yob - 1} and ${yob}.`);
  }),

  demo('Ask user to choose', () => {
    const numChoice = ask('Choose a number:').options(
      { label: 'One', value: 1 },
      { label: 'Two', value: 2 },
      { label: 'Three', value: 3 }
    );
    say(`You chose ${numChoice}.`);
  }),

  demo('Ask user to confirm', () => {
    const confirmed = ask('Are you sure?').confirm();
    say(confirmed ? 'You are sure!' : 'You are not sure!');
  })

);

NOTE: DemoScript looks only for default exports in .demo.ts files. You can export either a single demo or a group of demos. If you want to use named exports, be sure to import them in another .demo.ts file and export default group of those demos.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.