JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 725
  • Score
    100M100P100Q99886F
  • License (MIT or CC0 1.0)

Parse CLI args with type safety.

Package Exports

  • cli-vir
  • cli-vir/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cli-vir) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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[]