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

interrogation

v0.1.0

Published

Questioner library

Downloads

3

Readme

Interrogation

A tiny library that allows you to ask a series of questions to the user in the console.

Features

  • Ask question
  • Ask MCQ questions
  • Get response from user
  • Supports coloring

How it works

Install

npm install interrogation

Import the library

const interrogation = require('interrogation')

Ask a question

An array of questions is required for the use of the function getAnswersFor().

const interrogation = require('interrogation')

interrogation.getAnswersFor(['question1? ', 'question2? ']).then((value) => {
    console.log(value);
});

To ask a MCQ (multiple choice question), wrap your question and it's possible choices in an array and pass it to the getAnswersFor() function.

interrogation.getAnswersFor(['question1? ', 'question2? ', ['question3', ['choice1', 'choice2', 'choice3']]]).then((value) => {
  console.log(value);
});

Get response

The response of an interrogation is an array of objects structured like this :

[
  { question: 'Question1 ', response: 'Response1' },
  { question: 'Question2 ', response: 'Response2' },
  { question: 'Question3', response: '2' } // choice 2
]

Version ^0.1.0 : Create a file of questions

You can now create a json file of questions, encode these questions or decode them.

Create a question file

Just create a json file with questions structured like below:

[
  {
    "type": "simple-question",
    "label": "Question 1",
    "format": "string"
  },
  {
    "type": "simple-question",
    "label": "Question 2",
    "format": "string"
  },
  {
    "type": "one-choice-mcq",
    "label": "Question 3",
    "choices": ["Choice 1", "Choice 2", "Choice 3"]
  },
  {
    "type": "simple-question",
    "label": "Question 4",
    "format": "number"
  }
]

Encode a question file

You can encode questions by calling the encodeQuestions() function.

console.log(interrogation.encodeQuestions('json-question.json'));

The output is a base64 string.

Output
WwogIHsKICAgICJ0eXBlIjogInNpbXBsZS1xdWVzdGlvbiIsCiAgICAibGFiZWwiOiAiUXVlc3Rpb24gMSIsCiAgICAiZm9ybWF0IjogInN0cmluZyIKICB9LAogIHsKICAgICJ0eXBlIjogInNpbXBsZS1xdWVzdGlvbiIsCiAgICAibGFiZWwiOiAiUXVlc3Rpb24gMiIsCiAgICAiZm9ybWF0IjogInN0cmluZyIKICB9LAogIHsKICAgICJ0eXBlIjogIm9uZS1jaG9pY2UtbWNxIiwKICAgICJsYWJlbCI6ICJRdWVzdGlvbiAzIiwKICAgICJjaG9pY2VzIjogWyJDaG9pY2UgMSIsICJDaG9pY2UgMiIsICJDaG9pY2UgMyJdCiAgfSwKICB7CiAgICAidHlwZSI6ICJzaW1wbGUtcXVlc3Rpb24iLAogICAgImxhYmVsIjogIlF1ZXN0aW9uIDQiLAogICAgImZvcm1hdCI6ICJudW1iZXIiCiAgfQpd

A new file (question.int) containing the output is also generated. You can then send this file to anyone interrested in answering your questions. This can be very useful for an investigation or a survey.

Decode question file

On the other side, the question.int file can be decoded by calling the decodeQuestions() function.

console.log(interrogation.decodeQuestions('question.int'));
Output
[
  {
    "type": "simple-question",
    "label": "Question 1",
    "format": "string"
  },
  {
    "type": "simple-question",
    "label": "Question 2",
    "format": "string"
  },
  {
    "type": "one-choice-mcq",
    "label": "Question 3",
    "choices": ["Choice 1", "Choice 2", "Choice 3"]
  },
  {
    "type": "simple-question",
    "label": "Question 4",
    "format": "number"
  }
]

You can also get answers for encoded file directly by calling the getAnswersForJson() function.

interrogation.getAnswersForJson('question.int').then((value) => {
  console.log(value);
});
Output
[
  { question: 'Question 1', response: 'Response 1' },
  { question: 'Question 2', response: 'Response 2' },
  { question: 'Question 3', response: '3' }, // Choice 3
  { question: 'Question 4', response: 'Response 4' }
]

Future updates

  • Support of multiple choices.
  • Send encoded files by e-mail.
  • Develop a client to answer question (for non-developers).

Buy me a coffee