fs-plusplus
v1.0.1
Published
Simple file system extensions for node
Downloads
2
Maintainers
Readme
fs-plusplus
Simple file system extensions for node.
Install
npm i fs-plusplus
Usage
See the tests!
File
Directory Parser
File
const fs = require('fs-plusplus');
// Load a File that exists
const file = new fs.File('./foo/bar/hello.txt');
// or if the file doesn't exist yet we set the canCreate flag to true
const file = new fs.File('./foo/bar/hello.txt', true);
console.log(file.name); // 'hello.txt'
console.log(file.extension); // '.txt'
console.log(file.fullPath); // './foo/bar/hello.txt'
// Get the file content (lazy loaded)
console.log(file.content);
// Replace some stuff
file.replaceContent(/private/g, 'public') // makes private stuff public
// Save
file.save();
// or
file.saveAs('./newFileName.txt');
DirectoryParser
const fs = require('fs-plusplus');
// Make a directory parser
const dp = new fs.DirectoryParser();
// Parse recursively to get the files in the directory './foo'
const files = dp.parse('./foo');
// files is an array of files...
// Each file has a name, extension and full path
// e.g.
console.log(files[0].name); // 'hello.txt'
console.log(files[0].extension); // '.txt'
console.log(files[0].fullPath); // './foo/bar/hello.txt'
We can restrict to certain file types
const files = dp.parse('./foo', ['.cs', '.cpp']); // just .cs and .cpp files
We can exclude results based on keywords (case insensitive)
const files = dp.parse('./foo', undefined, ['bin', 'debug']); // ignore files with paths containing 'bin' or 'debug'
Or do a mixture
const files = dp.parse('./foo', ['.cs'], ['bin', 'debug']);