New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

inquirer-date-prompt

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

inquirer-date-prompt

A date prompt plugin for Inquirer.js.

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.8K
decreased by-7.12%
Maintainers
1
Weekly downloads
 
Created
Source
Inquirer Logo

inquirer-date-prompt

A comprehensive date prompt plugin for Inquirer.js.

Why?

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 (⌥⇧↓)

Demo

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.

Demo

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;
}

Demo

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.

Keywords

FAQs

Package last updated on 12 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc