https://github.com/jeffy-g/tiny-args
https://github.com/jeffy-g/tiny-args
Last synced: 5 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/jeffy-g/tiny-args
- Owner: jeffy-g
- License: mit
- Created: 2022-05-16T18:08:20.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2025-05-18T17:56:45.000Z (about 2 months ago)
- Last Synced: 2025-05-18T18:46:20.146Z (about 2 months ago)
- Language: JavaScript
- Size: 28.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

[](https://badge.fury.io/js/tin-args)



# tin-args
A **simple command-line argument parser** for Node.js with no external dependencies.
It automatically parses booleans, numbers, arrays, RegExps, and string values from `-key value` style inputs.> **Note:** Only single-dash (`-option`) arguments are supported.
> If you're expecting `--long-option` support, consider alternatives like `minimist`, `yargs`.---
## ✨ Features
- Single-dash CLI options like `-minify true`, `-factor 123.5`, `-regex "re/\\d+/g"` supported
- Auto-detects:
- Numbers: `-num 123`
- Booleans: `-flag`
- Arrays: `-list "v1,v2,v3"`
- Regex: `-re "re/\\.(j|t)s$/g"`
- Ignores positional args and collects them into `args: string[]`---
## 📦 Install
```bash
npm i tin-args
# or
yarn add tin-args
````---
## 🚀 Usage
```js
const getExtraArgs = require("tin-args");/**
* @typedef TArgs
* @prop {RegExp} test A regex value
* @prop {number} factor A numeric value
* @prop {boolean} minify A boolean flag
* @prop {string[]} values Array of strings
* @prop {string[]} values2 Array of strings
* @prop {any[]} a Array of mixed values
*//**
* will be:
* ```ts
* const params: TArgs & { args?: string[]; }
* ```
* @type {ReturnType>}
*/
const params = getExtraArgs({ prefix: "-" });console.log(params);
```### CLI Example:
+ run `arg-test.js` with node
```shell
$ yarn test .git/* # OR npm run test -- .git/*
```Output:
```shell
{
test: /(?<=reference path=")(\.)(?=\/index.d.ts")/,
factor: 123.5,
minify: true,
values: [ 'v0', 'v1', 'v2' ],
values2: [ 'v0', 'v1', 'v2' ],
a: [ 'value0', 100, true, /\r?\n/g ],
args: [
'.git/config',
'.git/description',
'.git/HEAD',
'.git/hooks',
'.git/index',
'.git/info',
'.git/logs',
'.git/objects',
'.git/packed-refs',
'.git/refs',
'.git/tortoisegit.data',
'.git/tortoisegit.index'
]
}
```---
## 🧠 Notes on RegExp values
If you want the parser to recognize a RegExp, use the `re` prefix:
```bash
node arg-test.js -re "re/\\.(j|t)s$/g"
```---
## 📄 License
MIT © 2022 [jeffy-g](mailto:[email protected])