Loading from a CDN
The parser runs in the browser, so you can load it straight from a CDN. This is mostly useful for demos and playgrounds, where you parse a string typed into a page instead of process.argv.
Global build
<!-- jsdelivr --><script src="https://cdn.jsdelivr.net/npm/@staticbolt/args-parser"></script>
<!-- unpkg --><script src="https://unpkg.com/@staticbolt/args-parser"></script>
<script> const { defineCLI, coerce } = ArgsParser;</script>ESM
<script type="module"> import { coerce, defineCLI } from "https://cdn.jsdelivr.net/npm/@staticbolt/args-parser/+esm";</script>The validation library too
A schema library is still required. Load it the same way:
<script type="module"> import { coerce, defineCLI } from "https://cdn.jsdelivr.net/npm/@staticbolt/args-parser/+esm"; import * as z from "https://cdn.jsdelivr.net/npm/zod/+esm";
const cli = defineCLI({ cliName: "hello", options: { name: { schema: z.string().default("world") }, }, });
cli.onExecute(({ options }) => console.log(`Hello, ${options.name}!`));
cli.run("--name Sam");</script>run accepts a plain string. That is what you want when the input comes from a text field rather than a shell.
For output in a page rather than a console, generate the help message as HTML. See Help messages.