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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@iyowei/fs-deep-walk

v1.0.0

Published

专注于深度扫描指定磁盘位置。

Downloads

1

Readme

@iyowei/fs-deep-walk

专注于深度扫描指定磁盘位置。

  • [x] 复用整个穷举,程序执行完成只发生一次穷举
  • [x] 内嵌仅搜索
  • [x] 编程式,匹配规则等,甚至可以请求远程接口,或者有需要的话可以自己实现功能最匹配需求但代码量最少的类似 “fast-glob”
  • [x] 轻量级场景优选

目录

fsDeepWalk({ from, worker })

  • from { String } 指定磁盘位置,必填
  • worker 处理器,如果扫描的同时需要更新、过滤操作可提供,一定程度复用穷举,可选,{ Function }
    • 返回 { Object | Boolean | Promise }
      • false 过滤掉当前扫描结果
      • true 保留当前扫描结果
      • 对象字面量,保留 / 更新当前扫描结果
      • 如果需要在处理器中需要安放些异步操作,如远程数据请求,可在处理器中返回一个 Promise,该 Promise 可返回,
        • false 过滤掉当前扫描结果
        • true 保留当前扫描结果
        • 对象字面量,保留 / 更新当前扫描结果
        • 其它类型则默认为没有任何处理
      • 其它类型则默认为没有任何处理
  • 返回: {Promise} 扫描到的文件夹、文件
    • files 文件扫描结果
    • dirs 文件夹扫描结果
import { log, time, timeEnd } from 'console';
import { fsDeepWalk } from @iyowei/fs-deep-walk;

(async () => {
  time('fsDeepWalk');

  const asyncrslt = await fsDeepWalk({
    from: process.cwd(),
    worker: (cur) => {
      const excludes = ['.git', 'node_modules'];

      if (cur.dirent.isDirectory() && excludes.includes(cur.dirent.name)) {
        return false;
      }

      return true;
    },
  });

  timeEnd('fsDeepWalk');

  log(asyncrslt);
})();

fsDeepWalkSync({ from, worker })

  • from { String } 指定磁盘位置,必填
  • worker 处理器,如果扫描的同时需要更新、过滤操作可提供,一定程度复用穷举,可选,{ Function }
    • 返回 { Object | Boolean | Promise }
      • false 过滤掉当前扫描结果
      • true 保留当前扫描结果
      • 对象字面量,保留 / 更新当前扫描结果
      • 如果需要在处理器中需要安放些异步操作,如远程数据请求,可在处理器中返回一个 Promise,该 Promise 可返回,
        • false 过滤掉当前扫描结果
        • true 保留当前扫描结果
        • 对象字面量,保留 / 更新当前扫描结果
        • 其它类型则默认为没有任何处理
      • 其它类型则默认为没有任何处理
  • 返回: {Promise} 扫描到的文件夹、文件
    • files 文件扫描结果
    • dirs 文件夹扫描结果
import { log, time, timeEnd } from 'console';
import { fsDeepWalkSync } from @iyowei/fs-deep-walk;

time('fsDeepWalkSync');

const syncrslt = fsDeepWalkSync({
  from: process.cwd(),
  worker: (cur) => {
    const excludeDirs = ['.git', 'node_modules'];

    if (cur.dirent.isDirectory() && excludeDirs.includes(cur.dirent.name)) {
      return false;
    }

    return true;
  },
});

timeEnd('fsDeepWalkSync');

log(syncrslt);

安装

Node Version Badge esm

NPM

npm add @iyowei/fs-deep-walk

PNPM

pnpm add @iyowei/fs-deep-walk

Yarn

yarn add @iyowei/fs-deep-walk

为什么不使用 glob?

"@iyowei/fs-deep-walk" 面对的场景与 "fast-glob" 一类非常相似。后者非常棒,只是各自适应不同的场景,对比 "@iyowei/fs-deep-walk" 的设定就会产生如下差异,

  • 无法复用穷举
  • 内嵌 “搜索 + 匹配”,复杂的实现势必增加体积、性能损耗
  • 配置式,(glob)匹配规则等
  • 重量级场景优选

总的来说,"fast-glob" 一类与 "@iyowei/fs-deep-walk" 的区别类似 Grunt 与 Gulp 的区别。

参与贡献

PRs Welcome

其它

"@iyowei/fs-deep-walk" 使用 @iyowei/create-esm 脚手架生成。