npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fs-mock

v1.2.1

Published

[ABANDONED] Simple fs mock with posix and windows file system styles

Downloads

1,274

Readme

fs-mock

NPM version Dependency Status Build Status

Donate

Simple fs mock with posix and windows file system styles.

Help

Unfortunately I don't have any more time to maintain this repository :-(

Don't you want to save me and this project by taking over it?

sad cat

Installation

$ npm install fs-mock

Usage

This module does not change original fs module in any way.

If you want to pass this module into other module, you will have to use for example rewire package.

var FS = require('fs-mock');
var fs = new FS({
	'var': {},											// empty directory
	'var/www/index.php': '',							// empty file in /var/www, so directory var is now not empty
	'home/david/documents/school/projects': {},
	'home': {
		'david': {},
		'john': {
			'password.txt': 'my super password'			// file
		}
	}
});

var myPassword = fs.readFileSync('/home/john/password.txt', {encoding: 'utf8'});		// my super password

If you write some path like this: home/david/documents/school/projects, it will be automatically expanded and all its parent directories will be also added to mocked file system.

Windows

var fs = new FS({
	'Users': {
		'David': {
			'password.txt': 'my super password'
		}
	}
}, {
	windows: true
});

This will change delimiter from / to \ and add root directory to c:.

Other drives

new FS({ ... }, {
	windows: true,
	drives: ['c:', 'd:', 'z:']
});

Another root directory

new FS({ ... }, {
	windows: true,
	drives: ['c:', 'd:', 'z:'],
	root: 'z:'
});

Now every path will be saved into z: drive.

If you want to save paths to custom drives, you need to disable auto saving into options.root.

new FS({
	'c:': {
		'Users': {}
	},
	'x:': {
		'xampp': {
			'htdocs': {}
		}
	}
}, {
	windows: true,
	root: false
});

I haven't got any machine with Windows so all methods (like chmod) works just like in Unix systems. Please let me know if you want to improve this and how.

Supported functions

There are also all *Sync methods.

Calling unsupported methods will throw an exception.

Fs object:

  • fs.rename(): yes
  • fs.ftruncate(): yes
  • fs.truncate(): yes
  • fs.chown(): yes
  • fs.fchown(): yes
  • fs.lchown(): yes
  • fs.chmod(): yes
  • fs.fchmod(): yes
  • fs.lchmod(): yes
  • fs.stat(): yes
  • fs.lstat(): yes
  • fs.fstat(): yes
  • fs.link(): yes
  • fs.symlink(): yes (type argument is ignored)
  • fs.readlink(): yes
  • fs.realpath(): yes
  • fs.unlink(): yes
  • fs.rmdir(): yes
  • fs.mkdir(): yes
  • fs.readdir(): yes
  • fs.close(): yes
  • fs.open(): yes
  • fs.utimes(): yes
  • fs.futimes(): yes
  • fs.write(): yes
  • fs.read(): yes
  • fs.readFile(): yes
  • fs.writeFile(): yes
  • fs.appendFile(): yes
  • fs.watchFile(): no (use fs.watch())
  • fs.unwatchFile(): no (use fs.watch())
  • fs.watch(): yes (persistent option is ignored)
  • fs.exists(): yes
  • fs.createReadStream(): yes
  • fs.createWriteStream(): yes

Stats object:

  • dev: no
  • ino: no
  • mode: yes
  • nlink: no
  • uid: yes
  • gid: yes
  • rdev: no
  • size: yes
  • blksize: yes
  • blocks: yes
  • atime: yes
  • mtime: yes
  • ctime: yes
  • isFile(): yes
  • isDirectory(): yes
  • isBlockDevice(): no
  • isCharacterDevice(): no
  • isSymbolicLink(): yes
  • isFIFO(): no
  • isSocket(): no

Tests

$ npm test

Changelog

  • 1.2.0 - 1.2.1

    • Move repository under Carrooi organization
    • Abandon project
    • Rewritten to pure javascript
    • Rebind all methods so they can be called event when they are unbound #11
    • Updated dependencies
    • Fixed root directories #15
    • Added some tests
    • Some fixes for Windows
    • Fixed paths with trailing slashes #13
    • Fixed lstat called on non symbolic links #14
    • Allow writing raw buffer #7
  • 1.1.3

    • Bug with createReadStream and createWriteStream not emitting 'open' event #10
  • 1.1.2

    • Bug with createWriteStream sending improper 'finish' event
  • 1.1.1

    • Setup coffee-script for development
    • createReadStream/createWriteStream send error events instead of exceptions
    • createReadStream could not use custom fd in options
  • 1.1.0

    • Added support for windows file systems
    • Added many tests
  • 1.0.1

    • Bug with root directories and readdir method
  • 1.0.0

    • First version