A tiny utility for parsing & validating Node CLI args and object literals
npm install @eegli/tinyparse!npm !GitHub Workflow Status (branch)  !npm bundle size (scoped)
> A tiny, type-safe and flexible utility for creating command line tools in Node.js
_Like oclif and Yargs had a baby._
``ts
import { Parser } from '@eegli/tinyparse';
new Parser()
.option('occasion', {
longFlag: '--occasion',
shortFlag: '-o',
defaultValue: '',
required: true,
})
.subcommand('congratulate', {
args: ['name'] as const,
handler: ({ args, options }) => {
const [name] = args;
const { occasion } = options;
console.log(Happy ${occasion}, ${name}!);
},
})
.defaultHandler(() => {
console.log('Please enter your name');
})
.parse(['congratulate', 'John', '--occasion', 'birthday'])
.call();
// Happy birthday, John!
``
I use this mostly for other pet projects of mine so it comes with some opinions 🤪.
- TypeScript first - 100% type-safety
- Supports subcommands and flag options
- Async API
- Lightweight - Zero dependencies
- Mega customizable
- Check out the extensive test suites or
- Play in the dedicated Code Sandbox
This project has been guided by the amazing Command Line Interface Guidelines by Aanand Prasad, Ben Firshman, Carl Tashian and Eva Parish.
Further inspiration has been taken from the Apache Commons CLI.