mfs
(micro-fs) is a nodejs fs wrapper that provides a collection of high-level functions for manipulating files and directories.
npm install @wbe/mfs
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"
})();
- 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>
- 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
MIT
© Willy Brauner