# Glob
Match files using the patterns the shell uses.
The most correct and second fastest glob implementation in
JavaScript. (See **Comparison to Other JavaScript Glob
Implementations** at the bottom of this readme.)
![a fun cartoon logo made of glob characters](https://github.com/isaacs/node-glob/raw/main/logo/glob.png)
## Usage
Install with npm
```
npm i glob
```
**Note** the npm package name is _not_ `node-glob` that's a
different thing that was abandoned years ago. Just `glob`.
```js
// load using import
import { glob, globSync, globStream, globStreamSync, Glob } from 'glob'
// or using commonjs, that's fine, too
const {
glob,
globSync,
globStream,
globStreamSync,
Glob,
} = require('glob')
// the main glob() and globSync() resolve/return array of filenames
// all js files, but don't look in node_modules
const jsfiles = await glob('**/*.js', { ignore: 'node_modules/**' })
// pass in a signal to cancel the glob walk
const stopAfter100ms = await glob('**/*.css', {
signal: AbortSignal.timeout(100),
})
// multiple patterns supported as well
const images = await glob(['css/*.{png,jpeg}', 'public/*.{png,jpeg}'])
// but of course you can do that with the glob pattern also
// the sync function is the same, just returns a string[] instead
// of Promise<string[]>
const imagesAlt = globSync('{css,public}/*.{png,jpeg}')
// you can also stream them, this is a Minipass stream
const filesStream = globStream(['**/*.dat', 'logs/**/*.log'])
// construct a Glob object if you wanna do it that way, which
// allows for much faster walks if you have to look in the same
// folder multiple times.
const g = new Glob('**/foo')
// glob objects are async iterators, can also do globIterate() or
// g.iterate(), same deal
for await (const file of g) {
console.log('found a foo file:', file)
}
// pass a glob as the glob options to reuse its settings and caches
const g2 = new Glob('**/bar', g)
// sync iteration works as well
for (const file of g2) {
console.log('found a bar file:', file)
}
// you can also pass withFileTypes: true to get Path objects
// these are like a Dirent, but with some more added powers
// check out http://npm.im/path-scurry for more info on their API
const g3 = new Glob('**/baz/**', { withFileTypes: true })
g3.stream().on('data', path => {
console.log(
'got a path object',
path.fullpath(),
path.isDirectory(),
path.readdirSync().map(e => e.name)
)
})
// if you use stat:true and withFileTypes, you can sort results
// by things like modified time, filter by permission mode, etc.
// All Stats fields will be available in that case. Slightly
// slower, though.
// For example:
const results = await glob('**', { stat: true, withFileTypes: true })
const timeSortedFiles = results
.sort((a, b) => a.mtimeMS - b.mtimeMS)
.map(path => path.fullpath())
const groupReadableFiles = results
.filter(path => path.mode & 0o040)
.map(path => path.fullpath())
// custom ignores can be done like this, for example by saying
// you'll ignore all markdown files, and all folders named 'docs'
const customIgnoreResults = await glob('**', {
ignore: {
ignored: p => /\.md$/.test(p.name),
childrenIgnored: p => p.isNamed('docs'),
},
})
// another fun use case, only return files with the same name as
// their parent folder, plus either `.ts` or `.js`
const folderNamedModules = await glob('**/*.{ts,js}', {
ignore: {
ignored: p => {
const pp = p.parent
return !(p.isNamed(pp.name + '.ts') || p.isNamed(pp.name + '.js'))
},
},
})
// find all files edited in the last hour, to do this, we ignore
// all of them that are more than an hour old
const newFiles = await glob('**', {
// need stat so we have mtime
stat: true,
// only want the files, not the dirs
nodir: true,
ignore: {
ignored: p => {
return new Date() - p.mtime > 60 * 60 * 1000
},
// could add similar childrenIgnored here as well, but
// directory mtime is inconsistent across platforms, so
// probably better not to, unless you know the system
// tracks this reliably.
},
})
```
**Note** Glob patterns should always use `/` as a path separator,
even on Windows systems, as `\` is used to escape glob
characters. If you wish to use `\` as a path separator _instead
of_ using it as an escape character on Windows platforms, you may
set `windowsPathsNoEscape:true` in the options. In this mode,
special glob characters cannot be escaped, making it impossible
to match a literal `*` `?` and so on in filenames.
## Command Line Interface
```
$ glob -h
Usage:
glob [options] [<pattern> [<pattern> ...]]
Expand the positional glob expression arguments into any matching file system
paths found.
-c<command> --cmd=<command>
Run the command provided, passing the glob expression
matches as arguments.
-A --all By default, the glob cli command will not expand any
arguments that are an exact match to a file on disk.
This prevents double-expanding, in case the shell
expands an argument whose filename is a glob
expression.
For example, if 'app/*.ts' would match 'app/[id].ts',
then on Windows powershell or cmd.exe, 'glob app/*.ts'
will expand to 'app/[id].ts', as expected. However, in
posix shells such as bash or zsh, the shell will first
expand 'app/*.ts' to a list of filenames. Then glob
will look for a file matching 'app/[id].ts' (ie,
'app/i.ts' or 'app/d.ts'), which is unexpected.
Setting '--all' prevents this behavior, causing glob to
treat ALL patterns as glob expressions to be expanded,
even if they are an exact match to a file on disk.
When setting this option, be sure to enquote arguments
so that the shell will not expand them prior to passing
them to the glob command process.
-a --absolute Expand to absolute paths
-d --dot-relative Prepend './' on relative matches
-m --mark Append a / on any directories matched
-x --posix Always resolve to posix style paths, using '/' as the
directory separator, even on Windows. Drive letter
absolute matches on Windows will be expanded to their
full resolved UNC maths, eg instead of 'C:\foo\bar', it
will expand to '//?/C:/foo/bar'.
-f --follow Follow symlinked directories when expanding '**'
-R --realpath Call 'fs.realpath' on all of the results. In the case
of an entry that cannot be resolved, the entry is
omitted. This incurs a slight performance penalty, of
course, because of the added system calls.
-s --stat Call 'fs.lstat' on all entries, whether required or not
to determine if it's a valid match.
-b --match-base Perform a basename-only match if the pattern does not
contain any slash characters. That is, '*.js' would be
treated as equivalent to '**/*.js', matching js files
in all directories.
--dot Allow patterns to match files/directories that start
with '.', even if the pattern does not start with '.'
--nobrace Do not expand {...} patterns
--nocase
没有合适的资源?快使用搜索试试~ 我知道了~
node-v20.3.1-win-x86.zip
共2000个文件
js:1205个
json:300个
md:189个
0 下载量 167 浏览量
2024-04-16
12:07:26
上传
评论
收藏 26.25MB ZIP 举报
温馨提示
Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。
资源推荐
资源详情
资源评论
收起资源包目录
node-v20.3.1-win-x86.zip (2000个子文件)
cssesc.1 2KB
AUTHORS 207B
win_delay_load_hook.cc 911B
corepack.cjs 1.52MB
index.cjs 10KB
index.cjs 6KB
npx.cmd 539B
corepack.cmd 218B
yarnpkg.cmd 216B
yarn.cmd 210B
pnpx.cmd 210B
pnpm.cmd 210B
npx.cmd 208B
npm.cmd 208B
corepack.cmd 180B
yarnpkg.cmd 178B
yarn.cmd 172B
pnpx.cmd 172B
pnpm.cmd 172B
npx.cmd 170B
npm.cmd 170B
corepack 334B
corepack 284B
Find-VisualStudio.cs 8KB
cssesc 3KB
index.d.cts 1KB
completion.fish 2KB
.flake8 125B
equation.gif 1KB
config.html 73KB
package-json.html 44KB
npm-install.html 34KB
scripts.html 23KB
npm-audit.html 23KB
npm-update.html 20KB
npm-link.html 19KB
npm-exec.html 19KB
dependency-selectors.html 18KB
npm-ci.html 16KB
package-lock-json.html 16KB
npm-init.html 16KB
npm-install-test.html 16KB
npm-dedupe.html 15KB
npm-ls.html 15KB
npm-diff.html 15KB
developers.html 15KB
folders.html 14KB
npm-install-ci-test.html 14KB
npm-run-script.html 14KB
npm-publish.html 14KB
npm-pkg.html 13KB
npm-version.html 13KB
npm-find-dupes.html 13KB
workspaces.html 12KB
npm-outdated.html 11KB
npm.html 11KB
npm-prune.html 11KB
npx.html 11KB
npm-view.html 11KB
npm-dist-tag.html 11KB
scope.html 11KB
npm-doctor.html 10KB
npm-query.html 10KB
npm-config.html 10KB
npm-rebuild.html 10KB
npm-uninstall.html 9KB
npm-unpublish.html 9KB
logging.html 9KB
npm-team.html 9KB
npmrc.html 9KB
npm-token.html 9KB
npm-search.html 9KB
npm-profile.html 9KB
registry.html 9KB
npm-pack.html 9KB
npm-access.html 9KB
npm-fund.html 8KB
npm-bugs.html 8KB
npm-docs.html 8KB
package-spec.html 8KB
npm-owner.html 8KB
npm-cache.html 8KB
install.html 8KB
npm-repo.html 8KB
npm-explain.html 7KB
orgs.html 7KB
npm-hook.html 7KB
npm-login.html 7KB
npm-org.html 7KB
npm-adduser.html 6KB
npm-star.html 6KB
npm-start.html 6KB
npm-unstar.html 6KB
npm-deprecate.html 6KB
npm-logout.html 6KB
npm-restart.html 6KB
npm-stop.html 6KB
removal.html 6KB
npm-test.html 6KB
npm-prefix.html 6KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
程序员Chino的日记
- 粉丝: 3718
- 资源: 5万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- java项目,毕业设计-家具商城系统
- sparse-occ-cpu.onnx
- c2532703d1b4e83f570f28ff6cf94aef_语法.pdf
- C# 将不限数量的Excel表格进行合并,支持多文件多表合并.zip
- java项目,毕业设计-体育场馆运营
- 阿里云联合中国信通院安全所发布-大模型安全研究报告2024
- 低空经济政策与产业生态研究报告(2024年)
- 基于微信小程序的手机商城的设计与实现ssm.zip
- 基于springboot汽车维修管理系统微信小程序springboot.zip
- 非常好用 的一款,网卡流量监控工具,可长时间 监控,有图标展示流量趋势,要记录一段时间 内的平均 流量,可单独记录每个网卡的流量, 绿色好用, 无功能 限制
- 基于微信小程序的医院挂号预约系统ssm.zip
- 基于机器学习的商品评论分析系统源代码+文档说明+GUI界面(高分项目)
- 基于微信小程序的校园二手交易平台ssm.zip
- 基于微信小程序的校园综合服务平台ssm.zip
- 基于微信小程序高校订餐系统的设计与开发ssm.zip
- 线性回归实现股票预测源代码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功