@neotales/args
v0.0.0-alpha.0
Published
Commandline/shell argument utilities for splitting, joining, splatting, and parsing arguments.
Maintainers
Readme
@neotales/args
Overview
Cross-runtime command-line argument utilities for splitting shell-like strings, joining argument arrays, converting objects to args, and parsing args into JSON-like objects.

Documentation
Documentation is available on jsr.io
A list of other modules can be found at github.com/neotales/js-std
Installation
# Deno
deno add jsr:@neotales/args
# npm from jsr
npx jsr add @neotales/args
# from npmjs.org
npm install @neotales/argsUsage
import { join, parse, splat, split } from "@neotales/args";
console.log(split("echo hello world --test")); // ["echo", "hello", "world", "--test"]
console.log(join(["echo", "hello", "world"])); // "echo hello world"
console.log(join(["echo", "hello world"])); // "echo \"hello world\""
const args = splat({
foo: "bar",
splat: {
command: ["git", "clone"],
} as SplatOptions,
});
console.log(args); // ["git", "clone", "--foo", "bar"]
console.log(parse(["--name", "neo", "--count=2", "-v", "input.txt"], { boolean: ["v"] }));
// { _: ["input.txt"], name: "neo", count: 2, v: true }Functions
split- splits a string into an array of arguments/args.join- joins an array of arguments/args into a string.splat- converts an object with args into an array of arguments/args.parse- parses arguments into an object with positional values in_.
Parsing
parse supports long and short options, repeated values, aliases, defaults, boolean flags, and preserving values after
--.
import { parse } from "@neotales/args/parse";
parse(["-n", "neo"], { alias: { name: "n" }, default: { color: "blue" } });
// { _: [], name: "neo", n: "neo", color: "blue" }
parse(["--id", "001", "--", "--not-parsed"], { string: ["id"], "--": true });
// { _: [], id: "001", "--": ["--not-parsed"] }