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

@havocrao/picktui

v0.1.2

Published

TUI candidate picker — pure TypeScript implementation. Filter / pick / history / confirm, zero runtime dependencies, same semantics as the Go engine (no binary required).

Readme

@havocrao/picktui — TUI 候选选择器(纯 TypeScript)

纯 TS 实现:过滤/匹配/交互选择/记忆全部在 JS 内完成,零运行时依赖、 无需任何引擎二进制,安装即用。行为与 Go 引擎(../go/cmd/picktui)语义 逐项对齐(匹配算法、高亮区间、非交互退化、状态文件格式互兼容)。 同份源码构建 esm + cjs + d.ts,TS 与 JS 共用。

安装

$ npm install @havocrao/picktui

交互 TUI 由本包渲染:POSIX 上打开 /dev/tty(宿主 stdout 干净,$(...) 安全);无 /dev/tty 的环境(如 Windows)退化为宿主 stdio。无 TTY 时 自动退化(无 query 取首个、有 query 过滤取首);取消(esc/ctrl+c) 返回 null;错误抛 PicktuiError(含 exitCode/stderr 诊断)。

API

import { filter, resolve } from '@havocrao/picktui/filter'
import { pick, menu, rawPick } from '@havocrao/picktui/tui'
import { histGet, histSet } from '@havocrao/picktui/history'
import { confirmCheck, confirmAdd } from '@havocrao/picktui/confirm'
import type { Candidate, FilterOptions, FilteredCandidate, PickFlags } from '@havocrao/picktui/types'
import { VERSION } from '@havocrao/picktui'

| 函数 | 说明 | |---|---| | filter(cands, query?, opts?) | 过滤 + 高亮区间(ranges 为 rune 区间,空查询恒 []) | | resolve(cands, query) | 精确/唯一前缀解析;无唯一解返回 null | | pick(cands?, flags?) | 交互过滤选择;flags 透传 -q/--label/--sep/--fuzzy/-1/--auto | | menu(label, cands) | 多值缩写菜单(数字 1-9 直选) | | rawPick([...args]) | 透传 pick 参数(--from/--map 等) | | histGet(label) / histSet(label, value) | 选择记忆 | | confirmCheck / confirmAdd | 自动匹配首次确认(add 幂等) | | ONESHOT_ENV / isOneshot() | 宿主循环 oneshot 开关(PICKTUI_ONESHOT=1 时 isOneshot() 为 true) | | VERSION | 本实现语义版本 |

注:pick 候选来自参数(不读宿主进程自身 stdin);需要命令/管道来源时用 rawPick(['--from', '<cmd>', ...])(10s 超时,失败带 stderr 诊断)。

宿主循环 oneshot:pick/menu 单次调用选完即返回,"执行完具体 cmd 后 保持 UI(再次渲染)"的循环由宿主维持。宿主每轮执行完选中的命令并输出结果后, 依 isOneshot() 决定是否退出循环:不设置 PICKTUI_ONESHOT 保持原有循环行为; =1 时 oneshot 模式——执行一次即退出(进程退出 / 退出 UI 循环)。参考实现见 examples/run-loop.mjs。

开发

$ npm install            # 安装 devDependencies(typescript,无运行时依赖)
$ npm run build          # tsc 双输出:dist/esm + dist/cjs + dist/types
$ npm test               # node:test 全量测试(filter/history/confirm/tui/model)
$ npm run test:pack      # npm pack → 干净目录安装 → import/require 冒烟

测试均为纯 JS 断言,无需二进制或 TTY:交互 TUI 的按键行为由 model 级测试覆盖。