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

meow-helper

v1.6.2

Published

Generate nicely formatted help text for meow CLI automatically.

Downloads

273

Readme

Features

  • Generates help text without effort. See images below.
  • Provides common flags. (--help and --version)
  • meow throws unknown flags with the allowUnknownFlags option. meow-helper shows help text instead of throwing. You can change this behavior with the notThrow option.
  • Formats, colorizes, and aligns arguments, options, default values, and their descriptions.
  • Marks required fields with an *.
  • Supports maximum line length and automatic word wrap.
  • Splits options into two lines if space for description is too small. You can change this behavior with the multilineThreshold option.
  • Generates description, usage, arguments, flags/options, examples sections.
  • Colorizes command in usage and examples and adds $ before command.
  • Exports chalk and cliui.
  • Supports both { autoHelp: true } and { autoHelp: false }. Adds a description to help if required.
  • Moves three dots in arguments outside of brackets. For example: args: { “path...” } becomes command <path>...
  • Adds three dots ... to flags with multiple value.

Synopsis

TypeScript

import getHelp, { commonFlags, chalk, cliui } from "meow-helper";
import type { ExtendedAnyFlags } from "meow-helper";
import { readFileSync } from "fs";
import { join } from "path";

CommonJS

const { default: getHelp, commonFlags, chalk, cliui } = require("meow-helper");
const { readFileSync } = require("fs");

Usage

const flags: ExtendedAnyFlags = {
  name: { alias: "n", type: "string", desc: "Name" },
  cwd: { alias: "c", type: "string", desc: "Working path." },
  context: { type: "string", desc: "Context." },
  ...commonFlags,
};

// Groups options. Keys are the first option of the group.
const groups = {
  name: { title: "General Options", description: "Some description" },
  context: { title: "Other Options", description: "Other description" },
};

const args = { "path...": "Paths of files." };
const pkg = JSON.parse(readFileSync(join(__dirname, "../package.json"), { encoding: "utf8" }));

meow(getHelp({ flags, args, groups, pkg }), { flags, pkg, allowUnknownFlags: false });
const help = getHelp({
  lineLength: 80,
  titleLength: 15,
  pkg: {}, // package.json data
  command: "not-sync",
  description: "Description of the command",
  args: { path: "Path of file." },
  flags, // meow flags with `desc` key.
  examples: ["not-sync node_modules,dist,coverage", "not-sync node_modules,dist,coverage --ignoreConfigs .gitignore"],
  multilineThreshold: 50,
  autoHelp: true,
  notThrow: true,
});

Details

meow-helper generates single-line or multi-line help text based on the multilineThreshold option automatically.

Single-Line

meow-helper help text in single line mode

Multi-Line

meow-helper help text in multi line mode

API

Table of contents

Interfaces

Type aliases

ExtendedAnyFlag

Ƭ ExtendedAnyFlag: AnyFlag & { desc?: string }

Meow flag extended with desc key.

Defined in: get-help.ts:8


ExtendedAnyFlags

Ƭ ExtendedAnyFlags: Record<string, ExtendedAnyFlag>

Record of extended any flag.

Defined in: get-help.ts:11

Variables

cliui

Const cliui: any

Defined in: index.ts:5


commonFlags

Const commonFlags: ExtendedAnyFlags

Very common flags

Defined in: index.ts:12

Functions

default

default(helpOptions: HelpOptions): string

Generate help text for meow.

Example

const flags: ExtendedFlags = { cwd: { alias: "c", type: "string", desc: "Current CWD." }, ...commonFlags };
const args = { path: "Path of file." };

meow(getHelp({ flags, args, pkg }), { flags, pkg, allowUnknownFlags: false });

Parameters:

| Name | Type | Description | | :------------ | :---------------------------------------- | :---------- | | helpOptions | HelpOptions | are options |

Returns: string

Defined in: get-help.ts:193

Interfaces

meow-helper / HelpOptions

Interface: HelpOptions

Options below modify behaviour of [[getHelp]] function.

Properties

args

Optional args: Record<string, string>

Name and description of positional arguments.

Defined in: get-help.ts:28


autoHelp

Optional autoHelp: boolean

This option sets whether the autoHelp option of meow is used. If this is true, the description text is not added, because meow adds it automatically.

Defined in: get-help.ts:36


command

Optional command: string

Name of the command.

Defined in: get-help.ts:22


description

Optional description: string | string[]

Command description.

Defined in: get-help.ts:24


examples

Optional examples: string | string[]

A single example or list of examples can be provided to show in the help text. Lines are prefixed with $ and the command is colored automatically.

Defined in: get-help.ts:32


flags

Optional flags: ExtendedAnyFlags

Flags provided to meow. Uses desc key for the description.

Defined in: get-help.ts:30


groups

Optional groups: Record<string, { description?: string ; title?: string }>

Option groups shown in help text. Key is the first option in group.

Defined in: get-help.ts:40


lineLength

Optional lineLength: number

Text longer than line length will be word-wrapped.

Defined in: get-help.ts:16


multilineThreshold

Optional multilineThreshold: number

If space available for option descriptions is less than this threshold, descriptions are given their own rows. So they have more space. See images above.

Defined in: get-help.ts:34


notThrow

Optional notThrow: boolean

Whether to throw an error when meow exits with exit code 2. If true, it adds process.on("exit") to show help and exits with code 0.

Defined in: get-help.ts:38


pkg

Optional pkg: Record<string, any>

package.json data.

Defined in: get-help.ts:20


titleLength

Optional titleLength: number

The total length of the colored background area of titles.

Defined in: get-help.ts:18


usage

Optional usage: string | string[]

Uasge text is shown at the beginning of help text. Lines are prefixed with $ and command is colored automatically.

Defined in: get-help.ts:26