Is a library that promisifies the native node FS operation and brings extras into the mix. Fsep has No Dependency.
- Native node.js Fs methods (promisified)
- Only Promises
- copy
- ensureLink
- move
- outputJson
- readJson
- remove
- writeJson
-
walk
-
exist
-
mkdirs
-
emptyFolder
-
outputFile
-
outputFolder
-
ensureFile
-
ensureFolder
-
ensureSymlink
-
scaffold
-
readFiles
-
readWriteLine
-
readFolder
-
removeFile
-
removeFolder
-
writeFolder
options: Object
path: String
Path to directoryfilters: Array
RegExp stringsrelative: Boolean
Return paths relative or absolute. Default isfalse
ignoreDot: Boolean
Ignores files beginning with a dot. Default istrue
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);
});
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);
});
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);
});
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);
});
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);
});
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);
});
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);
});
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);
});
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);
});
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);
});
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);
});
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);
});
Alias for Fs.readdir
.
Alias for Fs.unlink
.
Alias for Fs.rmdir
.
Alias for Fs.mkdir
.
Why You Should Choose MPL-2.0 This project is licensed under the MPL-2.0 License