# ketargs
ketargs is a TypeScript-based utility designed for converting JavaScript objects into command-line arguments. This library serves as a counterpart to mustargs, focusing on generating CLI-friendly argument strings from structured data. ketargs is ideal for scenarios where command-line arguments need to be dynamically generated from JavaScript objects.
- TypeScript Support: Built with TypeScript, offering type safety and integration with TypeScript-based projects.
- Flexible Input Handling: Capable of handling nested objects, arrays, and primitive data types.
- CLI-Style Argument Generation: Converts object properties into CLI-style flags and parameters.
ketargs is available as a package and can be easily integrated into your TypeScript or JavaScript project. To install ketargs, use the following command:
npm install ketargsImport ketargs into your project and pass a JavaScript object to convert it into an array of CLI arguments.
import ketargs from 'ketargs';
const options = {
verbose: true,
output: 'dist',
config: {
width: 1920,
height: 1080
},
format: ['jpeg', 'png']
};
const cliArgs = ketargs(options);
console.log(cliArgs);The ketargs function takes an object and recursively processes each key-value pair. Arrays are handled by placing each element under the same flag, while nested objects are flattened using dot notation.
- Primitive values (string, number, boolean) are converted directly.
- Arrays result in multiple values under the same key.
- Nested objects are flattened with keys combined using dot notation.
const options = {
optimize: true,
config: {
depth: 3,
algorithms: ['gzip', 'brotli'],
nested: {
children: 'value'
}
},
targets: ['src', 'lib']
};
const args = ketargs(options);
//['--optimize','--config','depth=3','algorithms=gzip,brotli','nested.children=value', '--targets','src','lib']When using ketargs in your project, it's crucial to ensure that your Node.js environment recognizes ESModule syntax. For this, you need to add the following line to your project's package.json:
{
"type": "module",
}Contributions to ketargs are welcome. This library is part of the toolx library.
ketargs is licensed under the MIT License.