Skip to content

A nodejs fs wrapper that provides some hight-level functions for manipulating files and directories.

Notifications You must be signed in to change notification settings

willybrauner/mfs

Repository files navigation

mfs

mfs (micro-fs) is a nodejs fs wrapper that provides a collection of high-level functions for manipulating files and directories.

Installation

npm install @wbe/mfs

Usage

import { * as mfs } from '@wbe/mfs';

(async () => {
  // create a new file in a non-existing directory
  await mfs.createFile('/test/foo.txt', 'Hello World');
  const content = await mfs.readFile('/test/foo.txt');
  console.log(content); // -> "Hello World"
})();

API

Async functions

  • fileExists
function fileExists(path: string): Promise<boolean>
  • createFile
function createFile(path: string, content?: string): Promise<void>
  • readFile
function readFile(path: string): Promise<string>
  • removeFile
function removeFile(path: string): Promise<boolean>
  • copyFile
function copyFile(
  src: string,
  dest: string,
  {
    transform,
    force,
  }: { transform?: (content: string) => Promise<string>; force?: boolean }
): Promise<void>
  • dirExists
function dirExists(path: string): Promise<boolean>
  • readDir
function readDir(path: string, recursive = true): Promise<string[]>
  • removeDir
function removeDir(path: string): Promise<void>
  • createDir
function createDir(path: string): Promise<string | undefined>
  • copyDir
function copyDir(
  src: string,
  dest: string,
  { force }: { force?: boolean } = {}
): Promise<void>

Sync functions

  • fileExistsSync
function fileExistsSync(path: string): boolean
  • createFileSync
function createFileSync(path: string, content?: string): void
  • readFileSync
function readFileSync(path: string): string
  • removeFileSync
function removeFileSync(path: string): boolean
  • copyFileSync
function copyFileSync(
  src: string,
  dest: string,
  {
    transform,
    force,
  }: { transform?: (content: string) => string; force?: boolean }
): void
  • dirExistsSync
function dirExistsSync(path: string): boolean
  • readDirSync
function readDirSync(path: string, recursive = true): string[]
  • removeDirSync
function removeDirSync(path: string): void
  • createDirSync
function createDirSync(path: string): string | undefined
  • copyDirSync
function copyDirSync(src: string, dest: string, { force }: { force?: boolean } = {}): void

License

MIT

Credits

© Willy Brauner

About

A nodejs fs wrapper that provides some hight-level functions for manipulating files and directories.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published