0.1.1 • Published 5 years ago
@jiaminghi/fs v0.1.1
使用 Promise 封装了一些常用的文件系统方法(基于 Node.js 的 fs 文件系统)
- 读取文件状态 
- 创建文件夹 
- 连接文件 
- 复制文件夹到指定位置,若文件夹已存在将被清空后进行复制操作 
- 读取文件夹 
- 递归清空文件夹,若文件夹不存在将被创建 
- 递归清空文件夹 
- 读取文件 
- 写入文件 
- 遍历文件夹 
- 递归遍历文件 
- 递归删除指定 extname 的文件 
npm 安装
$ npm install @jiaminghi/fs使用
import { readFile } from '@jiaminghi/fs'
// do somethingstat
type stat = (
  path: fs.PathLike,
  options: fs.StatOptions = { bigint: false }
) => Promise<fs.Stats | fs.BigIntStats | false>mkDir
type mkDir = (path: fs.PathLike, options: fs.MakeDirectoryOptions = {}) => Promise<boolean>access
type access = (path: fs.PathLike, mode = fs.constants.F_OK) => Promise<boolean>copyDir
type copyDir = (path: fs.PathLike, dest: string) => Promise<boolean>readDir
type readDir = (path: fs.PathLike) => Promise<string[] | false>clearDir
type clearDir = (path: fs.PathLike) => Promise<boolean>emptyDir
type emptyDir = (path: fs.PathLike) => Promise<boolean>readFile
type readFile = (
  path: fs.PathLike,
  options: { encoding: string; flag?: string } = { encoding: 'utf8' }
) => Promise<string | false>writeFile
type writeFile = (
  path: fs.PathLike,
  data: any,
  option: fs.WriteFileOptions = 'utf8'
) => Promise<boolean>dirForEach
type dirForEach = (path: fs.PathLike, callback: (path: string) => any) => Promise<boolean>fileForEach
type fileForEach = (path: fs.PathLike, callback: (path: string) => any) => Promise<boolean>unlinkDirFileByExtname
type unlinkDirFileByExtname = (path: fs.PathLike, extnames: string[] = []) => Promise<boolean>