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

af-lfupload

v0.0.1

Published

前端大文件上传组件(React + TypeScript)。特性:

Readme

AF-LFUpload

前端大文件上传组件(React + TypeScript)。特性:

作为 npm 组件库使用

  • 安装:npm i af-lfupload
  • 使用:
import { LargeFileUploader, createMockProtocol } from 'af-lfupload'

const protocol = createMockProtocol()

export function Demo() {
  return <LargeFileUploader protocol={protocol} />
}

注意:react / react-dom 是 peerDependencies,需要由业务项目自行安装。

开发

  • 安装依赖:npm i
  • 启动:npm run dev
  • 构建(库):npm run build
  • 构建(Demo):npm run build:demo
  • 代码检查:npm run lint

组件:LargeFileUploader

入口:

Props

  • protocol: UploadProtocol:上传协议实现(必填)
  • multiple?: boolean:是否允许选择多个文件(默认 true
  • accept?: string:原生 input accept
  • disabled?: boolean
  • maxFiles?: number:最多允许添加多少个文件
  • maxFileSizeBytes?: number:单文件最大字节数(超出会被过滤)

上传行为:

  • chunkSizeBytes?: number:切片大小(默认 5MB)
  • concurrency?: number:并发上传分片数(默认 3)
  • maxRetries?: number:单分片最大重试次数(默认 3)
  • retryDelayMs?: (attempt:number)=>number:重试延迟策略(默认指数退避)
  • autoStart?: boolean:添加文件后是否自动开始上传(默认 false
  • persist?: boolean:是否启用断点续传持久化(默认 true

事件回调:

  • onChange?: (items: UploadFileItem[]) => void
  • onFileAdded?: (item: UploadFileItem) => void
  • onFileRemoved?: (item: UploadFileItem) => void
  • onStatusChange?: (item: UploadFileItem) => void
  • onProgress?: (item: UploadFileItem) => void
  • onSuccess?: (item: UploadFileItem) => void
  • onError?: (item: UploadFileItem) => void

自定义渲染:

  • renderItem?: ({ item, actions }) => ReactNode
    • actions.start() / actions.pause() / actions.cancel() / actions.remove()

状态模型(UploadFileItem)

类型定义见:src/uploader/types.ts

  • statusidle | queued | fingerprinting | uploading | paused | completed | error | canceled
  • progresstotalBytes / uploadedBytes / percent / speedBps?
  • fileId?:断点续传指纹(异步计算,完成后写入)

统一协议:UploadProtocol

接口定义:

核心方法:

  • id: string:协议唯一 id(用于持久化命名空间)
  • init(req):创建/恢复一次上传会话,返回 { uploadId, uploadedParts? }
  • uploadPart(req):上传单个分片(1-based partNumber)
  • complete(req):提交合并
  • abort(req):取消会话
  • getUploadedParts?(req):可选;从服务端查询已上传分片(更强的断点续传保证)

已提供实现:

断点续传设计(当前实现)

  • 文件指纹:fingerprintFile(file) 使用 metadata + 头/尾片段 SHA-256,避免读取全文件
  • 本地持久化:localStorage 记录 protocolId + fileId -> { uploadId, chunkSizeBytes, partCount, uploadedParts }
  • 恢复流程:
    • 若存在本地 session 且切片参数一致:继续未上传分片
    • 若协议支持 getUploadedParts:优先与服务端对齐(更可靠)

Demo

默认页面已替换为 Demo:

使用 createMockProtocol() 可以在没有后端时演示并发、失败重试、断点续传。

React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

React Compiler

The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see this documentation.

Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:

export default defineConfig([
  globalIgnores(['dist']),
  {
    files: ['**/*.{ts,tsx}'],
    extends: [
      // Other configs...

      // Remove tseslint.configs.recommended and replace with this
      tseslint.configs.recommendedTypeChecked,
      // Alternatively, use this for stricter rules
      tseslint.configs.strictTypeChecked,
      // Optionally, add this for stylistic rules
      tseslint.configs.stylisticTypeChecked,

      // Other configs...
    ],
    languageOptions: {
      parserOptions: {
        project: ['./tsconfig.node.json', './tsconfig.app.json'],
        tsconfigRootDir: import.meta.dirname,
      },
      // other options...
    },
  },
])

You can also install eslint-plugin-react-x and eslint-plugin-react-dom for React-specific lint rules:

// eslint.config.js
import reactX from 'eslint-plugin-react-x'
import reactDom from 'eslint-plugin-react-dom'

export default defineConfig([
  globalIgnores(['dist']),
  {
    files: ['**/*.{ts,tsx}'],
    extends: [
      // Other configs...
      // Enable lint rules for React
      reactX.configs['recommended-typescript'],
      // Enable lint rules for React DOM
      reactDom.configs.recommended,
    ],
    languageOptions: {
      parserOptions: {
        project: ['./tsconfig.node.json', './tsconfig.app.json'],
        tsconfigRootDir: import.meta.dirname,
      },
      // other options...
    },
  },
])