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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@cpu-search/core

v1.0.1

Published

A TypeScript Node.js toolkit

Readme

@cpu-search/core

一个 vscode 左侧搜索替换同款的代码搜索和替换引擎,是 vscode-search 项目的核心库。

特性

  • 高性能的文本和正则表达式搜索
  • 支持文件包含/排除模式
  • 尊重 .gitignore 规则
  • 提供上下文行显示
  • 支持大小写敏感、全词匹配等选项
  • 生成格式化的搜索报告
  • 基于报告的修改应用功能
  • 搜索历史管理

安装

npm install @cpu-search/core
# 或者
yarn add @cpu-search/core
# 或者
pnpm add @cpu-search/core

基本用法

import { SearchEngine, FileSystem } from '@cpu-search/core';
import { SearchOptions } from '@cpu-search/core/types';

// 实现自定义文件系统适配器
class MyFileSystem implements FileSystem {
  async readFile(path: string): Promise<string> {
    // 实现文件读取
  }

  async writeFile(path: string, content: string): Promise<void> {
    // 实现文件写入
  }

  listFiles(patterns: string[]): Promise<string[]> {
    // 实现文件列表获取
  }

  watchFiles(callback: (path: string) => void): void {
    // 实现文件监控
  }
}

// 创建搜索引擎实例
const fs = new MyFileSystem();
const engine = new SearchEngine(fs);

// 执行搜索
const results = await engine.search('searchPattern', '/path/to/search', {
  caseSensitive: false,
  wholeWord: true,
  useRegex: false,
  include: ['*.ts', '*.tsx'],
  exclude: ['**/node_modules/**'],
  contextLines: { before: 2, after: 2 },
});

// 生成报告
const report = engine.generateReport(results, '/path/to/search');
console.log(report);

// 执行替换
await engine.replace(results, 'replaceText');

// 撤销替换
await engine.undoReplace();

// 应用修改后的报告
await engine.applyReportChange(modifiedReport, '/path/to/search');

API

SearchEngine

搜索引擎核心类,提供搜索、替换和报告生成功能。

方法

  • search(searchPattern, rootPath, options, onProgress?): 执行搜索操作
  • cancelSearch(): 中断当前搜索
  • replace(searchResults, replaceText): 执行替换操作
  • previewReplace(searchResults, replaceText): 预览替换结果
  • undoReplace(): 撤销上一次替换操作
  • generateReport(results, rootPath): 生成搜索报告
  • applyReportChange(reportText, rootPath): 应用修改后的报告

SearchHistory

搜索历史管理类,用于保存和检索搜索查询。

方法

  • saveQuery(searchPattern, options): 保存搜索查询
  • getHistory(): 获取搜索历史

搜索选项

搜索选项对象支持以下属性:

  • caseSensitive: 是否区分大小写 (默认: false)
  • wholeWord: 是否全词匹配 (默认: false)
  • useRegex: 是否使用正则表达式 (默认: false)
  • include: 包含的文件匹配模式 (例如: ['*.ts'])
  • exclude: 排除的文件匹配模式 (例如: ['/node_modules/'])
  • contextLines: 上下文行配置 (例如: { before: 2, after: 2 })
  • maxResults: 最大结果数量
  • respectGitIgnore: 是否尊重 .gitignore 规则 (默认: true)

许可证

ISC