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-handler

v0.1.2

Published

Handle file system by Node

Downloads

13

Readme

fs-handler

使用 Node 来操作文件系统(file system)的一些工具集。

1. API

1.1 util

1.1.1 util.isDirectory(paths)

/**
 * 当前路径是否为目录
 * @param {String} paths 路径
 * @return {Boolean}
 */

1.1.2 util.isFile(paths)

/**
 * 当前路径是否为文件
 * @param {String} paths 路径
 * @return {Boolean}
 */

1.2 search

1.2.1 search.getAll(paths, options)

/**
 * 获得某路径下所有的文件和文件夹。
 *
 * https://www.npmjs.com/package/walk-sync
 *
 * @param {String} paths 路径
 * @param {Object} [options] 额外选项
 * @param {Array} [options.globs] An array of globs. Only files and directories that match at least one of the provided globs will be returned.
 * @param {Boolean} [options.directories ]  (default: true): Pass false to only return files, not directories
 * @param {Array} [options.ignore] An array of globs. Files and directories that match at least one of the provided globs will be pruned while searching.
 *
 * @return {Array} 结果,每个数组的元素为FileItem。
 */

1.2.2 search.getAllFiles(paths)

/**
 * 获得某个路径下的所有文件,不包含文件夹。
 * 返回一个数组,每个数组元素参考 [walk-sync](https://www.npmjs.com/package/walk-sync) 。
 *
 * @param {String} paths 路径
 * @return {Array}
 */

1.3 handle

1.3.1 handle.saveModule(savePath, modulePath)

/**
 * 获取模块文件的执行结果,并将结果保存在相应的路径下
 *
 * @param {String} savePath 保存路径
 * @param {String} modulePath 模块文件的路径
 * @return {Promise}
 */

1.3.2 handle.saveJSON(savePath, data)

/**
 * 将 JSON 格式的对象保存为json文件。
 *
 * @param {String} savePath 保存路径
 * @param {Object} data 对象,plain object
 * @return {Promise}
 */

1.3.3 handle.getModuleResult(filePath, ...props)

/**
 * 通过模块的路径,获取模块的执行结果
 * 如果 `filePath` 对应的模块返回一个函数,则 `...props` 将作为该函数的参数传递进去
 *
 * @param {String} filePath 文件路径
 * @return {Promise}
 */

1.3.4 handle.getTargetResult(filePath, ...props)

/**
 * 获得模块内容之后,计算出最终返回值
 * 如果 `saveTarget` 是一个函数,则 `...props` 将作为该函数的参数传递进去
 *
 * @param {*} saveTarget 有可能是函数、对象或者普通字符串
 * @return {Promise}
 */

1.4 filter

1.4.1 filter.filterModuleInFolder(folderPath, filterFunc, callback)

/**
 * 过滤出某个文件夹下的指定模块
 *
 * @param {String} folderPath 文件夹路径
 * @param {Function} filterFunc 过滤函数,接受一个参数data(模块数据),如果返回 true,则为找到了
 * @param {Function} callback 回调,如果成功,则会返回两个参数:item(文件对象)和data(模块数据)
 */