toptions
TypeScript icon, indicating that this package has built-in type declarations

2.0.3 • Public • Published

toptions

Options parsing & nothing else.

Features

  • Parses options
  • Optional configuration
  • TypeScript support
  • No coercion
  • No validation
  • No dependencies

Install

npm install toptions
# or
pnpm add toptions
# or
yarn add toptions
# or
bun add toptions

Example

import options from "toptions"

const parse = options({
  // Positional option
  path: options.arg(0),
  // Named option (type is: string | undefined)
  dist: options.flag("d"),
  // Named option with a default (type is: string)
  port: options.flag("p", 3000),
  // Append multiple values to "exclude"
  exclude: options.list("e"),
  // Boolean --help option
  help: options.bit("h"),
  // Increments the "log" option
  log: options.level("l"),
  // Parses everything after a --
  nodeargs: options.raw(),
  // Parses everything after given positional index
  // Other options will still be parsed
  // Useful for conditionally passing the rest of the options to another command
  args: options.rest(0),
})

const { path, dist, port, exclude, help, log, nodeargs, args } = parse(process.argv.slice(2))

Package Sidebar

Install

npm i toptions

Weekly Downloads

11

Version

2.0.3

License

MIT

Unpacked Size

21.3 kB

Total Files

7

Last publish

Collaborators

  • errilaz