parsemate
TypeScript icon, indicating that this package has built-in type declarations

0.0.10 • Public • Published

🧩 ParseMate

A flexible, zero-dependency TypeScript class for parsing command-line arguments with support for multi-value flags, default values, required arguments, and rich help output.


🚀 Features

  • Define your own argument structure using ArgSpec
  • Support for required flags and multiple values
  • Auto-generated terminal help with examples
  • Simple access to argument values

📦 Installation

This is a self-contained utility. Just include ArgvParser.ts and ArgSpec.ts in your project.

Or install from npm:

npm install parsemate

📄 Usage

import { ArgvParser } from "parsemate";
  ( () => {
  const parser = new ArgvParser({
    folder: {
      flags: ['-f', '--folder'],
      description: 'Folder to scan',
      required: true,
      multiple: true,
    },
    tech: {
      flags: ['-t', '--tech'],
      description: 'Technologies to process',
      multiple: true,
      default: ['html', 'css'],
    },
    output: {
      flags: ['-o', '--output'],
      description: 'Output folder',
      default: 'dist',
    },
  });
for (const [key, value] of parser.entries) {
  console.log(`${key}:`, value);
}

})();


🔧 ArgSpec Type

export type ArgSpec = {
  flags: string[];          // e.g., ['-f', '--folder']
  description: string;
  required?: boolean;
  multiple?: boolean;
  default?: any;
};

🔍 Example Help Output


🧪 API Reference

  • constructor(appName: String, defs: ArgDefinition) – Initialize with a map of argument specs.
  • getArg(name: string) – Get the parsed value for a specific argument.
  • getAll() – Get all parsed arguments as an object.
  • keys – Array of all argument names.
  • values – Array of all parsed values.
  • entries – Array of [key, value] pairs.
  • definitionList – Array of defined arguments and specs.
  • generateHelp(appName?: string) – Returns CLI help string.

📃 License

MIT – Use freely in personal or commercial projects.

/parsemate/

    Package Sidebar

    Install

    npm i parsemate

    Weekly Downloads

    222

    Version

    0.0.10

    License

    MIT

    Unpacked Size

    11.6 kB

    Total Files

    9

    Last publish

    Collaborators

    • pskywalker96