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

@kordar-lib/menus

v2.0.0

Published

菜单与树结构工具库:提供通用侧边栏节点类型、菜单生成服务、二叉树索引、选择树等能力,便于在不同 UI 框架中复用菜单与 Tab 数据结构。

Readme

@kordar-lib/menus

菜单与树结构工具库:提供通用侧边栏节点类型、菜单生成服务、二叉树索引、选择树等能力,便于在不同 UI 框架中复用菜单与 Tab 数据结构。

导出

  • BinaryNode, NODE_TYPE:用于路径搜索的二叉树工具
  • MenuService:通用菜单服务(生成侧边栏、路径索引、节点缓存)
  • TabMenuService:基于根节点拆分 Tab 的菜单服务
  • MenuTree:将原始数组转换为树
  • SelectionTree/SelectionTreeItem:选择树结构
  • SideBarItem:侧边栏节点类型

快速使用

import {MenuService, type SideBarItem} from '@kordar-lib/menus'

// 原始菜单数据(示例)
const raw = [
  { id: 1, pid: 0, title: '系统', router_name: 'system' },
  { id: 2, pid: 1, title: '用户管理', router_name: 'user' },
  { id: 3, pid: 1, title: '角色管理', router_name: 'role' }
]

// 映射成通用节点结构(支持 UI 框架无关的字段)
const mapper = (ele: any): SideBarItem<number> => ({
  id: ele.id,
  pid: ele.pid,
  text: ele.title,
  label: ele.title,
  key: ele.id,
  path: ele.router_name
})

const menusvc = new MenuService<number>(0, mapper)
menusvc.init(raw)

// 侧边栏数据
const menus = menusvc.menus()

// 通过 id 反查节点
const item = menusvc.getItemById(2)

// 计算路径展开链(父链/自身)
const openKeys = menusvc.searchPathIndex(3) // [1,3]

Tab 导航场景:

import {TabMenuService} from '@kordar-lib/menus'

const tabsSvc = new TabMenuService<number>(0, mapper)
tabsSvc.init(raw)
const tabs = tabsSvc.getTabs() // 顶层 pid===root 的条目

类型说明

SideBarItem(核心字段)

  • id:唯一标识(string | number)
  • text/label:展示文本
  • pid:父节点 id
  • path/routerName/url:路由或地址字段
  • children:子节点数组

构建与类型(Monorepo:npm)

在仓库根目录执行:

npm install
npm run -w @kordar-lib/menus build

类型检查:

npm exec -w @kordar-lib/menus -- tsc -p tsconfig.json --noEmit

许可证

MIT