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

@lucyjs/file-scanner

v1.1.0

Published

文件扫描工具

Downloads

841

Readme

@lucyjs/file-scanner

一个用于扫描文件系统的 TypeScript 工具库。

功能特点

  • 支持递归扫描目录
  • 可按文件扩展名过滤
  • 支持忽略特定文件或目录
  • 可选的模块自动导入功能
  • 完整的 TypeScript 类型支持

安装

使用 npm:

npm install @lucyjs/file-scanner

使用 yarn:

yarn add @lucyjs/file-scanner

使用方法

import { FileScanner } from '@lucyjs/file-scanner';

// 创建扫描器实例
const scanner = new FileScanner({
  dirPath: './src',           // 要扫描的目录路径
  recursive: true,            // 是否递归扫描子目录
  extensions: ['.ts', '.js'], // 要扫描的文件扩展名
  ignore: ['node_modules'],   // 要忽略的文件或目录
  autoImport: true           // 是否自动导入扫描到的模块
});

// 执行扫描
const results = await scanner.scan();

// 处理扫描结果
results.forEach(result => {
  console.log('文件路径:', result.path);
  console.log('文件名:', result.name);
  console.log('扩展名:', result.ext);
  if (result.module) {
    console.log('导入的模块:', result.module);
  }
});

API 文档

ScanOptions

扫描器配置选项接口:

| 参数 | 类型 | 必填 | 默认值 | 说明 | |------|------|------|--------|------| | dirPath | string | 是 | - | 要扫描的目录路径 | | recursive | boolean | 否 | true | 是否递归扫描子目录 | | extensions | string[] | 否 | [] | 要扫描的文件扩展名列表 | | ignore | string[] | 否 | [] | 要忽略的文件或目录路径列表 | | autoImport | boolean | 否 | true | 是否自动导入扫描到的模块 |

ScanResult

扫描结果接口:

| 属性 | 类型 | 说明 | |------|------|------| | path | string | 文件的完整路径 | | name | string | 文件名(不含扩展名)| | ext | string | 文件扩展名 | | module | any | 导入的模块(仅当 autoImport 为 true 时存在)|

FileScanner 类

主要的扫描器类,提供以下方法:

constructor(options: ScanOptions)

创建扫描器实例。

async scan(): Promise<ScanResult[]>

执行扫描操作,返回扫描结果数组。

注意事项

  1. 当使用 autoImport 功能时,请确保扫描的文件是可导入的模块格式。
  2. 路径可以是相对路径或绝对路径,内部会自动转换为绝对路径。
  3. 如果 extensions 数组为空,则会扫描所有文件。

许可证

MIT