8000 GitHub - apla/funar: Signature parser for functions
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

apla/funar

Repository files navigation

funar

Signature parser for functions

github action codecov npm

Example

funar allows you to convert this function:

// example package: `jscertооl`; source path: `src/cli.js`
/**
 * Update certificate on local machine using an existing TLS certificate
 * @param   {Object}  options
 * @param   {string}  options.domainName Domain name to download the certificate for
 * @param   {boolean} [options.verbose]  Be verbose
 * @returns {Promise}
 */
export async function updateCertificate ({domainName, verbose}) {}

To this CLI:

$ npx jscertооl updateCertificate
Missing required parameter: domainName
Update certificate on local machine using an existing TLS certificate
Usage: updateCertificate [options]
Required:
  --domainName=<string>  Domain name to download the certificate
Optional:
  --verbose              Be verbose

No configuration required!

Getting started

Generate CLI from ESM

Run the generator:

$ npx funar cli -i src/<cli>.js -o bin/<packageName>.js

(Optionally) setup package.json for npx:

npm pkg set bin.$(npm pkg get name | xargs echo)=./bin/<packageName>.js

Compatibility

Running

Only ESM modules are supported right now

Testing

Node.js v22 is required because of native V8 coverage

How it works

How is this possible? The function metadata already includes:

  • The function's input contract, specifying the input data structure, parameter types, and associated destructured variable names
  • Function output contract
  • Synchronized parameter descriptions (you can use tsc to ensure the documentation is in sync with the function declaration)
  • The exported name to allow running different functions in one executable

Running a function as a CLI is straightforward if you have a function contract. Here's the process:

  1. Parse input parameter values from command line arguments
  2. Validate input parameter values
  3. Pass values to the function

Additional features:

  • Function name and parameter autocompletion;
  • Generate usage for a function
  • Generate usage for an executable to list all the functions
  • Support …rest to read extra arguments

About

Signature parser for functions

Resources

License

Stars

Watchers

Forks

3649

Releases

No releases published

Packages

No packages published
0