args-tokenizer is a lightweight JavaScript library for parsing shell commands with arguments into an argv array. This makes it easy to work with command-line tools and libraries that expect an array format for arguments, such as tinyexec.
Features
Simple and intuitive API.
Handles quoted strings and escapes correctly.
Supports multiline input.
Ideal for parsing human-readable shell commands, especially curl-style commands.
Parses a shell command string into an array of arguments. Properly handles:
Quoted strings (e.g., '"./path/to/file"').
Escaped characters (e.g., \").
Multiline commands (e.g., lines ending with \\).
Options
loose: If true, the tokenizer will not throw an error when closing quotes are missing. Default is false.
Examples
// Without loose option (default behavior)// This will throw an error due to the missing closing quotetokenizeArgs('command "arg1 arg2');// With loose option enabledconst args = tokenizeArgs('command "arg1 arg2', { loose: true });// ['command', 'arg1 arg2']