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 🙏

© 2026 – Pkg Stats / Ryan Hefner

qna

v1.0.1

Published

Chat like questions and answers

Readme

qna.js Build Status Coverage Status

Chat like questions and answers

Usage

Editable Example

<body>
  <p class="question">
      <span class="snippet"></span>
      <span class="snippet"></span>
  </p>

	<form id="question-form" name="question">
			<input name="name" type="text" placeholder="Your Name">
	</form>

  <p class="answer">
      <span class="answer-snippet"></span>
      <span class="answer-snippet"></span>
  </p>

	<script src="dist/qna.min.js"></script>
	<script>

	document.addEventListener('DOMContentLoaded', function() {

		var questionText = [
	    {str: 'Hello, '},
      {str: 'What\'s your name?', pauseDelay: 50}
    ];

    var defaultAnswerText = [
    	{str: 'It\'s, great to meet you'}
    ];

	  var answerOpts   = { responder: answerResponder };
	  var questionOpts = { form: '#question-form' };

	  var answer   = new qna('.answer .snippet', defaultAnswerText, answerOpts);
		var question = new qna('.question .snippet', questionText, questionOpts);

		question.bindAnswer(answer) ;
		question.respond( );

		function answerResponder ( event, form ) {
			event.preventDefault();

			var input = form.querySelector('input');
			var name = input.value.trim();

			input.blur();

			return [
				{str: 'Hello, '+name},
				{str: 'It\'s, great to meet you'}
			];
		}
	});

	</script>
</body>

Api

In the browser, qna is a global variable. In Node, do:

var qna = require('qna');

var q = new qna(nodeSelection, snippets [, opts]);

This will initialize a qna instance on the documents nodeSelection and corresponding snippets with the given options.

  • nodeSelection — A DOM Node List or a query selector string (passed into document.querySelectorAll()).
  • snippets — An ordered Array of snippetObjects.
    • snippetObject — An Object literal with the following properties
      • str — A String (required)
      • pauseDelay — A Number representing the delay before typing in milliseconds (optional, default 750)
      • typeSpeed — A Number representing the typing speed in milliseconds (optional, default 50)
  • opts

Key | Description | Value :--|:--|:-- responder | A function for generating responses to form submissions | A function that returns a snippetObject Array form | The form element to listen for a submit event. | A DOM Element or a selector String answer | The answer to the question | An instance on qna

q.respond([callback, args])

Type the snippets to the corresponding nodeSelection list defined at initialization with an optional callback that will be called after all the snippets have been typed to the screen.

If a responder was specified at initialization the additional arguments will be passed through to the responder function. If the responder returns a snippetObject it will use those snippetObjects to type to the corresponding nodeSelection

q.bindAnswer(a, [callback])

a is a instance of qna.

callback is a function that will be called after the questions form has been submitted.

Assign an answer and optional callback to a question.

The answers a.respond method will be triggered when the questions form is submitted with that events parameters (formEvent, formEl).

Installation

Install via npm:

$ npm i --save qna

Install via bower:

$ bower i --save alex-ray/qna

License

MIT