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

ltw-engine

v1.0.0

Published

LTW file decoder library with virtual file system support

Readme

@ltw/decoder

前端 LTW 解码器 - Service Worker 虚拟文件系统 + iframe 预览

安装

yarn add @ltw/decoder

最短路径使用

import { LTWPreviewer } from "@ltw/decoder";

// 1. 创建预览器
const previewer = new LTWPreviewer({
  serviceWorkerUrl: "./ltw-sw.js",
});

// 2. 初始化
await previewer.init();

// 3. 加载文件
await previewer.load(file);

// 4. 预览
await previewer.createPreview(container);

核心思路

架构

LTW 文件 → LTWParser (解析) → Service Worker (虚拟文件系统) → iframe (预览)

关键点

  1. LTWParser: 解析 LTW 二进制格式,提取文件列表和内容
  2. Service Worker: 拦截 /ltw-virtual/* 请求,从内存返回文件
  3. LTWPreviewer: 封装完整流程,管理 SW 和 iframe 生命周期

Service Worker 配置

复制 public/ltw-sw.js 到项目 public 目录:

// 核心逻辑:拦截虚拟路径请求
self.addEventListener("fetch", (event) => {
  const url = new URL(event.request.url);
  if (url.pathname.startsWith("/ltw-virtual/")) {
    const filePath = url.pathname.replace("/ltw-virtual/", "");
    const file = virtualFiles.get(filePath);
    event.respondWith(
      new Response(file.data, {
        headers: { "Content-Type": file.mimeType },
      }),
    );
  }
});

API

LTWPreviewer

// 构造
new LTWPreviewer({
  serviceWorkerUrl: string,      // SW 路径
  fallbackMode?: boolean,        // 降级模式(无 SW)
  onReady?: () => void,
  onError?: (error: Error) => void
})

// 方法
init(): Promise<boolean>                    // 初始化 SW
load(file: File): Promise<void>             // 加载 LTW
createPreview(container, options?): Promise // 创建 iframe
getParser(): LTWParser | null               // 获取解析器
cleanup(): void                             // 清理资源

LTWParser

load(file: File): Promise<void>             // 加载文件
listFiles(): string[]                       // 文件列表
getFile(path: string): Promise<LTWFile>     // 读取文件

开发

yarn dev      # 开发模式
yarn build    # 构建(ES + UMD)
yarn buildp   # 构建单文件(压缩混淆)
yarn link     # 本地链接