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

inquirer-date-prompt

v3.0.0

Published

A date prompt plugin for Inquirer.js.

Downloads

19,794

Readme

inquirer-date-prompt

A comprehensive date prompt plugin for Inquirer.js.

Why?

  • No additional dependencies
  • Leverages native Date and Intl.DateTimeFormat API
  • Augmented TypeScript declarations
  • Locale-agnostic 1
  • The other plugins weren't cutting it

Installation

npm install inquirer-date-prompt

:warning: Note that the latest version of this package uses native ESM modules, which means this plugin will only work with inquirer v9 and above. If you cannot use ESM modules yet for whatever reason, you can rely on v2.x until you're ready to upgrade your environment:

npm install --save inquirer-date-prompt@^2.0.0

Usage

import inquirer from "inquirer";
import DatePrompt from "inquirer-date-prompt";

inquirer.registerPrompt("date", DatePrompt);

inquirer.prompt({
  type: "date",
  // ...
});

Although you can use whatever type name you want, registering the prompt with a type of 'date' will afford you IntelliSense when specifying the prompt options, thanks to TypeScript's declaration merging.

Prompt

To change the date, simply use the left and right arrow keys to move the cursor, and up and down to change the value. You can also use modifier keys to determine by how much to increase or decrease the value:

  • ±10: Shift + Arrow (⇧↓)
  • ±100: Option/Alt + Shift + Arrow (⌥⇧↓)

Options

Note: allowed options written inside square brackets ([]) are optional. Others are required.

type, name, message [, default, filter, validate, transformer, locale, format, clearable]

default (Date)

  • default is expected to be a Date instance if used. If no default value is provided, the prompt will default to the current date and time.

transformer (Function)

  • In addition to the default arguments, the transformer function supports the following Boolean flags:
    • isFinal: Indicates whether a final answer has been selected
    • isDirty: Indicates whether the input has been modified by the user
    • isCleared: Indicates whether the input has been cleared (if the clearable option has been enabled)

locale 1 (String | Array<String>)

  • A specific locale or locales to use when formatting the date. If no locale is provided, it will default to the user's current locale.

format (Intl.DateTimeFormatOptions)

  • A DateTimeFormatOptions object for customizing the date format. By default, all editable parts default to 'numeric'.

clearable (Boolean)

  • A Boolean value indicating whether the input can be cleared. If true, hitting delete or backspace will clear the prompt and set its current value to null. Pressing any other key before returning will restore the state to its previous value.

See the inquirer README for details on all other options.

Example

async function getTimestamp(date) {
  const { timestamp } = await inquirer.prompt({
    type: "date",
    name: "timestamp",
    message: "When will the world end?",
    prefix: " 🌎 ",
    default: date,
    filter: (d) => Math.floor(d.getTime() / 1000),
    validate: (t) => t * 1000 > Date.now() + 86400000 || "God I hope not!",
    transformer: (s) => chalk.bold.red(s),
    locale: "en-US",
    format: { month: "short", hour: undefined, minute: undefined },
    clearable: true,
  });
  return timestamp;
}

Caveats

  1. Be aware that even though this plugin works with Node ≥ v12, specifying a locale other than 'en-US' while running on any version less than 13.0.0 will fail silently. See the MDN docs for more details.