Socket
Book a DemoInstallSign in
Socket

cli-vir

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cli-vir

Parse CLI args with type safety.

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
663
-59.77%
Maintainers
1
Weekly downloads
 
Created
Source

cli-vir

Type safe CLI argument parser.

  • Allows single (-f, -force) or double (--f, --force) dashes for both short and long flag arguments.
  • Accepts camelCase, kebab-case, or snake_case flag name variants with case insensitivity.
  • Allows restricting arg values to a set of known values.
  • Can convert truthy and falsy strings to booleans ('t', 'true', 1, 'f', 'false', 0).
  • Provides type safe values.
  • Prints man page styled documentation when parsing fails.
  • Automatically excludes the bin name or script path from raw arguments.
  • and many more features...

Reference docs: https://electrovir.github.io/cli-vir

Install

npm i cli-vir

Usage

Use parseArgs:

import {FlagRequirement, parseArgs} from 'cli-vir';

const myArgs = parseArgs(
    process.argv,
    {
        arg1: {
            flag: {
                valueRequirement: FlagRequirement.Blocked,
            },
        },
        arg2: {
            required: true,
            position: 0,
        },
        arg3: {
            flag: {
                aliases: ['-3'],
                allowMultiple: true,
                valueRequirement: FlagRequirement.Required,
            },
        },
    },
    {
        /** The binName for your package, if relevant. */
        binName: 'cli-vir',
        /**
         * Make sure this `import.meta` is accessed in your top level JavaScript/TypeScript file
         * that is being executed.
         */
        importMeta: import.meta,
    },
);

console.info(myArgs.arg1); // boolean
console.info(myArgs.arg2); // string
console.info(myArgs.arg3); // string[]

Keywords

cli

FAQs

Package last updated on 18 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts