Registry / devops / argv-formatter

argv-formatter

JSON →
library1.0.0jsnpmunverified

Transforms an options object into a process.argv-like array for use with child_process.spawn. Current stable version is 1.0.0, last released in 2014. Unlike minimist (which parses argv into an object), argv-formatter does the reverse: converts an object of options into an array of arguments. Handles boolean flags, stringified values, and '_' for positional arguments. Minimal dependencies, no updates for over a decade, but stable for its narrow purpose.

npm install argv-formatter
INSTALL
IMPORT
SIG · ARGV-FORMATTER
A
argv-formatter
devopsjavascriptv1.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

format
import { format } from 'argv-formatter'
const formatter = require('argv-formatter')
Package has no default export; use named import or CommonJS destructuring.
require('argv-formatter')
const { format } = require('argv-formatter')
const formatter = require('argv-formatter'); formatter()
CommonJS require returns an object with a 'format' method; calling the require result directly is an error.
default
import { format } from 'argv-formatter'
import format from 'argv-formatter'
No default export; using default import will result in undefined.

Demonstrates converting an options object to argv array, then using it with child_process.spawn.

import { format } from 'argv-formatter'; const args = format({ _: './test/*', format: '%h', R: true }); console.log(args); // ['--format', '%h', '-R', './test/*'] // With child_process import { spawn } from 'child_process'; const child = spawn('git', ['log'].concat(args));
Debug
Known issues
gotchaValues are stringified: passing a Date object will produce a string representation.
fix
Format values to strings before passing to format().
affects: >=0.0.0
gotchaFalsy values (null, undefined, false) are removed from the arguments array, which may silently drop intended flags.
fix
Explicitly check if a value should be included, e.g., use { verbose: true } instead of conditional.
affects: >=0.0.0
gotchaWhen using CommonJS, require returns an object with a format method; forgetting to destructure is a common mistake.
fix
const { format } = require('argv-formatter');
affects: >=0.0.0
deprecatedPackage is effectively unmaintained (last release 2014). No TypeScript definitions.
fix
Consider using a modern alternative like yargs-parser's unparse or building your own with simpler logic.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: formatter is not a function
Calling the require result directly instead of using the format method.
fix
const { format } = require('argv-formatter'); const args = format({...});
undefined is not an object (evaluating 'formatter.format')
Default import returns undefined; package has no default export.
fix
Use named import: import { format } from 'argv-formatter';
./test/* is not a file or something when spawning
Values are stringified; an array under '_' is flattened but not escaped. Shell globbing not handled.
fix
Use exec or shell option in child_process for glob expansion, or pass array of filenames.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources
argv-formatter — npm install argv-formatter · libregistry