node-fsxu
fsxu
is minimal set of filesystem utility functions inspired by fs-extra
Installation
npm install --save fsxu
Usage
listDirSync(path)
listDirSync
works like readdirSync
function, but returns path+name array instead just names. So you can work with files without joining path. Returns null
var fsxu = ; fsxu; //['my/path/file.json', 'my/path/dir01'] fsxu; //null
makeDirSync(path)
makeDirSync
works like mkdir -p
command. It recursively creates directories. Works with absolute and relative paths. Returns true
if everything was ok.
var fsxu = ; fsxu; //true
findUpSync(name[, path])
findUpSync
searches for file or directory starting from path or __dirname
, and going up, until it reaches filesystem root. Once found, the absolute path is returned, otherwise null
.
var fsxu = ; //get project root directoryvar rootDir = fsxu; // '/Users/psxcode/dev/my-proj' var filepath = fsxu; // '/Users/psxcode/dev/my-proj/search'
isFileSync(filepath)
isFileSync
returns true
if path provided is a file
var fsxu = ; //check if file existsfsxu); //true //file exists //get only files listed in directoryvar files = fsxu;
isDirSync(path)
isDirSync
returns true
if path provided is a directory
var fsxu = ; //check if directory existsfsxu); // true //directory exists //get only directories listed in directoryvar files = fsxu;
emptyDirSync(path)
emptyDirSync
ensures that a directory is empty. Deletes directory contents if the directory is not empty. If the directory does not exist, it is created. The directory itself is not deleted. Returns true
if everything was ok.
var fsxu = ; fsxu; //true fsxu; //true
rmDirSync(path[, recursive])
rmDirSync
removes directory. If recursive
is set to true
recursively removes all content, and then the directory. Returns true
if directory does not exist or if removal was successfull.
var fsxu = ; //try to removefsxu; // false //directory is not empty //use recursive optionfsxu; //true //now removed
rmFileSync(pathname)
rmFileSync
removes file. Returns true
if file does not exist or if removal was successfull.
var fsxu = ; //try to removefsxu; // true //file removed //ensure removedfsxu; //true //does not exist
rmSync(pathname[, recursive])
rmSync
removes file or directory. If target is directory and recursive
is set to true
recursively removes all content, and then the directory. Returns true
if target does not exist or if removal was successfull.
var fsxu = ; //try to removefsxu; // true //file removed //ensure removedfsxu; //true //recursively removes everything in 'path' and the 'path' itself.
readJsonSync(filepath)
readJsonSync
returns parsed JSON content. Returns null
if something was wrong.
var fsxu = ; var jsonObj = fsxu;ifjsonObj //use the object
writeJsonSync(filepath, object)
writeJsonSync
stringifies object
and writes it to .json
file. If the directory does not exist, it is created. Returns true
if write was successfull.
var fsxu = ; var jsonObj = name: 'alex' hobby: 'javascript'; fsxu; //true