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

@dimstack/git-provider

v0.1.2

Published

A unified Git provider interface supporting GitHub, Gitee and more

Readme

@dimstack/git-provider

一个统一的Git提供商接口,支持GitHub、Gitee等平台。

特性

  • 🔄 统一接口: 提供一致的API,支持GitHub和Gitee
  • 📁 文件系统抽象: 将Git仓库当作本地文件系统使用
  • 🔐 版本控制: 完整的Git操作支持,包括提交、分支、合并等
  • 🛡️ 类型安全: 完整的TypeScript类型定义
  • 🚀 现代化: 基于fetch API,支持现代JavaScript环境

安装

npm install @dimstack/git-provider

快速开始

基本使用

import { GitHubProvider, GitFileSystem } from '@dimstack/git-provider';

// 创建GitHub Provider
const provider = new GitHubProvider({
  token: 'your-github-token'
});

// 创建文件系统实例
const fs = new GitFileSystem(provider, {
  owner: 'octocat',
  repo: 'Hello-World'
});

// 读取文件
const content = await fs.readFile('README.md', {
  owner: 'octocat',
  repo: 'Hello-World',
  encoding: 'utf-8'
});

// 写入文件
await fs.writeFile('docs/example.md', '# Hello World', {
  message: 'Add example document'
});

跨平台支持

import { GitHubProvider, GiteeProvider } from '@dimstack/git-provider';

// GitHub
const githubProvider = new GitHubProvider({
  token: 'your-github-token'
});

// Gitee
const giteeProvider = new GiteeProvider({
  token: 'your-gitee-token'
});

// 相同的API接口
const repo = await githubProvider.getRepository({
  owner: 'octocat',
  repo: 'Hello-World'
});

API 参考

GitProvider 接口

interface GitProvider {
  // 仓库操作
  getRepository(options: { owner: string; repo: string }): Promise<ApiResponse<Repository>>;
  createRepository(options: { name: string; private?: boolean; description?: string }): Promise<ApiResponse<Repository>>;
  deleteRepository(options: { owner: string; repo: string }): Promise<ApiResponse<void>>;

  // 用户信息
  getUserInfo(): Promise<ApiResponse<User>>;

  // 分支操作
  getBranches(options: { owner: string; repo: string }): Promise<ApiResponse<Branch[]>>;
  createBranch(options: { owner: string; repo: string; branch: string; ref?: string }): Promise<ApiResponse<Branch>>;

  // 文件操作
  getFile(options: FileSystemOptions & { path: string }): Promise<ApiResponse<FileContent>>;
  getFileInfo(options: FileSystemOptions & { path: string }): Promise<ApiResponse<FileItem[]>>;
  putFile(options: FileSystemOptions & { path: string; content: string | Uint8Array; sha?: string }): Promise<ApiResponse<FileItem>>;
  deleteFile(options: FileSystemOptions & { path: string; sha?: string }): Promise<ApiResponse<void>>;

  // 版本控制
  getCommits(options: { owner: string; repo: string; path?: string; branch?: string; per_page?: number }): Promise<ApiResponse<Commit[]>>;
  getCommit(options: { owner: string; repo: string; sha: string }): Promise<ApiResponse<Commit>>;
  getDiff(options: { owner: string; repo: string; base: string; head: string; path?: string }): Promise<ApiResponse<Diff[]>>;
  mergeBranch(options: { owner: string; repo: string; base: string; head: string; commit_message?: string }): Promise<ApiResponse<MergeResult>>;

  // 拉取请求
  createPullRequest(options: { owner: string; repo: string; title: string; body?: string; head: string; base: string }): Promise<ApiResponse<PullRequest>>;
  getPullRequests(options: { owner: string; repo: string; state?: 'open' | 'closed' | 'all' }): Promise<ApiResponse<PullRequest[]>>;
  mergePullRequest(options: { owner: string; repo: string; pull_number: number; commit_message?: string; merge_method?: 'merge' | 'squash' | 'rebase' }): Promise<ApiResponse<MergeResult>>;
}

GitFileSystem 类

class GitFileSystem {
  constructor(provider: GitProvider, options: { owner: string; repo: string });

  // 文件操作
  readFile(path: string, options: FileSystemOptions & { encoding?: string }): Promise<string | Uint8Array>;
  writeFile(path: string, content: string | Uint8Array, options: FileSystemOptions): Promise<void>;
  deleteFile(path: string, options: FileSystemOptions): Promise<void>;

  // 目录操作
  readdir(path: string): Promise<FileItem[]>;
  mkdir(path: string): Promise<void>;
}

配置选项

GitHubProvider

interface GitHubProviderOptions {
  token: string;                    // GitHub Personal Access Token
  baseUrl?: string;                 // 自定义API基础URL
  timeout?: number;                 // 请求超时时间
  headers?: Record<string, string>; // 自定义请求头
}

GiteeProvider

interface GiteeProviderOptions {
  token: string;                    // Gitee Personal Access Token
  baseUrl?: string;                 // 自定义API基础URL
  timeout?: number;                 // 请求超时时间
  headers?: Record<string, string>; // 自定义请求头
}

错误处理

import { GitProviderError } from '@dimstack/git-provider';

try {
  const repo = await provider.getRepository({
    owner: 'octocat',
    repo: 'non-existent-repo'
  });
} catch (error) {
  if (error instanceof GitProviderError) {
    console.error(`Git Provider Error: ${error.message}`);
    console.error(`Error Code: ${error.code}`);
    console.error(`HTTP Status: ${error.status}`);
  }
}

示例应用

查看 examples/ 目录获取完整的示例应用:

  • 基础使用: examples/basic-usage.ts
  • 个人知识管理: examples/personal-kms.ts
  • 团队文档协作: examples/team-docs.ts
  • Git博客系统: examples/git-blog.ts

运行示例:

# 设置环境变量
export GITHUB_TOKEN="your-github-token"
export GITEE_TOKEN="your-gitee-token"

# 运行基础示例
npx ts-node examples/basic-usage.ts

贡献

欢迎提交 Issue 和 Pull Request!

许可证

MIT License