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

zompt

v1.1.4

Published

![Zompt](https://i.imgur.com/EEs7eok.png)

Downloads

8

Readme

Zompt

Zompt

The TypeScript-first prompting library for Node.js CLIs.

Why Zompt?

To date, traditional JavaScript prompting libraries such as prompt and inquirer have yet to support TypeScript typing for a user's input, or as Zompt calls it, answer. Though this isn't possible with traditional TypeScript, the zod library has become increasingly popular in recent years for runtime validation of TypeScript types. As a result, we're leveraging this library to bring this functionality to you.

Features

  • Text input
    • Runtime zod validation
    • Semantic error responses by preferring zod parsing errors
  • Select input
    • Static typing for choices
    • Ability to set a default
  • Multiselect input
    • Static typing for choices
    • Ability to set defaults

How to use it

First, install zompt from npm.

npm i zompt

Then, import zompt.

import { Zompt } from 'zompt';

Next, instantiate a new instance. There are a variety of configuration options available to truly make this library your own. By default, we leverage chalk for formatting.

// Using the default configuration
const zompt = new Zompt();

// If you wish to make the library your own!
const zompt = new Zompt({
  streams: {
    input: process.stdin,
    output: process.stdout,
  },
  colors: {
    primary: chalk.white,
    secondary: {
      question: chalk.cyan,
      info: chalk.cyan,
      item: chalk.cyan,
      'active-item': chalk.cyan,
      'selected-item': chalk.green,
      error: chalk.red,
      warning: chalk.yellow,
      success: chalk.green,
    },
    tertiary: chalk.gray,
  },
  prefixes: {
    question: '?',
    info: 'ℹ',
    item: '○',
    'active-item': '●',
    'selected-item': '◉',
    error: '✖',
    warning: '⚠',
    success: '✔',
  },
  messages: {
    errors: {
      invalid: 'There was an issue with your answer.',
      unknown: 'An unknown error occurred.',
    },
  },
});

Now, start asking your user's questions and have peace of mind with types!

  const name = await zompt.input(
    'What is your name?',
    z
      .string()
      .min(3, {
        message: 'Your name must be at least 3 characters long.',
      })
      .regex(/^[a-zA-Z]+$/, {
        message: 'Your name must only contain letters.',
      }),
  );

  const color = await zompt.input(
    'What is your favorite color?',
    z.enum(['red', 'orange', 'yellow', 'green', 'blue', 'purple'], {
      errorMap: () => ({ message: 'Please choose a color from the rainbow!' }),
    }),
  );

  const cloudPlatform = await zompt.select<'aws' | 'gcp' | 'azure'>(
    'What is your favorite cloud platform?',
    [
      {
        label: 'Amazon Web Services',
        value: 'aws',
      },
      {
        label: 'Google Cloud Platform',
        value: 'gcp',
      },
      {
        label: 'Microsoft Azure',
        value: 'azure',
      },
    ],
  );

  const languages = await zompt.multiselect<'js' | 'py' | 'java' | 'c'>(
    'What programming languages do you know?',
    [
      {
        label: 'JavaScript',
        value: 'js',
      },
      {
        label: 'Python',
        value: 'py',
        default: true,
      },
      {
        label: 'Java',
        value: 'java',
      },
      {
        label: 'C',
        value: 'c',
      },
    ],
  );

  // Finally, make your success messages look identical to your prompts!
  zompt.log(
    `Hello, ${name}!
    I see you like the color ${color}.
    You also like the cloud platform ${cloudPlatform}.
    Finally, ${
      languages.get('js') ? 'you know' : "you don't know"
    } JavaScript!`,
    'success', // 'info' | 'error' | 'warning' | 'success'
  );

Is this here to stay?

Absolutely. At John Deere (my day job), I work on numerous developer experience CLIs and always felt TypeScript was treated as an afterthought. That being said, zompt was born as a side project with the intention of bringing it to the Fortune 100 space. Though the company itself does not maintain this piece of software, I will be regularly updating and improving it.

Contributing

At the moment, I'd love for someone to start writing unit tests! I plan to do this in the future myself, but it isn't a high priority for me at the moment! If you're at all interested, please reach out to me!