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

@dongfangw/library-core

v0.2.1

Published

内容库清单契约:library.yaml 的解析 / 校验 / 扫描 / 检索过滤(零运行时依赖)

Readme

@dongfangw/library-core

内容库清单契约层。 把一个"资料库"变成任何工具都能读的东西:一份 library.yaml 声明有哪些分组、怎么扫、怎么检索、对谁可见;本包负责解析、校验、扫描与过滤。

零运行时依赖(只用 Node 内置)。三套件(study / prep / sim)与内容仓都只依赖它,互不相识。

30 秒

npx @dongfangw/library-core validate ./my-library     # 体检一份内容库
npx @dongfangw/library-core catalog  ./my-library     # 打印目录树
npx @dongfangw/library-core catalog  ./ws --viewer teacher
# my-library/library.yaml
schema: aero-library/1
id: my-notes
title: 我的笔记库
kind: notes
visibility: private
groups:
  - { id: main, label: 笔记, dir: notes, exts: [md], maxDepth: 3 }

两种模式

| 模式 | 触发条件 | 分组来源 | |---|---|---| | manifest | 库根有 library.yaml(或 .json) | 清单里的 groups | | legacy | 库根同时有 textbook/ teaching-case/ lesson-plan/ | 内置的 11 个分组(与拆分前逐字节一致) |

legacy 模式是兼容层:test/fixtures/legacy-digest.json 存着拆分前的目录树指纹, test/legacy.test.ts 每次都比对(学生 / 教师两个视图)。

公开接口

import {
  buildCatalog, loadLibrary, loadWorkspace, resolveEntry,   // 加载与目录树
  buildLibraryCatalog, buildLegacyCatalog,                   // 单库 / legacy
  scanFiles, scanDecks, buildTreeFromFiles, flattenPaths,    // 扫描原语
  searchLibraries, readStatusField, tokenize, analyzeQuery,   // 检索(在线全文扫)
  buildIndex, writeIndex, readIndex, queryIndex,              // 分块索引(节 → 块)
  isIndexStale, workspaceFingerprint, docTitle,               // 索引过期判定 / 节名提取
  isInside, resolveSafe, dirExists, fileExists,               // 路径
  parseYamlSubset, readConfigFile,                           // 清单解析(YAML 子集 / JSON)
} from '@dongfangw/library-core'

检索与索引(两种粒度,别混用)

| 入口 | 粒度 | 何时用 | |---|---|---| | searchLibraries(libs, query, opts) | 行级片段 | 永远最新(每次读全文);适合"某个词出现在哪一行" | | buildIndex + queryIndex | 块级证据(段落) | 需要"哪一节讲这个""式 C17.2-11 定义在哪";读索引,不碰正文 |

queryIndex 的块带行范围而不是正文:索引才几 MB,取原文按 path + startLine/endLine 回文件读。索引落 <workspace>/.kb-index/kb-index.json:

aero-library index <workspace>              # 建/重建(默认跳过 kind: reference 的库)
aero-library query <workspace> "正激波 总压" --top 8
aero-library query <workspace> "C17.2-11"   # 式号直查

块的边界落在小节标题上(同级标题必断;下级标题只在当前块已够长时才断,标题与自己的正文 同块);节名取正文第一行标题(docTitle),取不到才退回文件名。KbIndex.fingerprint 记下 文件数与最新 mtime,isIndexStale(index, workspace) 判「要不要重建」——有正文比 generatedAt 新、或文件数变了,就算过期。宿主插件据此在打开资料面板时自动重建,学生不用碰 CLI。

两条纪律:

  1. 索引是派生物,永远允许回退到 searchLibraries——调用方不该因为"没建索引"就不可用。
  2. 切词口径统一:tokenize 返回去重的词表(不是词频),问句先过 stripQueryNoise; 词频自己数。多词查询按"任一切词命中"入选,mode: 'all' 要求全覆盖。

可见性(两处,语义不同)

  • 库级 visibility:teacher 的库只在教师视图出现;private 是学生自己的库; public 任何人可见(须写 license)。
  • 分组级 teacherOnly:同一个库里某些分组只给老师(如习题解答)。学生视图里换成 「(教师端内容 · 学习模式下隐藏)」占位分组 —— 与拆分前行为一致。

YAML 支持范围(故意不完整)

支持:key: value、嵌套映射、序列、行内 [a, b] / {a: 1}、引号、注释、数字/布尔/null。 不支持:锚点、多行块标量、标签、多文档。需要这些时写 library.json(JSON 也是合法 YAML)。

门禁

npm test          # 25 例:YAML / 路径 / 清单 / 目录树 / 检索 / legacy 黄金指纹
npm run test:node # 标准 runner(每文件一个子进程)

许可

MIT。