https://github.com/errilaz/toptions
Options parsing & that's all.
https://github.com/errilaz/toptions
Last synced: 9 months ago
JSON representation
Options parsing & that's all.
- Host: GitHub
- URL: https://github.com/errilaz/toptions
- Owner: errilaz
- Created: 2022-12-11T16:03:11.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-06-12T15:51:18.000Z (almost 3 years ago)
- Last Synced: 2025-08-27T08:57:38.033Z (9 months ago)
- Language: TypeScript
- Size: 22.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# toptions
> Options parsing & nothing else.
## Features
- Parses options
- Optional configuration
- TypeScript support
- No coercion
- No validation
- No dependencies
## Install
```sh
npm install toptions
# or
pnpm add toptions
# or
yarn add toptions
# or
bun add toptions
```
## Example
```ts
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))
```