Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@jiaminghi/fs

jiaming74387MIT0.1.1TypeScript support: included

Promise fs based on node.js fs

fs, node, promise

readme

ENGLISH

FS

LICENSE LICENSE

使用 Promise 封装了一些常用的文件系统方法(基于 Node.js 的 fs 文件系统)

npm 安装

$ npm install @jiaminghi/fs

使用

import { readFile } from '@jiaminghi/fs'

// do something

示例

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>

changelog

0.1.1-alpha (2020-07-06)

Perfect

  • Exception: Throw exception normally.

0.1.0-alpha (2020-05-01)

typescript

  • typescript: Rewrite with typescript.

0.0.2-alpha (2019-07-10)

New

  • access: Promise fs.access.

0.0.1-alpha (2019-07-09)

Bug Fixes

  • Entry: Incorrect entry file setting.

0.0.0-alpha (2019-07-09)

Release

  • stat: fs.stat.
  • mkDir: fs.mkdir.
  • readDir: fs.readdir.
  • copyDir: Copy the folder to the specified location. If the folder already exists in the specified location, the folder will be cleared.
  • clearDir: Recursively empty the specified folder, the folder will be created if it does not exist.
  • emptyDir: Recursively empty the folder.
  • readFile: fs.readFile.
  • writeFile: fs.writeFile.
  • dirForEach: Recursively traverse all folders.
  • fileForEach: Recursively traverse all files.
  • unlinkDirFileByExtname: Delete the specified extname file.