npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mdopt

v2.0.1

Published

markdown option parsing

Downloads

4

Readme

mdopt

markdown option parsing

Useful in combination with marked-man to ensure your man pages are always up to date by making the docs a core part of the cli's runtime. (related: package.json man).

Check out the test cases, or view the example below to get an idea of what a properly formatted options section looks like.

Example

cli.js:

const mdopt = require('mdopt');

const { readFileSync } = require('fs');

const md = readFileSync('path.md', {
  encoding: 'utf8'
});

const argv = process.argv.slice(2)

const argv = mdopt(argv, md);

console.log(argv);

argv is a variable that holds a minimist object that has been populated (aliases, defaults) according to the provided markdown file.

A sample session might look like this:

$ node cli.js
Error: Missing required option demand

$ node cli.js --demand
Error: Missing required option pghost

$ PGHOST=localhost node demo.js --demand hey hey you you
{ _: [ 'hey', 'hey', 'you', 'you' ],
  f: false,
  flag: false,
  home: '/home/jay',
  demand: true,
  default: 'foo',
  d: 'foo',
  pghost: 'localhost' }

And finally what the spec.md file looks like demonstrating all available options:

spec.md

# demo -- A demonstration of the features & formatting

## SYNOPSIS

sample [flags] `<first>` `<last>` `[pet]`

## OPTIONS

### -f, --flag

This is a boolean flag as there is no values that
follow the flag.  It can be accessed with $('f') or
$('flag')

### --anything ANYTHING

This flag expects a value to come after it. It can be a
number, a string, etc. The type will be auto detected
and the value of $('anything') will be that value.

### -s "VALUE", --string "VALUE"

Same as above, except that the value placeholder is in
quotes meaning that no type detection is performed, and
it is kept as a string. Give it `000123` and it will
remain `000123` vs. converting it to a number resulting
in `123`.

### --default=SOMETHING, -d SOMETHING (default=foo)

It is also possible to set default values.

### --home (default=$HOME)

And use environment variables to set those
defaults. Any default value beginning with a `$` will
be treated as an environment variable.

### --demand (required)

We can also demand that a flag should be set.

### --pghost "URI" (required, default=$PGHOST)

Combining required and using environment variables as
defaults is a good way to ensure that the value will be
set one way or another.

## AUTHORS

... Another section

## BUGS

... Another section. Add as many sections as you want.