No description
  • TypeScript 100%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2023-06-12 17:50:55 +02:00
src 2.0.2. fix overlapping arg/rest bug 2023-03-25 19:48:47 +01:00
test 2.0.2. fix overlapping arg/rest bug 2023-03-25 19:48:47 +01:00
.gitignore topt 2022-12-11 02:25:08 +01:00
.npmignore add npmignore 2022-12-11 17:54:49 +01:00
package.json update to ESM 2023-06-12 17:50:55 +02:00
pnpm-lock.yaml tests 2023-03-25 18:49:01 +01:00
README.md npm badge 2023-03-26 01:25:42 +01:00
tsconfig.json update to ESM 2023-06-12 17:50:55 +02:00
vitest.config.ts tests 2023-03-25 18:49:01 +01:00

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))