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

mv-file

v1.0.5

Published

A simple and flexible utility for moving files and directories with support for glob patterns, concurrent operations, and event handling.

Downloads

330

Readme

mv-file

version codecov release node.js license

English | 中文

简单灵活的 文件/目录 移动工具,支持 glob 模式匹配、并发操作和事件处理。

Features

  • 🎯 支持 Glob 模式匹配
  • 📂 设定目录结构
  • 🚀 并发文件操作
  • 🎭 监听操作事件
  • 🧹 支持清理空目录

Installation

npm install mv-file

Usage

moveFile

import { moveFile } from 'mv-file'

// 移动文件
await moveFile(
	{
		'src/html/': 'dist'
		'src/file.txt': 'dist/file.txt',
		'src/**/*.js': 'dist/js',
	},
	{
		force: true,
		clean: true,
	}
)

createFileMover

import { createFileMover } from 'mv-file'

// 创建操作实例
const mover = createFileMover({
	force: true, // 强制覆盖已存在的文件
	clean: true, // 清理空目录
	base: 'src',
	dest: 'dist',
})

// 移动文件
await mover.move({
	'src/js/**/*.js': 'dist/',
})
// => dist/js/**/*.js

// 监听事件
mover.on('copy:start', (source, target) => {
	console.log(`开始复制: ${source} -> ${target}`)
})

mover.on('copy:done', (source, target) => {
	console.log(`复制完成: ${source} -> ${target}`)
})

mover.on('error', (error) => {
	console.error('操作失败:', error.message)
})

API

import { moveFile, createFileMover } from 'mv-file'

// 移动文件
moveFile(pathMap: PathMapping, options?: MoveOptions): Promise<void>
// 创建操作实例
const mover = createFileMover(options?: MoveOptions): FileMover

// 移动文件
mover.move(pathMap: PathMapping): Promise<void>

PathMapping

路径映射表

  • 键:源文件路径
  • 值:目标文件路径
interface PathMapping {
	[source: string]: string
}

MoveOptions

配置选项

| 属性 | 类型 | 默认值 | 说明 | | ------------- | --------- | --------------- | ------------------------ | | cwd | string | process.cwd() | 当前工作目录 | | base | string | | 源基础目录 | | dest | string | | 目标基础目录 | | force | boolean | false | 是否强制覆盖已存在的文件 | | clean | boolean | false | 是否清理空目录 | | verbose | boolean | false | 启用详细日志 | | concurrency | number | 4 | 最大并发操作数 |

FileMover 类

Methods

move(pathMap: PathMapping): Promise<void>

根据提供的路径映射移动文件。

Event

FileOperator 继承自 EventEmitter,提供以下事件:

| 事件 | 参数 | 说明 | | ------------- | ---------------------------------- | -------------- | | copy:start | (source: string, target: string) | 开始copy时触发 | | copy:done | (source: string, target: string) | 完成copy时触发 | | clean:start | (path: string) | 开始清理时触发 | | clean:done | (path: string) | 完成清理时触发 | | error | (error: FileMoverError) | 发生错误时触发 |

FileMoverError

使用自定义的 FileMoverError 类进行错误处理:

class FileMoverError extends Error {
	code: string
	source?: string
	target?: string
	originalError?: Error
}

License

MIT

贡献

欢迎提交 Pull Request 来改进这个工具!