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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@d-zero/cli-core

v1.3.9

Published

Common CLI utilities for D-Zero tools

Readme

@d-zero/cli-core

CLIアプリケーション構築のためのコアユーティリティ。

エクスポート

すべての機能は @d-zero/cli-core からインポートできます:

  • createCLI - CLIアプリケーションを作成し、コマンドライン引数をパース
  • parseCommonOptions - 共通のCLIオプションをパース
  • parseList - カンマ区切りの文字列を配列に変換
  • 型定義: BaseCLIOptions, CLIAlias, CLIConfig, ParsedCLI

API

createCLI<T>(config: CLIConfig<T>): ParsedCLI<T>

CLIアプリケーションを作成し、コマンドライン引数をパースします。検証に失敗した場合は使用方法を表示して終了します。

パラメータ:

  • config: CLIConfig<T> - CLI設定オブジェクト
    • name?: string - パッケージ名(バージョン表示時に使用)
    • version?: string - パッケージバージョン(-v/--versionオプションで表示)
    • aliases?: CLIAlias - コマンドラインオプションのエイリアス定義(例: { o: 'output' }
    • usage: string[] - ヘルプメッセージとして表示される使用方法の文字列配列
    • parseArgs: (cli: ParsedArgs) => T - 引数をパースしてオプションオブジェクトに変換する関数
    • validateArgs: (options: T, cli: ParsedArgs) => boolean - 引数の妥当性を検証する関数(falseを返すと終了)

バージョン表示:

nameversionを設定すると、-vまたは--versionオプションでバージョン情報を表示できます。ただし、aliasesvが既に別のオプションに割り当てられている場合は、--versionのみが使用可能です。

戻り値:

ParsedCLI<T> オブジェクト:

  • options: T - パースされたオプション
  • args: string[] - 位置引数の配列
  • hasConfigFile: boolean - 設定ファイル(listfileオプション)が指定されているかどうか

使用例:

import { createRequire } from 'node:module';

import { createCLI, type BaseCLIOptions } from '@d-zero/cli-core';

const require = createRequire(import.meta.url);
const pkg = require('../package.json') as { name: string; version: string };

interface MyOptions extends BaseCLIOptions {
	output?: string;
}

const cli = createCLI<MyOptions>({
	name: pkg.name,
	version: pkg.version,
	aliases: {
		o: 'output',
		l: 'limit',
		d: 'debug',
	},
	usage: [
		'Usage: my-cli [options] <input>',
		'',
		'Options:',
		'  -o, --output <file>  出力ファイルパス',
		'  -l, --limit <num>    処理する最大件数',
		'  -d, --debug          デバッグモードを有効化',
	],
	parseArgs: (cli) => ({
		output: cli.output,
		limit: cli.limit ? Number.parseInt(cli.limit) : undefined,
		debug: !!cli.debug,
	}),
	validateArgs: (options, cli) => {
		return cli._.length > 0; // 少なくとも1つの引数が必要
	},
});

console.log(cli.options); // パースされたオプション
console.log(cli.args); // 位置引数

parseCommonOptions(cli: ParsedArgs): Pick<BaseCLIOptions, 'limit' | 'debug' | 'verbose' | 'interval'>

共通のCLIオプション(limit, debug, verbose, interval)をパースします。createCLIparseArgs関数内で使用することを想定しています。

パラメータ:

  • cli: ParsedArgs - minimistでパースされた引数オブジェクト

戻り値:

以下のプロパティを持つオブジェクト:

  • limit?: number - 処理する最大件数
  • debug?: boolean - デバッグモードフラグ
  • verbose?: boolean - 詳細出力モードフラグ
  • interval?: number | DelayOptions - 処理間隔(ミリ秒または遅延オプション)

使用例:

import { createCLI, parseCommonOptions } from '@d-zero/cli-core';

const cli = createCLI({
	parseArgs: (parsedArgs) => {
		const common = parseCommonOptions(parsedArgs);
		return {
			...common,
			// カスタムオプションを追加
			output: parsedArgs.output,
		};
	},
	// ...
});

parseList(listParam: string): string[]

カンマ区切りの文字列をパースして、トリミングされた文字列の配列に変換します。

パラメータ:

  • listParam: string - カンマ区切りの文字列

戻り値:

string[] - トリミングされた文字列の配列

使用例:

import { parseList } from '@d-zero/cli-core';

const result = parseList('apple, banana, cherry');
console.log(result); // ['apple', 'banana', 'cherry']

const result2 = parseList('item1,item2,  item3  ');
console.log(result2); // ['item1', 'item2', 'item3']