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

fs-sugar

v0.0.3

Published

fs-sugar(甜fs)封装了部分fs常用的方法,方便开发。

Downloads

15

Readme

node-fs-sugarBuild Status

fs-sugar(甜fs)封装了部分fs常用的方法,来方便开发。

Quick Examples

file

  • createFileSync(filePath) 如果目录不存在,会先创建目录。
var fs = require('fs'),
    sugar = require('fs-sugar');
var file = path.join('/a/b', 'aa.txt');
sugar.createFileSync(file);
assert.equal(fs.existsSync(file), true, 'createFilSyenc fail');
  • isFileSync(filePath) 判断是否为文件,如果不存在,直接抛出异常。
var sugar = require('fs-sugar');
assert.equal(sugar.isFileSync('/a/b'), false, 'isFileSync fail')
  • copyFileSync(srcFile, destDir) 将srcFile文件拷贝至destDir,如果destDir不存在会新建
var sugar = require('fs-sugar');
sugar.copyFileSync('/a/b/aa.txt','/c')

dir

  • isDirectorySync(dirPath) 判断是否为文件夹,如果不存在,直接抛出异常。
var sugar = require('fs-sugar');
assert.equal(sugar.isDirectorySync('/a/b'), true, 'isDirectorySync fail')
  • mkDir(dir/,mode/,cb) 创建多层目录
var path = require('path'),
    sugar = require('../lib/sugar');

var baseDir = path.join('/', 'testSugar' + new Date().getTime()),
    dir = path.join(baseDir, "a/b/c/d/e");
sugar.mkDir(dir, '0755', function (err, dir) {
    console.log(err);
    console.log(dir);
});

sugar.mkDir(dir, function (err, dir) {
    console.log(err);
    console.log(dir);
});
  • mkDirSync(dir/,mode/) 创建多层目录,类似mkdir -p /a/b/c
var sugar = require('fs-sugar');
sugar.mkdirSync('/a/b/c');

sugar.mkdirSync('/a/b/c','0755');
  • rmrDirSync(dir) 直接删除目录,类似rm -rf /a/b
var sugar = require('fs-sugar');
sugar.rmrDirSync('/a/b');
  • listSync(dir) 列出文件夹下面所有文件
var sugar = require('fs-sugar');
var fileNameArray = sugar.listSync(dir);
  • listFilterSync(dir,filter) 按照制定的条件列出子文件、目录
var sugar = require('fs-sugar');
var fileNameArray = sugar.listFilter('/a/b/c',function(fileName,fileStat){
    console.log(fileName);
    console.log(JSON.stringify(fileStat));
    if (fileStat.isFile()) {
        return true;
    } else {
        return false;
    }
});
  • copyDirSync(source, dest) 将source文件夹拷贝成destDir文件夹,类似cp /a/b /c
var sugar = require('fs-sugar');
sugar.copyDirSync('/a/b', '/c');
  • copyDirFilterSync(source, dest, filter) 将source文件夹拷贝成destDir文件夹,其中可以用filter过滤不需要拷贝文件
var sugar = require('fs-sugar');
sugar.copyDirFilterSync('/a/b', '/c', function (fileName, fileStat) {
    console.log(fileName);
    console.log(JSON.stringify(fileStat));
    if (fileStat.isFile()) {
        return true;
    } else {
        return false;
    }
});

TODO

  1. 异步