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

fsep

v3.0.1

Published

Fsep is a library that promisifies the native node FS operation and brings extras into the mix.

Downloads

28

Readme

FSEP

Is a library that promisifies the native node FS operation and brings extras into the mix. Fsep has No Dependency.

Features

  • Native node.js Fs methods (promisified)
  • Only Promises

TODO

  • copy
  • ensureLink
  • move
  • outputJson
  • readJson
  • remove
  • writeJson

API

  • walk

  • exist

  • mkdirs

  • emptyFolder

  • outputFile

  • outputFolder

  • ensureFile

  • ensureFolder

  • ensureSymlink

  • scaffold

  • readFiles

  • readWriteLine

  • readFolder

  • removeFile

  • removeFolder

  • writeFolder

walk(path, [options])

  • options: Object
    • path: String Path to directory
    • filters: Array RegExp strings
    • relative: Boolean Return paths relative or absolute. Default is false
    • ignoreDot: Boolean Ignores files beginning with a dot. Default is true
const Fsep = require('fsep');
const path = '/home/user/directory';
const options = {
	relative: false,
	ignoreDot: true,
	filters: ['.DS_Store']
};

Fsep.walk(path, options).then(function (files) {
	console.log(files);
}).catch(function (error) {
	console.error(error);
});

exist(path)

Checks if a path exists. Returns true or false. Uses Fs.stat.

const Fsep = require('fsep');

Fsep.exist(path).then(function (exist) {
	console.log(exist); // true || false
}).catch(function (error) {
	console.error(error);
});

mkdirs(path [,mode])

Creates the path folders if they do not exist. Accepts a mode parameter.

const Fsep = require('fsep');
const path = '/non/existing/dir';

Fsep.mkdirs(path).then(function () {
	console.log('done');
}).catch(function (error) {
	console.error(error);
});

outputFile(path, data, [options])

Creates a file and also directories if non existent. Overwrites file if it exists.

const Fsep = require('fsep');

var path = '/non/existing/path/file.js';
var data = 'hello';

Fsep.outputFile(path, data).then(function () {
	console.log('done');
}).catch(function (error) {
	console.error(error);
});

outputFolder(path [,mode, cwd])

Creates folders in path if they do not exist.

const Fsep = require('fsep');
const path = '/non/existing/dir';

Fsep.outputFolder(path).then(function () {
	console.log('done');
}).catch(function (error) {
	console.error(error);
});

ensureFolder(path, [,mode, cwd])

Creates folders in path if they do not exist.

const Fsep = require('fsep');
const path = '/non/existing/dir';

Fsep.ensureFolder(path).then(function () {
	console.log('done');
}).catch(function (error) {
	console.error(error);
});

ensureFile(path, data, [options], [mode || cwd])

Ensures that the file and its directory structure exists. If the file already exists it is not modified.

const Fsep = require('fsep');

var path = '/non/existing/dirs/and/file.txt';

Fsep.ensureFile(path).then(function () {
	console.log('done');
}).catch(function (error) {
	console.error(error);
});

ensureSymlink(source, target, type, [mode || cwd])

Ensures that the symlink and its directory structure exists. If the file already exists it is not modified.

const Fsep = require('fsep');
const src = '/existing/folders/file.txt';
const dst = '/non/existing/folders/file.txt';

Fsep.ensureSymlink(source, target).then(function () {
	console.log('symlink created');
}).catch(function (error) {
	console.error(error);
});

emptyFolder(path, safe)

Deletes the contents of a directory if it exists and is not empty. This is recursive so be careful. Same as rm -r.

  • path: String Path to the direcotry to empty.
  • safe: Boolean Default is true which throws an error if you try to empty the root of the file system.
const Fsep = require('fsep');

var path = '/home/username/dirs'; // contains folders and files

Fsep.emptyFolder(path).then(function () {
	console.log('done');
}).catch(function (error) {
	console.error(error);
});

scaffold(path, data)

Requires a path and an object or array. Makes files and folders based on object or array. End points are assumed to be file names.

const Fsep = require('fsep');

const data = {
	one: 'one.txt',
	two: 'two.txt',
	array: [
		'three.txt',
		'four.txt'
	]
};

Fsep.scaffold(path, data).then(function () {
	console.log('done');
	/* output
		one
			one.txt
		two
			two.txt
		array
			three.txt
			four.txt
	*/
}).catch(function (error) {
	console.error(error);
});

readFiles(paths, options)

Reads an array of files asynchronously. The result is an array of files.

const Fsep = require('fsep');

var paths = [
	'/one.txt',
	'two.txt'
];

Fsep.readFiles(paths).then(function (files) {
	console.log(files);
}).catch(function (error) {
	console.error(error);
});

readWriteLine(options)

Reads and writes a file line by line. The line function allows line manipulation.

const Fsep = require('fsep');

var options = {
	read: { // node stream options
		path: './rw/one.txt'
	},
	write: { // node stream options
		path: './rw/two.txt',
		flags: 'a'

	},
	line: function (line) {
		return line.toUpperCase();
	}
};

Fsep.readWriteLine(options).then(function () {
	console.log('done');
}).catch(function (error) {
	console.error(error);
});

readFolder

Alias for Fs.readdir.

removeFile

Alias for Fs.unlink.

removeFolder

Alias for Fs.rmdir.

writeFolder

Alias for Fs.mkdir.

Authors

AlexanderElias

License

Why You Should Choose MPL-2.0 This project is licensed under the MPL-2.0 License