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

wizardy

v0.4.1

Published

Conversational wizard and prompts generator with zero dependencies.

Downloads

31

Readme

Wizardy 🧙📜

Wizardy is a conversational wizard which helps you to easily build prompts and questionnaires. It has been designed to be used with messenger applications to generate bot interactions but it is generic and can be used in many ways.

❯ Features

  • Easy-to-use. Wizardy's API is dead simple, easy to use and easy to replace (if you ever want to).
  • Typed. Wizardy is written 100% in TypeScript, so there is no need to install typings from an external source.
  • Tested. Do not be surprised when using Wizardy, it ships with 100% code coverage.
  • Documented. Modern documentation lives in code. That's why Wizardy's interface contains TSDoc comments.
  • Compatible. Node.js, Browsers? Run Wizardy on the platform of your choice!
  • Independent. Don't be afraid of big lock files. Wizardy uses zero dependencies.

❯ Installation

npm install wizardy
yarn add wizardy

❯ Usage

TypeScript

import {Prompt, Wizardy} from 'wizardy';

const questionnaire: Prompt<string | number>[] = [
  {
    answerKey: 'item',
    answerValue: input => input.trim(),
    question: `What would you like to order?`,
    response: () => `Lucky you! We have '${wizard.answers.item}' in stock.`,
  },
  {
    answerKey: 'quantity',
    answerValue: input => parseInt(input, 10),
    question: () => `How many '${wizard.answers.item}' do you want to buy?`,
    response: () =>
      `Great, we will prepare your order and deliver ${wizard.answers.quantity}x ${wizard.answers.item} as soon as possible.`,
  },
];

const wizard = new Wizardy();
wizard.addQuestions(questionnaire);
console.log(wizard.step); // 0

console.log(wizard.ask()); // "What would you like to order?"
console.log(wizard.answer('iPhones')); // "Lucky you! We have 'iPhones' in stock."
console.log(wizard.step); // 1

console.log(wizard.ask()); // "How many 'iPhones' do you want to buy?"
console.log(wizard.answer('13')); // "Great, we will prepare your order and deliver 13 iPhones as soon as possible."
console.log(wizard.step); // 2

Node.js

const {Prompt, Wizardy} = require('wizardy');

const wizard = new Wizardy();

wizard.on(Wizardy.TOPIC.START, () => console.log('Wizard started...'));
wizard.on(Wizardy.TOPIC.END, answers => {
  console.log('Wizard ended', answers); // Wizard ended { category: 'pizza', quantity: 7 }
});

const questionnaire = [
  {
    answerKey: 'category',
    answerValue: answer => {
      const menu = ['burger', 'pizza', 'veggie burger'];
      answer = answer.toLowerCase();
      if (menu.includes(answer)) {
        return answer;
      } else {
        throw Error(
          `Sorry, we only offer: ${menu
            .map(category => category.charAt(0).toUpperCase() + category.substr(1))
            .join(', ')}.`
        );
      }
    },
    question: 'What kind of food do you want to order?',
    response: 'Good choice!',
  },
  {
    answerKey: 'quantity',
    answerValue: answer => {
      try {
        return parseInt(answer.match(/(\d+)/)[0], 10);
      } catch (error) {
        throw Error('Please write down the amount as number.');
      }
    },
    question: `How much do you want?`,
    response: 'Thanks. We will prepare your order.',
  },
];

wizard.addQuestions(questionnaire);

console.log(wizard.ask()); // What kind of food do you want to order?
console.log(wizard.answer('Fajitas')); // Sorry, we only offer: Burger, Pizza, Veggie burger.

console.log(wizard.ask()); // What kind of food do you want to order?
console.log(wizard.answer('Pizza')); // Good choice!

console.log(wizard.ask()); // How much do you want?
console.log(wizard.answer('Seven')); // Please write down the amount as number.

console.log(wizard.ask()); // How much do you want?
console.log(wizard.answer('I would like to have 7.')); // Thanks. We will prepare your order.