Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yuanqing/clinical
:pill: A minimum-viable arguments parser in ~90 LOC with zero dependencies
https://github.com/yuanqing/clinical
Last synced: 10 days ago
JSON representation
:pill: A minimum-viable arguments parser in ~90 LOC with zero dependencies
- Host: GitHub
- URL: https://github.com/yuanqing/clinical
- Owner: yuanqing
- License: mit
- Created: 2020-11-15T04:22:57.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-01-30T07:39:41.000Z (almost 4 years ago)
- Last Synced: 2024-10-08T17:28:04.753Z (about 1 month ago)
- Language: TypeScript
- Homepage:
- Size: 79.1 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/funding.yml
- License: LICENSE.md
Awesome Lists containing this project
README
# clinical [![npm Version](https://img.shields.io/npm/v/clinical?cacheSeconds=1800)](https://www.npmjs.org/package/clinical) [![build](https://github.com/yuanqing/clinical/workflows/build/badge.svg)](https://github.com/yuanqing/clinical/actions?query=workflow%3Abuild)
> A minimum-viable arguments parser in [~90 LOC](src/index.ts) with zero dependencies
## Features
- Casts values to the appropriate JavaScript primitive type
- Converts option keys to camelCase
- Throws on duplicated options
- Stops parsing options after `--`
- Prints the supplied version on `--version` or `-v`
- Prints the supplied help message on `--help` or `-h`## Example
```sh
$ npm install --save clinical
``````js
#!/usr/bin/env nodeimport clinical from 'clinical'
try {
const result = clinical('1.0.0', 'my help message')
console.log(result)
} catch (error) {
console.error(error.message)
process.exit(1)
}
``````sh
$ my-cli --foo --bar 42 -x=y -- baz null
{
options: { foo: true, bar: 42, x: 'y' },
positionals: [ 'baz', null ]
}
``````sh
$ my-cli --version
1.0.0
``````sh
$ my-cli --help
my help message
```## API
```ts
import clinical from 'clinical'
```### const result = clinical(version, helpMessage [, args = process.argv.slice(2)])
- **`version`** (*`string`*) – *Required.* Writes this string to `stdout` on encountering the `--version` or `-v` flag, then exits the `process`.
- **`helpMessage`** (*`string`*) – *Required.* Writes this string to `stdout` on encountering the `--help` or `-h` flag, then exits the `process`.
- **`args`** (*`Array`*) – *Optional.* The arguments to be parsed. Defaults to `process.argv.slice(2)`.The returned `result` object has the following keys:
- **`positionals`** (*`Array`*)
- **`options`** (*`{ [key: string]: boolean | null | number | string }`*)## Installation
```sh
$ npm install --save clinical
```## License
[MIT](/LICENSE.md)