Registry / tiny-opts-parser

tiny-opts-parser

JSON →
library0.0.3jsnpmunverified

tiny-opts-parser is an extremely lightweight and minimal command-line interface (CLI) options parser for JavaScript and TypeScript applications. Currently at version 0.0.3, it focuses on providing core argument parsing functionality without the overhead or extensive feature sets found in more comprehensive libraries like Commander, Minimist, or Yargs. It takes an array of strings (typically `process.argv.slice(2)` from Node.js) and an optional configuration object, returning a structured object representing parsed arguments and options. Its design prioritizes simplicity and a small footprint, making it suitable for projects where bundle size or minimal dependency count is critical. Given its very early version number, its release cadence is likely slow and focused on stability rather than rapid feature additions, and users should anticipate a deliberate pace of development. It aims to produce an output format consistent with popular CLI parsers, simplifying migration or usage for developers familiar with other tools.

npm install tiny-opts-parser
INSTALL
IMPORT
SIG · TINY-OPTS-PARSER
T
tiny-opts-parser
javascriptv0.0.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

parser
import parser from 'tiny-opts-parser';
import { parser } from 'tiny-opts-parser';
The library uses a default export for its primary parser function.
parser
const parser = require('tiny-opts-parser');
const { parser } = require('tiny-opts-parser');
CommonJS `require` also imports the default export directly.

Demonstrates parsing various CLI argument styles and accessing the resulting structured options object.

import parser from 'tiny-opts-parser'; // Simulate command line arguments as if `node myapp.js -a -bcd def xyz --abcd --foo=bar --num 123` was run const argsFromCLI = ['-a', '-bcd', 'def', 'xyz', '--abcd', '--foo=bar', '--num', '123']; // Parse the arguments array const parsedOptions = parser(argsFromCLI); console.log('Parsed Options:', parsedOptions); /* Example output for the argsFromCLI above: { _: ['xyz'], a: true, b: true, c: true, d: 'def', abcd: true, foo: 'bar', num: '123' // Note: '123' might be a string, not a number, depending on internal logic } */ // A more practical example demonstrating access to parsed values const myAppArgs = ['--env', 'production', '-p', '8080', 'serve', '--verbose']; const parsedAppArgs = parser(myAppArgs); console.log('Environment:', parsedAppArgs.env); // Expected: production console.log('Port:', parsedAppArgs.p); // Expected: 8080 console.log('Command:', parsedAppArgs._[0]); // Expected: serve console.log('Verbose flag present:', parsedAppArgs.verbose); // Expected: true // Accessing an environment variable (simulated) as part of an app's logic const apiKey = parsedAppArgs.apiKey ?? process.env.APP_API_KEY ?? 'default-key'; console.log('API Key source:', apiKey === 'default-key' ? 'default' : 'CLI/Env');
Debug
Known issues
gotchaEarly-stage development: Version 0.0.3 indicates that `tiny-opts-parser` is in early development. While functional, users should be aware that future minor releases may introduce breaking changes without explicit major version bumps, as stability guarantees are typically established in higher versions.
fix
Pin exact versions of the package in `package.json` (e.g., `"tiny-opts-parser": "0.0.3"`) and thoroughly review any changelog before updating to a new minor version.
affects: >=0.0.1
gotchaLimited feature set: As a 'tiny' parser, `tiny-opts-parser` deliberately omits advanced CLI features such as built-in command chaining, extensive type validation, or auto-generated help messages. It focuses solely on basic argument parsing.
fix
For complex CLI applications requiring rich features, consider more comprehensive libraries like `commander`, `minimist`, or `yargs`. If `tiny-opts-parser` is chosen, be prepared to implement additional logic for validation, help, and command handling manually.
affects: *
gotchaImplicit type handling: The parser might treat all option values as strings by default, even if they appear to be numbers or booleans (e.g., `--count 10` might result in `count: '10'`). Explicit type coercion may be required in application logic.
fix
Manually convert parsed option values to their desired types within your application code (e.g., `parseInt(parsed.count, 10)`, `parsed.myFlag === 'true'`). Consult the documentation for any specific configuration options related to type handling.
affects: *
gotchaPotential for dormant maintenance: The very low version number (0.0.3) and limited community activity could indicate that the project might not receive frequent updates, bug fixes, or security patches, which could be a concern for long-term projects.
fix
Evaluate your project's long-term maintenance needs and reliance on prompt updates. Consider contributing to the project, forking it, or migrating to a more actively maintained alternative if consistent updates and support are critical.
affects: *
Errors
Common errors & fixes
TypeError: parser is not a function
Incorrectly importing the default export or attempting to destructure it as a named export in CommonJS.
fix
For CommonJS, use `const parser = require('tiny-opts-parser');`. For ESM, use `import parser from 'tiny-opts-parser';`.
Argument 'myOption' is a string, expected number.
The parser returns values as strings by default, and your application code expects a numeric type.
fix
Explicitly convert the parsed value to a number: `const myOption = parseInt(parsedOptions.myOption, 10);`.
Upgrade
Version history
0.0.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources
tiny-opts-parser — npm install tiny-opts-parser · libregistry