"Globs" là các mẫu bạn nhập khi bạn thực hiện những việc như ls *.js
trên dòng lệnh hoặc đặt _______ 149 _______ trong tệp .gitignore
Trước khi phân tích các mẫu phần đường dẫn, các phần có dấu ngoặc nhọn được mở rộng thành một tập hợp. Các phần có dấu ngoặc bắt đầu bằng {
và kết thúc bằng
var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]0, với bất kỳ số lượng phần nào được phân cách bằng dấu phẩy trong. Các phần được giằng có thể chứa các ký tự gạch chéo, do đó,
var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]1 sẽ mở rộng thành
var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]2 và
var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]3
Các ký tự sau có ý nghĩa kỳ diệu đặc biệt khi được sử dụng trong phần đường dẫn
var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
4 So khớp 0 ký tự trở lên trong một phần đường dẫn đơnvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
5 Khớp với 1 ký tựvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
6 So khớp một phạm vi ký tự, tương tự như phạm vi RegExp. Nếu ký tự đầu tiên của phạm vi làvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
7 hoặcvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
8 thì nó khớp với bất kỳ ký tự nào không có trong phạm vivar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
9 Khớp với bất kỳ mẫu nào không khớp với bất kỳ mẫu nào được cung cấp
0 Không khớp hoặc một lần xuất hiện của các mẫu được cung cấp$ echo a*s*d*f a*s*d*f
1 Khớp một hoặc nhiều lần xuất hiện của các mẫu được cung cấp$ echo a*s*d*f a*s*d*f
2 Không khớp hoặc nhiều lần xuất hiện hơn của các mẫu được cung cấp$ echo a*s*d*f a*s*d*f
3 Khớp chính xác một trong các mẫu được cung cấp$ echo a*s*d*f a*s*d*f
4 Nếu một "globstar" ở một mình trong phần đường dẫn, thì nó khớp với 0 hoặc nhiều thư mục và thư mục con đang tìm kiếm kết quả khớp. Nó không thu thập dữ liệu các thư mục được liên kết tượng trưng$ echo a*s*d*f a*s*d*f
dấu chấm
Nếu một phần đường dẫn tệp hoặc thư mục có
$ echo a*s*d*f
a*s*d*f
5 làm ký tự đầu tiên, thì nó sẽ không khớp với bất kỳ mẫu hình cầu nào trừ khi phần đường dẫn tương ứng của mẫu đó cũng có một $ echo a*s*d*f
a*s*d*f
5 làm ký tự đầu tiênVí dụ: mẫu
$ echo a*s*d*f
a*s*d*f
7 sẽ khớp với tệp tại $ echo a*s*d*f
a*s*d*f
8. Tuy nhiên, mẫu $ echo a*s*d*f
a*s*d*f
9 sẽ không, vì var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]4 không bắt đầu bằng ký tự dấu chấm
Bạn có thể biến toàn cầu coi các dấu chấm là các ký tự bình thường bằng cách đặt
var Glob = require["glob"].Glob var mg = new Glob[pattern, options, cb]1 trong các tùy chọn
Kết hợp tên cơ sở
Nếu bạn đặt
var Glob = require["glob"].Glob var mg = new Glob[pattern, options, cb]2 trong các tùy chọn và mẫu không có dấu gạch chéo trong đó, thì nó sẽ tìm kiếm bất kỳ tệp nào ở bất kỳ đâu trong cây có tên cơ sở phù hợp. Ví dụ:
var Glob = require["glob"].Glob var mg = new Glob[pattern, options, cb]3 sẽ khớp với
var Glob = require["glob"].Glob var mg = new Glob[pattern, options, cb]4
Bộ trống
Nếu không tìm thấy tệp phù hợp, thì một mảng trống sẽ được trả về. Điều này khác với trình bao, trong đó bản thân mẫu được trả về. Ví dụ
$ echo a*s*d*f
a*s*d*f
Để có hành vi kiểu bash, hãy đặt
var Glob = require["glob"].Glob var mg = new Glob[pattern, options, cb]5 trong các tùy chọn
Xem thêm
var Glob = require["glob"].Glob var mg = new Glob[pattern, options, cb]
6var Glob = require["glob"].Glob var mg = new Glob[pattern, options, cb]
7 [Tìm kiếm "So khớp mẫu"]var Glob = require["glob"].Glob var mg = new Glob[pattern, options, cb]
8var Glob = require["glob"].Glob var mg = new Glob[pattern, options, cb]
9- tài liệu đối sánh nhỏ
quả địa cầu. hasMagic[mẫu, [tùy chọn]]
Trả về
# to run tests
npm test
# to re-generate test fixtures
npm run test-regen
# to benchmark against bash/zsh
npm run bench
# to profile javascript
npm run prof
0 nếu có bất kỳ ký tự đặc biệt nào trong mẫu và trả về # to run tests
npm test
# to re-generate test fixtures
npm run test-regen
# to benchmark against bash/zsh
npm run bench
# to profile javascript
npm run prof
1 nếu khôngLưu ý rằng các tùy chọn ảnh hưởng đến kết quả. Nếu
# to run tests
npm test
# to re-generate test fixtures
npm run test-regen
# to benchmark against bash/zsh
npm run bench
# to profile javascript
npm run prof
2 được đặt trong đối tượng tùy chọn, thì # to run tests
npm test
# to re-generate test fixtures
npm run test-regen
# to benchmark against bash/zsh
npm run bench
# to profile javascript
npm run prof
3 sẽ không được coi là một mẫu ma thuật. Nếu mẫu có một dấu ngoặc mở rộng, chẳng hạn như # to run tests
npm test
# to re-generate test fixtures
npm run test-regen
# to benchmark against bash/zsh
npm run bench
# to profile javascript
npm run prof
4 thì điều đó được coi là kỳ diệu, trừ khi # to run tests
npm test
# to re-generate test fixtures
npm run test-regen
# to benchmark against bash/zsh
npm run bench
# to profile javascript
npm run prof
5 được đặt trong các tùy chọntoàn cầu [mẫu, [tùy chọn], cb]
6# to run tests npm test # to re-generate test fixtures npm run test-regen # to benchmark against bash/zsh npm run bench # to profile javascript npm run prof
7 Mẫu được so khớp# to run tests npm test # to re-generate test fixtures npm run test-regen # to benchmark against bash/zsh npm run bench # to profile javascript npm run prof
8# to run tests npm test # to re-generate test fixtures npm run test-regen # to benchmark against bash/zsh npm run bench # to profile javascript npm run prof
9# to run tests npm test # to re-generate test fixtures npm run test-regen # to benchmark against bash/zsh npm run bench # to profile javascript npm run prof
minimatch
0minimatch
1minimatch
2minimatch
3minimatch
4minimatch
5 tên tệp được tìm thấy khớp với mẫu
Thực hiện tìm kiếm toàn cầu không đồng bộ
quả địa cầu. đồng bộ hóa [mẫu, [tùy chọn]]
6# to run tests npm test # to re-generate test fixtures npm run test-regen # to benchmark against bash/zsh npm run bench # to profile javascript npm run prof
7 Mẫu được so khớp# to run tests npm test # to re-generate test fixtures npm run test-regen # to benchmark against bash/zsh npm run bench # to profile javascript npm run prof
8# to run tests npm test # to re-generate test fixtures npm run test-regen # to benchmark against bash/zsh npm run bench # to profile javascript npm run prof
9# to run tests npm test # to re-generate test fixtures npm run test-regen # to benchmark against bash/zsh npm run bench # to profile javascript npm run prof
- trở lại.
minimatch
5 tên tệp được tìm thấy khớp với mẫu
Thực hiện tìm kiếm toàn cầu đồng bộ
Tầng lớp. quả địa cầu. quả địa cầu
Tạo một đối tượng Glob bằng cách khởi tạo lớp ls *.js
1
var Glob = require["glob"].Glob var mg = new Glob[pattern, options, cb]
Đó là một EventEmitter và bắt đầu đi bộ hệ thống tệp để tìm các kết quả phù hợp ngay lập tức
quả địa cầu mới. Toàn cầu[mẫu, [tùy chọn], [cb]]
- Mẫu
6# to run tests npm test # to re-generate test fixtures npm run test-regen # to benchmark against bash/zsh npm run bench # to profile javascript npm run prof
7 để tìm kiếm# to run tests npm test # to re-generate test fixtures npm run test-regen # to benchmark against bash/zsh npm run bench # to profile javascript npm run prof
8# to run tests npm test # to re-generate test fixtures npm run test-regen # to benchmark against bash/zsh npm run bench # to profile javascript npm run prof
9# to run tests npm test # to re-generate test fixtures npm run test-regen # to benchmark against bash/zsh npm run bench # to profile javascript npm run prof
minimatch
0minimatch
1 Được gọi khi xảy ra lỗi hoặc tìm thấy kết quả trùng khớpminimatch
2minimatch
3minimatch
4minimatch
5 tên tệp được tìm thấy khớp với mẫu
Lưu ý rằng nếu cờ build/*
2 được đặt trong các tùy chọn, thì thành viên build/*
3 sẽ có kết quả phù hợp ngay lập tức
Của cải
minimatch
Đối tượng minimatch mà toàn cầu sử dụng
8 Đối tượng tùy chọn được truyền vào# to run tests npm test # to re-generate test fixtures npm run test-regen # to benchmark against bash/zsh npm run bench # to profile javascript npm run prof
build/*
6 Boolean được đặt thành true khi gọibuild/*
7. Tại thời điểm này, không có cách nào để tiếp tục tìm kiếm toàn cầu sau khi hủy bỏ, nhưng bạn có thể sử dụng lại statCache để tránh phải lặp lại các tòa nhà chọc trờibuild/*
8 Đối tượng tiện lợi. Mỗi trường có các giá trị có thể sau
1 - Đường dẫn không tồn tại# to run tests npm test # to re-generate test fixtures npm run test-regen # to benchmark against bash/zsh npm run bench # to profile javascript npm run prof
0 - Đường dẫn tồn tại# to run tests npm test # to re-generate test fixtures npm run test-regen # to benchmark against bash/zsh npm run bench # to profile javascript npm run prof
.gitignore
1 - Đường dẫn tồn tại và không phải là thư mục.gitignore
2 - Đường dẫn tồn tại và là một thư mục.gitignore
3 - Đường dẫn tồn tại, là một thư mục và giá trị mảng là kết quả của.gitignore
4
.gitignore
5 Bộ nhớ cache của.gitignore
6 kết quả, để ngăn việc nhập cùng một đường dẫn nhiều lần.gitignore
7 Một bản ghi trong đó các đường dẫn là các liên kết tượng trưng, có liên quan đến việc giải quyết các mẫu
4$ echo a*s*d*f a*s*d*f
.gitignore
9 Một đối tượng tùy chọn được truyền cho{
0 để giảm thiểu các cuộc gọi tòa nhà không cần thiết. Nó được lưu trữ trên đối tượng Glob đã khởi tạo và có thể được sử dụng lại
Sự kiện
{
1 Khi quá trình khớp kết thúc, điều này được phát ra cùng với tất cả các kết quả phù hợp được tìm thấy. Nếu tùy chọn{
2 được đặt và không tìm thấy kết quả phù hợp, thì danh sáchminimatch
4 chứa mẫu ban đầu. Các trận đấu được sắp xếp, trừ khi cờ{
4 được đặt{
5 Mỗi khi tìm thấy một kết quả phù hợp, nội dung này sẽ được phát ra cùng với nội dung cụ thể phù hợp. Nó không bị trùng lặp hoặc phân giải thành một đường dẫn thực{
6 Được phát ra khi gặp phải lỗi không mong muốn hoặc bất cứ khi nào xảy ra bất kỳ lỗi fs nào nếu{
7 được đặt{
8 Khibuild/*
7 được gọi, sự kiện này được nâng lên
phương pháp
var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
00 Tạm dừng tìm kiếmvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
01 Tiếp tục tìm kiếm{
8 Ngừng tìm kiếm mãi mãi
Tùy chọn
Tất cả các tùy chọn có thể được chuyển tới Minimatch cũng có thể được chuyển tới Glob để thay đổi hành vi khớp mẫu. Ngoài ra, một số đã được thêm vào hoặc có sự phân nhánh cụ thể trên toàn cầu
Tất cả các tùy chọn đều sai theo mặc định, trừ khi có ghi chú khác
Tất cả các tùy chọn cũng được thêm vào đối tượng Glob
Nếu bạn đang chạy nhiều hoạt động
var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]03, bạn có thể chuyển một đối tượng Glob làm đối số
# to run tests
npm test
# to re-generate test fixtures
npm run test-regen
# to benchmark against bash/zsh
npm run bench
# to profile javascript
npm run prof
8 cho hoạt động tiếp theo để tắt một số cuộc gọi var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]05 và
var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]06. Ít nhất, bạn có thể chuyển các tùy chọn
.gitignore
7, .gitignore
5, .gitignore
9 và build/*
8 được chia sẻ để các hoạt động toàn cầu song song sẽ được tăng tốc bằng cách chia sẻ thông tin về hệ thống tệpvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
11 Thư mục làm việc hiện tại để tìm kiếm. Mặc định làvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
12. Tùy chọn này luôn bị ép buộc sử dụng dấu gạch chéo lên làm dấu phân cách đường dẫn, vì nó không được kiểm tra dưới dạng mẫu hình cầu, do đó không cần phải thoát khỏi bất kỳ thứ gìvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
13 Nơi mà các mẫu bắt đầu bằngvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
14 sẽ được gắn vào. Mặc định làvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
15 [var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
14 trên hệ thống Unix vàvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
17 hoặc một số như vậy trên Windows. ] Tùy chọn này luôn bị ép buộc sử dụng dấu gạch chéo lên làm dấu phân cách đường dẫn, vì nó không được kiểm tra dưới dạng mẫu hình cầu, do đó không cần phải thoát khỏi bất kỳ thứ gìvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
18 Chỉ sử dụngvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
19 làm dấu phân cách đường dẫn và không bao giờ làm ký tự thoát. Nếu được đặt, tất cả các ký tựvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
19 sẽ được thay thế bằngvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
14 trong mẫu. Lưu ý rằng điều này làm cho nó không thể khớp với các đường dẫn chứa các ký tự mẫu hình cầu theo nghĩa đen, nhưng cho phép khớp với các mẫu được tạo bằng cách sử dụngvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
22 vàvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
23 trên nền tảng Windows, bắt chước [buggy. ] hành vi của Glob v7 trở về trước trên Windows. Vui lòng sử dụng một cách thận trọng và chú ý đến. [Vì lý do kế thừa, giá trị này cũng được đặt nếuvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
24 được đặt thành giá trị chính xác
1. ]# to run tests npm test # to re-generate test fixtures npm run test-regen # to benchmark against bash/zsh npm run bench # to profile javascript npm run prof
var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
26 Bao gồmvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
27 tệp trong các trận đấu thông thường vàvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
28 trận đấu. Lưu ý rằng một dấu chấm rõ ràng trong một phần của mẫu sẽ luôn khớp với các tệp dấu chấmvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
29 Theo mặc định, một mẫu bắt đầu bằng dấu gạch chéo lên sẽ được "gắn" vào cài đặt gốc để đường dẫn hệ thống tệp hợp lệ được trả về. Đặt cờ này để tắt hành vi đóvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
30 Thêm một ký tựvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
14 vào thư mục phù hợp. Lưu ý rằng điều này yêu cầu các lệnh gọi stat bổ sung{
4 Không sắp xếp kết quảvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
05 Đặt thành true để thống kê tất cả các kết quả. Điều này phần nào làm giảm hiệu suất và hoàn toàn không cần thiết, trừ khivar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
06 được coi là một chỉ số không đáng tin cậy về sự tồn tại của tệpvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
35 Khi gặp lỗi bất thường khi cố gắng đọc một thư mục, một cảnh báo sẽ được in ra stderr. Đặt tùy chọnvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
35 thành true để chặn những cảnh báo nàyvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
37 Khi gặp lỗi bất thường khi cố gắng đọc một thư mục, quá trình sẽ tiếp tục tìm kiếm các kết quả phù hợp khác. Đặt tùy chọnvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
37 để báo lỗi trong những trường hợp nàybuild/*
8 Xem tài sảnbuild/*
8 ở trên. Chuyển vào một đối tượng bộ đệm được tạo trước đó để lưu một số cuộc gọi fs.gitignore
5 Bộ đệm chứa kết quả của thông tin hệ thống tệp, để ngăn các lệnh gọi stat không cần thiết. Mặc dù thông thường không cần thiết phải thiết lập điều này, nhưng bạn có thể chuyển statCache từ một lệnh gọi glob[] sang đối tượng tùy chọn của đối tượng khác, nếu bạn biết rằng hệ thống tệp sẽ không thay đổi giữa các lệnh gọi. [Xem "Điều kiện cuộc đua" bên dưới. ].gitignore
7 Bộ nhớ cache của các liên kết tượng trưng đã biết. Bạn có thể chuyển vào một đối tượng.gitignore
7 đã tạo trước đó để lưu các cuộc gọivar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
44 khi giải quyết các trận đấu của
4$ echo a*s*d*f a*s*d*f
build/*
2 KHÔNG DÙNG. sử dụngvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
47 thay thếvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
48 Trong một số trường hợp, các mẫu mở rộng bằng dấu ngoặc nhọn có thể dẫn đến cùng một tệp hiển thị nhiều lần trong tập hợp kết quả. Theo mặc định, việc triển khai này ngăn trùng lặp trong tập hợp kết quả. Đặt cờ này để tắt hành vi đó{
2 Đặt để không bao giờ trả về tập hợp trống, thay vào đó trả về tập hợp chứa chính mẫu đó. Đây là mặc định trong toàn cầu [3]var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
50 Đặt để bật ghi nhật ký gỡ lỗi trong minimatch và toàn cụcvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
51 Không mở rộng bộ nẹpvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
52 vàvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
53var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
54 Không khớp
4 với nhiều tên tệp. [Tức là, coi nó như một$ echo a*s*d*f a*s*d*f
var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
4 bình thường thay vì. ]var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
57 Không khớp với mẫu
3 "extglob"# to run tests npm test # to re-generate test fixtures npm run test-regen # to benchmark against bash/zsh npm run bench # to profile javascript npm run prof
var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
59 Thực hiện khớp không phân biệt chữ hoa chữ thường. Ghi chú. trên các hệ thống tệp không phân biệt chữ hoa chữ thường, các mẫu không có phép thuật sẽ khớp theo mặc định, vìvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
05 vàvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
06 sẽ không gây ra lỗivar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
62 Thực hiện đối sánh chỉ tên cơ sở nếu mẫu không chứa bất kỳ ký tự gạch chéo nào. Nghĩa là,var Glob = require["glob"].Glob var mg = new Glob[pattern, options, cb]
3 sẽ được coi là tương đương vớivar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
64, khớp với tất cả các tệp js trong tất cả các thư mụcvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
65 Không khớp thư mục, chỉ khớp tệp. [Ghi chú. để chỉ khớp các thư mục, chỉ cần đặt mộtvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
14 ở cuối mẫu. ]var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
67 Thêm một mẫu hoặc một mảng các mẫu hình cầu để loại trừ các kết quả phù hợp. Ghi chú.var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
67 mẫu luôn ở chế độvar Glob = require["glob"].Glob var mg = new Glob[pattern, options, cb]
1, bất kể mọi cài đặt khácvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
70 Theo dõi các thư mục được liên kết tượng trưng khi mở rộng các mẫu
4. Lưu ý rằng điều này có thể dẫn đến nhiều tham chiếu trùng lặp khi có các liên kết tuần hoàn$ echo a*s*d*f a*s*d*f
var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
72 Đặt thành true để gọi{
0 trên tất cả các kết quả. Trong trường hợp một liên kết tượng trưng không thể giải quyết được, đường dẫn tuyệt đối đầy đủ đến mục phù hợp sẽ được trả về [mặc dù nó thường là một liên kết tượng trưng bị hỏng]var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
74 Đặt thành true để luôn nhận được đường dẫn tuyệt đối cho các tệp phù hợp. Không giống nhưvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
72, điều này cũng ảnh hưởng đến các giá trị được trả về trong sự kiện{
5var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
77 Đối tượng hệ thống tệp với APIvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
77 của Node. Theo mặc định, mô-đunvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
77 tích hợp sẵn sẽ được sử dụng. Đặt thành âm lượng do thư viện cung cấp nhưvar glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]
80 để tránh sử dụng hệ thống tệp "thực"
So sánh với các triển khai fnmatch/glob khác
Mặc dù việc tuân thủ nghiêm ngặt các tiêu chuẩn hiện có là một mục tiêu đáng giá, nhưng vẫn tồn tại một số khác biệt giữa các triển khai toàn cầu nút và các triển khai khác và là có chủ ý.
Ký tự sao kép
$ echo a*s*d*f
a*s*d*f
4 được hỗ trợ theo mặc định, trừ khi cờ var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]54 được đặt. Điều này được hỗ trợ theo cách của bsdglob và bash 4. 3, trong đó
$ echo a*s*d*f
a*s*d*f
4 chỉ có ý nghĩa đặc biệt nếu nó là thứ duy nhất trong phần đường dẫn. Nghĩa là, var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]84 sẽ khớp với
var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]85, nhưng
var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]86 thì không
Lưu ý rằng các thư mục được liên kết tượng trưng không được thu thập thông tin như một phần của
$ echo a*s*d*f
a*s*d*f
4, mặc dù nội dung của chúng có thể khớp với các phần tiếp theo của mẫu. Điều này ngăn chặn các vòng lặp và trùng lặp vô hạn và những thứ tương tựNếu một mẫu thoát không có kết quả phù hợp và cờ {
2 được đặt, thì toàn cục sẽ trả về mẫu như được cung cấp, thay vì diễn giải ký tự thoát. Ví dụ:
var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]89 sẽ trả về
var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]90 thay vì
var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]91. Điều này giống như đặt tùy chọn
var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]92 trong bash, ngoại trừ việc nó không giải quyết các ký tự mẫu đã thoát
Nếu mở rộng dấu ngoặc không bị tắt, thì nó được thực hiện trước bất kỳ cách diễn giải nào khác của mẫu hình cầu. Do đó, một mẫu như
var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]93, sẽ không hợp lệ trong bash hoặc zsh, trước tiên được mở rộng thành tập hợp của
# to run tests
npm test
# to re-generate test fixtures
npm run test-regen
# to benchmark against bash/zsh
npm run bench
# to profile javascript
npm run prof
3 và var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]95, và những mẫu đó được kiểm tra tính hợp lệ. Vì hai cái đó là hợp lệ, tiền thu được phù hợp
Nhận xét và Phủ định
Trước đây, mô-đun này cho phép bạn đánh dấu một mẫu là "nhận xét" nếu mẫu bắt đầu bằng ký tự
var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]96 hoặc mẫu "phủ định" nếu mẫu bắt đầu bằng ký tự
var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]7
Các tùy chọn này không được dùng trong phiên bản 5 và bị xóa trong phiên bản 6
Để chỉ định những thứ không khớp, hãy sử dụng tùy chọn
var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]67
các cửa sổ
Vui lòng chỉ sử dụng dấu gạch chéo lên trong biểu thức toàn cục
Mặc dù các cửa sổ sử dụng
var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]14 hoặc
$ echo a*s*d*f
a*s*d*f
00 làm dấu phân cách đường dẫn, nhưng chỉ có var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]14 ký tự được sử dụng bởi triển khai toàn cầu này. Bạn chỉ được sử dụng dấu gạch chéo trong các biểu thức toàn cầu. Dấu gạch chéo ngược sẽ luôn được hiểu là ký tự thoát, không phải dấu phân cách đường dẫn
Kết quả từ các mẫu tuyệt đối, chẳng hạn như
$ echo a*s*d*f
a*s*d*f
02 được gắn vào cài đặt gốc bằng cách sử dụng $ echo a*s*d*f
a*s*d*f
03. Trên windows, theo mặc định, điều này sẽ dẫn đến kết quả khớp với ____10_______02 ___10_______05Để tự động ép buộc tất cả các ký tự
$ echo a*s*d*f
a*s*d*f
00 thành var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]14 trong chuỗi mẫu, do đó không thể thoát khỏi các ký tự toàn cầu theo nghĩa đen, bạn có thể đặt tùy chọn
var glob = require["glob"] // options is optional glob["**/*.js", options, function [er, files] { // files is an array of filenames. // If the `nonull` option is set, and nothing // was found, then files is ["**/*.js"] // er is an error object or null. }]18 thành
# to run tests
npm test
# to re-generate test fixtures
npm run test-regen
# to benchmark against bash/zsh
npm run bench
# to profile javascript
npm run prof
0Điều kiện cuộc đua
Tìm kiếm toàn cầu, về bản chất, dễ bị ảnh hưởng bởi các điều kiện chủng tộc, vì nó dựa vào việc đi bộ thư mục và như vậy
Do đó, có thể một tệp tồn tại khi global tìm kiếm có thể đã bị xóa hoặc sửa đổi vào thời điểm nó trả về kết quả
Là một phần của quá trình triển khai nội bộ, chương trình này lưu trữ tất cả lệnh gọi stat và readdir mà nó thực hiện, để cắt giảm chi phí hoạt động của hệ thống. Tuy nhiên, điều này cũng làm cho nó dễ bị races hơn, đặc biệt nếu các đối tượng bộ đệm hoặc statCache được sử dụng lại giữa các lệnh gọi toàn cục
Do đó, người dùng được khuyên không nên sử dụng kết quả toàn cục để đảm bảo trạng thái hệ thống tệp khi đối mặt với những thay đổi nhanh chóng. Đối với phần lớn các hoạt động, đây không bao giờ là vấn đề