ENGLISH
FS
使用 Promise 封装了一些常用的文件系统方法(基于 Node.js 的 fs 文件系统)
npm 安装
$ npm install @jiaminghi/fs
使用
import { readFile } from '@jiaminghi/fs'
示例
stat
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>