Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glob #156

Open
magicdawn opened this issue Mar 20, 2023 · 2 comments
Open

glob #156

magicdawn opened this issue Mar 20, 2023 · 2 comments

Comments

@magicdawn
Copy link
Owner

No description provided.

@magicdawn
Copy link
Owner Author

magicdawn commented Mar 20, 2023

fast-glob

依赖链

从上至下

  • globby
  • fast-glob
  • micromatch
  • micromatch/picomatch & micromatch/braces

所有有的文档指向 picomatch, 有的指向 micromatch

基础语法

  • * 匹配所有(除了 / 和开头的点号 aka 隐藏文件)
  • ? 匹配一个字符
  • [seq] 匹配 s or e or q, 这里应该和 regexp character classes 重复

高级语法

  • \\ escape
  • [:digit] 不如 [0-9] 来的实在
  • extglob
  • brace {}
  • regexp character classes [ac] / [b-d] / [A-Z].js

extglob

https://github.com/micromatch/micromatch#extglobs

注意和 regex 语法不同, ? / * /+ 在 pattern 前面

braces

https://github.com/micromatch/braces

这个也很复杂, 简单来说

  • {abc,def} 逗号分割 sequence
  • {01..03} 序列, 还支持步长...至今没用到过
  • 支持嵌套

regexp character classes

[0-9]+

regexp groups

fast-glob 没提到, 但是 micromatch 提到了

(a|c).js => a.js or c.js
  • 可以嵌套, 同 braces

@magicdawn
Copy link
Owner Author

magicdawn commented Oct 25, 2023

micromatch API

import mm from 'micromatch'

mm()

这个 API 对标 fast-glob, 举例来说

list = [' av1234 .mp4', ' BV1234 .mp4', ' BV1234 - P2 - .mp4']

patterns = [
    '**/* av+([0-9]) *.mp4',
    '**/* BV+([\\w]) *.mp4',
    '!**/* - P{2..99} - *.mp4',
]
mm(list, patterns)
// => [ ' av1234 .mp4', ' BV1234 .mp4' ]

mm.isMatch

> mm.isMatch(list[0], patterns)
true
> mm.isMatch(list[1], patterns)
true
> mm.isMatch(list[2], patterns)
true

isMatch

Returns true if any of the given glob patterns match the specified string.

任意的 pattern 匹配 str 即为 true,

mm.all

Returns true if all of the given patterns match the specified string.

micromatch/micromatch#9 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant