Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
inquirer-date-prompt
Advanced tools
A comprehensive date prompt plugin for Inquirer.js.
Date
and Intl.DateTimeFormat
APInpm 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 onv2.x
until you're ready to upgrade your environment:npm install --save inquirer-date-prompt@^2.0.0
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.
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:
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)transformer
function supports the following Boolean flags:
isFinal
: Indicates whether a final answer has been selectedisDirty
: Indicates whether the input has been modified by the userisCleared
: Indicates whether the input has been cleared (if the clearable
option has been enabled)locale
1 (String | Array<String>)
format
(Intl.DateTimeFormatOptions)DateTimeFormatOptions
object for customizing the date format. By default, all editable parts default to 'numeric'
.clearable
(Boolean)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.
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;
}
'en-US'
while running on any version less than 13.0.0 will fail silently. See the MDN docs for more details.FAQs
A date prompt plugin for Inquirer.js.
We found that inquirer-date-prompt demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.