Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stefanoruth/valon-args
A Typescript arguement parser with strong types
https://github.com/stefanoruth/valon-args
args argument-parser cli typescript
Last synced: 3 months ago
JSON representation
A Typescript arguement parser with strong types
- Host: GitHub
- URL: https://github.com/stefanoruth/valon-args
- Owner: stefanoruth
- License: mit
- Created: 2020-11-20T11:44:52.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-04-04T06:47:36.000Z (7 months ago)
- Last Synced: 2024-07-13T01:35:47.032Z (4 months ago)
- Topics: args, argument-parser, cli, typescript
- Language: TypeScript
- Homepage:
- Size: 346 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Valon Args
Typescript node argument parser with strong types.
![npm](https://img.shields.io/npm/v/valon-args) ![npm](https://img.shields.io/npm/dt/valon-args)
![Build & Tests](https://github.com/stefanoruth/valon-args/workflows/Build%20&%20Tests/badge.svg?branch=master)## Installation
```sh
# npm
npm install valon-args# Yarn
yarn add valon-args# Pnpm
pnpm add valon-args
```## Example
```ts
import { cliArgs } from 'valon-args'const options = cliArgs({
name: { type: 'string', required: true },
retries: { type: 'number' },
force: { type: 'boolean' },
})// All args are now typed and validated.
options.name // string
options.retires // number | undefined
options.force // boolean | undefined
```## Documentation
```ts
import { cliArgs } from 'valon-args'// Console args are automaticly parsed fron the terminal.
const args = cliArgs({ name: { type: 'string' } })
```### Usage
#### String
```ts
node ./example.js --string=foo // 'foo'
node ./example.js --string="foo bar" // 'foo bar'
```#### String[]
```ts
node ./example.js --string=foo --string=bar // ['foo', 'bar']
node ./example.js --string="foo bar" --string="bar baz" // ['foo bar', 'bar baz']
node ./example.js --string "foo bar" foobar "bar baz" // ['foo bar', 'foobar', 'bar baz']
```#### Number
```ts
node ./example.js --number=1 // 1
```#### Number[]
```ts
node ./example.js --number=1 --number=2 // [1, 2]
```#### Boolean
```ts
node ./example.js --force // true
node ./example.js --force=true // true
node ./example.js --force=false // false
node ./example.js --force=1 // true
node ./example.js --force=0 // false
node ./example.js // undefined
```