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

search-keywords

v3.3.0

Published

search the keywords from target path

Readme

search-keywords

文档锚链接

1. 该库用来干什么?
2. 输出内容简单介绍
3. 配置描述
4. Installation安装
5. Usage使用案例

1. 该库用来干什么?

1.作用:极速查找目标关键字存在于哪些文件中,类似于vscode侧边栏的搜索
2.适合文件:文本文件,如.txt , .c , .js , .html等等...,不适合二进制文件如.excel, .exe, .jpg等等...

2. 输出内容简单介绍

{
    关键字1:{
        文件路径1:[
            该文件路径的第1行,
            该文件路径的第7行
            ...
        ],
        文件路径2:[
            该文件路径的第5行,
            该文件路径的第34行
            ...
        ],
    },
    关键字2:{
        ...
    }
}

例子↓↓↓
{
  console: {
    'F:\\abc\\npm\\temp\\src\\scriptSearch.js': [ 
        17,//第17行
        2,//第2行
        3//第3行
    ],
    'F:\\zyx\\npm\\temp\\src\\searchKeywords.js': [ 42 ]
  },
  search: {...}
}

3. 配置描述

主配置

| 参数名 | 数据类型 | 必填|默认值 |简单描述 |举例| | :----:| :----: | :----: | :----: | :----: |:----: | | rootDirPath | String|是🐢 | | 查询的根目录(绝对路径) |path.resolve(__dirname)| | keywords | Array|是🐢 | | 查询的关键字数组 |["console","function"]| | validExts | Array|否⭕ | [".js",".jsx",".vue"] | 允许的文件后缀,若设置了inValidExts则validExts无效 || | inValidExts | Array|否⭕ | false | 查询所有文件,除了设置的不允许的文件后缀,若设置了inValidExts则validExts无效 || | excludeKeywords | Array|否⭕ | ["(.*)/node_modules", "(.*)/LICENSE", "(.*)/dist"] | 排除的目标文件或目录,根据path-to-regexp库规则进行配置,也可直接传绝对路径 |[path.resolve(__dirname,"./node_modules")]|

4. Installation安装

npm install search-keywords
或者
yarn add search-keywords

5. Usage使用案例

场景一:查找关键字const和require
const scriptSearch = require("search-keywords");
const path = require("path");
const config = {//配置
    rootDirPath: path.resolve(__dirname),
    keywords: ["const","require"]
}
//不传配置则使用默认配置
scriptSearch(config).then(res=>{
    console.log(res)
});
场景二:修改所有一样的目录名,如所有.git包括嵌套的,改为.mygit
const scriptSearch = require('search-keywords');
const path = require('path');
const fs = require("fs/promises")
const originGit = ".git";
const rename = ".mygit"
const config = {//配置
  rootDirPath: path.resolve(__dirname,"__ttt"),
  //.git/config里的关键字repositoryformatversion
  keywords: ['repositoryformatversion'],
  validExts: ['\\' + `${originGit}\\config`],
  excludeKeywords: ["(.*)/node_modules","(.*)/.nuxt","(.*)/.umi", "(.*)/LICENSE", "(.*)/dist"]
}
main({originGit, rename})
async function main({originGit , rename }){
  //不传配置则使用默认配置
  const {repositoryformatversion:result} = await scriptSearch(config);
  const gitPaths = []
  const keys = Object.keys(result)
  for(let keyItem of keys){
    const index = keyItem.indexOf('\\' + originGit)
    if(index !== -1){
      const dir = keyItem.slice(0,index);
      gitPaths.push({
        origin: path.resolve(dir,originGit),
        rename: path.resolve(dir,rename)
      })
    }
  }
  console.log(gitPaths)
  console.time("修改时间")
  await Promise.allSettled(gitPaths.map(it=>{
    return fs.rename(it.origin,it.rename)
  }))
  const {repositoryformatversion:failResult} = await scriptSearch(config);
  let failLen = Object.keys(failResult).length
  console.log(`修改成功数量: ${gitPaths.length - failLen}/${gitPaths.length}`)
  console.timeEnd("修改时间")
}