The mighty option parser used by yargs for parsing command-line arguments with extensive configuration options.
Low-level utility function for tokenizing argument strings into arrays of individual arguments. This function handles quoted strings, escape sequences, and proper parsing of shell-like argument syntax.
Node.js (ESM):
import { tokenizeArgString } from "yargs-parser/build/lib/tokenize-arg-string.js";Node.js (CommonJS):
// Not directly available in CommonJS - tokenizeArgString is internal
// Use the main parser for argument processing insteadBrowser/Deno:
// tokenizeArgString is not exposed in browser or Deno builds
// This is an internal utility primarily for Node.js environments/**
* Take an un-split argv string and tokenize it into an array of arguments
* @param argString - String or array to tokenize
* @returns Array of tokenized argument strings
*/
function tokenizeArgString(argString: string | any[]): string[];import { tokenizeArgString } from "yargs-parser/build/lib/tokenize-arg-string.js";
// Simple argument string
const args1 = tokenizeArgString("--foo bar --baz");
console.log(args1);
// Output: ["--foo", "bar", "--baz"]
// With quoted arguments
const args2 = tokenizeArgString('--name "John Doe" --age 30');
console.log(args2);
// Output: ["--name", "John Doe", "--age", "30"]// Single quotes
const args1 = tokenizeArgString("--title 'My Great App' --debug");
console.log(args1);
// Output: ["--title", "My Great App", "--debug"]
// Double quotes with spaces
const args2 = tokenizeArgString('--message "Hello world from app"');
console.log(args2);
// Output: ["--message", "Hello world from app"]
// Mixed quotes
const args3 = tokenizeArgString(`--config '{"theme": "dark"}' --verbose`);
console.log(args3);
// Output: ["--config", '{"theme": "dark"}', "--verbose"]// If array is provided, converts all elements to strings
const args1 = tokenizeArgString(["--port", 3000, "--debug", true]);
console.log(args1);
// Output: ["--port", "3000", "--debug", "true"]
// String array passes through unchanged
const args2 = tokenizeArgString(["--name", "Alice", "--age", "25"]);
console.log(args2);
// Output: ["--name", "Alice", "--age", "25"]// Multiple spaces and complex quoting
const complexArgs = tokenizeArgString(
`--input "file with spaces.txt" --output 'result file.json' --verbose`
);
console.log(complexArgs);
// Output: ["--input", "file with spaces.txt", "--output", "result file.json", "--verbose"]
// Empty quotes
const emptyArgs = tokenizeArgString(`--name "" --value ''`);
console.log(emptyArgs);
// Output: ["--name", "", "--value", ""]') and double (") quotes+ '')This function is primarily used internally by yargs-parser but is exposed for advanced use cases where you need to manually tokenize argument strings before parsing.
Install with Tessl CLI
npx tessl i tessl/npm-yargs-parser