“NPM那些库” 是系列文章,每篇介绍几个 Node 环境中常用的库,目的是:总结、记录、分享。
1. rimraf
rimraf 是 Linux 命令 rm -rf 的 node 版本。就是用来删除目录、删除文件的。
安装:
npm install --save rimraf
示例:
2. chalk
chalk(粉笔),顾名思义,它可以控制输出到 console 中文字的样式。
安装:
npm install --save chalk
示例:
3. glob
3.1. 什么是 glob 模式?
In computer programming, glob patterns specify sets of filenames with wildcard characters.
mv *.txt textfiles/ moves
moves (mv) all files with names ending in .txt from the current directory to the directory textfiles.
—— 来源于 Wiki
3.2. glob 的起源?
The command interpreters of the early versions of Unix relied on a separate program to expand wildcard characters in unquoted arguments to a command: /etc/glob. That program performed the expansion and supplied the expanded list of file paths to the command for execution. Its name is an abbreviation for "global command". Later, this functionality was provided as a library function, glob(), used by programs such as the shell.
—— 来源于 Wiki
下面要介绍的就是 Node 环境中的 glob 库,它可以让我们使用通配符去搜索文件;
安装:
npm install --save glob
示例:
4. globby
globby 是 glob 的增强版本!
图:globby 的增强特性;
安装:
npm install --save glob
示例:
参考:
rimraf项目地址:https://github.com/isaacs/rimraf chalk项目地址:https://github.com/chalk/chalk glob项目地址:https://github.com/isaacs/node-glob globby项目地址:https://github.com/sindresorhus/globby