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

fsxu

v0.2.2

Published

minimal filesystem utility functions inspired by fs-extra

Downloads

14

Readme

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 = require('fsxu');

fsxu.listDirSync('my/path'); //['my/path/file.json', 'my/path/dir01']

fsxu.listDirSync('path/does/not/exist'); //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 = require('fsxu');

fsxu.makeDirSync('create/deep/nested/path'); //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 = require('fsxu');

//get project root directory
var rootDir = fsxu.findUpSync('package.json'); // '/Users/psxcode/dev/my-proj'

var filepath = fsxu.findUpSync('config.json', 'search/from/here'); // '/Users/psxcode/dev/my-proj/search'

###isFileSync(filepath) isFileSync returns true if path provided is a file

var fsxu = require('fsxu');

//check if file exists
fsxu.isFileSync('path/to/my/file.json')); //true //file exists

//get only files listed in directory
var files = fsxu.listDirSync('path/to/my/files').filter(fsxu.isFileSync);

###isDirSync(path) isDirSync returns true if path provided is a directory

var fsxu = require('fsxu');

//check if directory exists
fsxu.isDirSync('path/to/my/dir')); // true //directory exists 

//get only directories listed in directory
var files = fsxu.listDirSync('path/to/my/dir').filter(fsxu.isDirSync);

###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 = require('fsxu');

fsxu.emptyDirSync('relative-path-to-my-dir'); //true

fsxu.emptyDirSync('/absolute/path/to/my/dir'); //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 = require('fsxu');

//try to remove
fsxu.rmDirSync('path/to/my/dir'); // false //directory is not empty

//use recursive option
fsxu.rmDirSync('path/to/my/dir', true); //true //now removed 

###rmFileSync(pathname) rmFileSync removes file. Returns true if file does not exist or if removal was successfull.

var fsxu = require('fsxu');

//try to remove
fsxu.rmFileSync('path/to/my/file.json'); // true //file removed

//ensure removed
fsxu.rmFileSync('path/to/my/file.json'); //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 = require('fsxu');

//try to remove
fsxu.rmSync('path/to/my/file.json'); // true //file removed

//ensure removed
fsxu.rmSync('path', true); //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 = require('fsxu');

var jsonObj = fsxu.readJsonSync('path/to/file.json');
if(jsonObj) {
  //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 = require('fsxu');

var jsonObj = {
  name: 'alex',
  hobby: 'javascript'
};

fsxu.writeJsonSync('path/to/file.json', jsonObj); //true