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

@webgal-go/parser

v0.0.11

Published

webgal-go/parser

Downloads

20

Readme

一个可配置、可扩展的解析器,分为 预解析器(状态机核心)和解析器工厂(封装与扩展) 两部分。以下是核心逻辑解析:

一、整体架构与角色

| 文件 | 核心职责 | 关键能力 | | --------- | ---------------------------- | -------------------------------------------------------------------------------------------------------------- | | parser.ts | 解析器工厂,负责组装解析流程 | ✅ 配置预解析规则 ✅ 扩展插件(处理解析后的数据)✅ 对外提供 preParse/parse/stringify 接口 | | pre.ts | 预解析器(状态机实现) | ✅ 基于状态机解析原始文本 →Section 数组 ✅ 支持自定义分隔符、转义规则 ✅ 处理 header/body/属性/注释 等状态切换 |

二、parser.ts 解析(工厂层)

核心逻辑:createParserFactory

作用:创建解析器工厂,支持配置预解析规则和挂载插件,最终生成 Parser 实例。

三、pre.ts 解析(状态机层)

  1. 状态机设计
  • 状态类型:'header' | 'body' | 'attributeKey' | 'attributeValue' | 'comment',覆盖文本解析的核心阶段。
  • 上下文 Context:保存解析过程中的临时数据(当前状态、已解析的 Section 数组等)。
  • 状态处理器 stateHandlers:每个状态对应一组处理函数,处理转义、分隔符、状态切换等逻辑:
  1. 核心方法 preParser.parse

    流程:

  • 初始化上下文(createContext),包含原始文本、解析位置、空 Section 数组。
  • 循环处理剩余文本,根据当前状态调用对应处理器(如 header 状态处理转义、进入 body 等)。
  • 处理分隔符、属性、注释的切换(如 enterBody 检测到 body 分隔符时切换状态)。
  • 完成一段解析后,通过 pushCurrentSection 保存到 sections 数组。

四、扩展与灵活性

配置扩展:

  • 自定义配置:
    • 分隔符(如 body 开始 / 结束符、注释分隔符)。
    • 转义规则(如转义字符、转义后的处理逻辑)。
  • 插件扩展:
    • 工厂的 use 方法允许挂载插件,插件通过 管道函数(pipe) 组合,在 parse 阶段对 Article 进行加工(如添加元数据、转换格式)。