Gathering detailed insights and metrics for micro-memfs
Gathering detailed insights and metrics for micro-memfs
Gathering detailed insights and metrics for micro-memfs
Gathering detailed insights and metrics for micro-memfs
A simple, tiny, in-memory mock file system for all environments.
npm install micro-memfs
Typescript
Module System
Node Version
NPM Version
72.5
Supply Chain
89.5
Quality
75.7
Maintenance
100
Vulnerability
100
License
TypeScript (98.56%)
JavaScript (1.44%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
2 Stars
22 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Jun 13, 2024
Latest Version
1.2.0
Package Id
micro-memfs@1.2.0
Unpacked Size
24.97 kB
Size
6.87 kB
File Count
13
NPM Version
8.16.0
Node Version
18.12.1
Published on
Feb 14, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
micro-memfs
is a tiny in-memory "file system" for use in a simple applications that need a mocked file system i.e. unit testing, web apps or games.
process.cwd()
)path
-like path resolution to support absolute and relative paths.The mock file system is made up of directories, files and "executables".
Files map a path to some text. This text can encode whatever you'd like. A file must have an extension - e.g. directory/file.txt
.
Executables are sync/async functions that will return some output. These are analogous to regular old binaries and thus their source code can be read with readFile()
too.
1type CommandFunc = (args: string[]) => string[] | Promise<string[]>; 2 3interface MicroFs { 4 /** Check if a path exists in the file system. */ 5 exists(path: string): boolean; 6 /** Check if a given path is a directory or a file/doesn't exist. This method also ensures the path exists. */ 7 isDirectory(path: string): boolean; 8 /** Read the text content of a file in the file system. */ 9 readFile(pth: string): string | undefined; 10 /** Read the contents of a directory in the file system. */ 11 readDir(pth: string): string[]; 12 /** Get or set the cwd (current working directory of this file system) */ 13 cwd(pth?: string): string; 14 /** 15 * Find an "executable" in the file system returning a callable function if found. 16 * Use this to prevent your linter going crazy if you try to `eval()` the output from `readFile() ` 17 * */ 18 findExecutable(prog: string): CommandFunc | null; 19}
1import microfs from 'micro-memfs'; 2 3const fs = microfs({ 4 "usr/file.txt": "Some text content", 5}, 6{ 7 "usr/emphasize": (args) => args.concat(["!"]), 8}); 9 10fs.cwd() // '/' 11fs.exists('usr') // true 12fs.isDirectory('usr') // true 13fs.cwd('usr') // '/usr' 14fs.readFile('file.txt') // 'Some text content' 15fs.readFile('emphasize') // '(args) => args.concat(["!"])' 16const emphasize = fs.findExecutable("emphasize"); 17emphasize(['hello', 'world']) // -> ['hello', 'world'] 18fs.cwd('another-dir') // will throw an `Error` as /usr/another-dir doesn't exist
Contributions are always welcome! Please submit them on GitHub :)
No vulnerabilities found.
No security vulnerabilities found.