Toàn cầu không đồng bộ Python

"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 đơ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.
    })
    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ặ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.
    })
    8 thì nó khớp với bất kỳ ký tự nào không có trong phạm 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.
    })
    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
  • $ echo a*s*d*f
    a*s*d*f
    
    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

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ên

Ví 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)
    6
  • var 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)
    8
  • var 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ông

Lư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ọn

toàn cầu (mẫu, [tùy chọn], cb)

  • # 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
    
    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
  • minimatch0 minimatch1
    • minimatch2 minimatch3
    • minimatch4 minimatch5 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])

  • # 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
    
    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
  • trở lại. minimatch5 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 *.js1

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
    # 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
    
    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
  • minimatch0 minimatch1 Được gọi khi xảy ra lỗi hoặc tìm thấy kết quả trùng khớp
    • minimatch2 minimatch3
    • minimatch4 minimatch5 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
  • # 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 Đối tượng tùy chọn được truyền vào
  • build/*6 Boolean được đặt thành true khi gọi build/*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ời
  • build/*8 Đối tượng tiện lợi. Mỗi trường có các giá trị có thể sau
    • # 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 - Đườ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
    • .gitignore1 - Đường dẫn tồn tại và không phải là thư mục
    • .gitignore2 - Đường dẫn tồn tại và là một thư mục
    • .gitignore3 - Đường dẫn tồn tại, là một thư mục và giá trị mảng là kết quả của .gitignore4
  • .gitignore5 Bộ nhớ cache của .gitignore6 kết quả, để ngăn việc nhập cùng một đường dẫn nhiều lần
  • .gitignore7 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
    $ echo a*s*d*f
    a*s*d*f
    
    4
  • .gitignore9 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ách minimatch4 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 Khi build/*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ếm
  • 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.
    })
    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 .gitignore7, .gitignore5, .gitignore9 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ệ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.
    })
    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ằ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 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ụ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.
    })
    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ằ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 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ụ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.
    })
    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ế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.
    })
    24 được đặt thành giá trị chính xác
    # 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. )
  • 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ồm
    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.
    })
    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ấm
  • 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.
    })
    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ừ khi
    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 được coi là một chỉ số không đáng tin cậy về sự tồn tại của tệ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.
    })
    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ọ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.
    })
    35 thành true để chặn những cảnh báo này
  • 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.
    })
    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ọ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.
    })
    37 để báo lỗi trong những trường hợp này
  • build/*8 Xem tài sản build/*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
  • .gitignore5 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. )
  • .gitignore7 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 .gitignore7 đã tạo trước đó để lưu các 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.
    })
    44 khi giải quyết các trận đấu của
    $ echo a*s*d*f
    a*s*d*f
    
    4
  • build/*2 KHÔNG DÙNG. 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.
    })
    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ụ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.
    })
    51 Không mở rộng bộ nẹ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.
    })
    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.
    })
    53
  • 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 Không khớp
    $ echo a*s*d*f
    a*s*d*f
    
    4 với nhiều tên tệp. (Tức là, coi nó như mộ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.
    })
    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
    # 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 "extglob"
  • 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ỗ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.
    })
    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ớ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.
    })
    64, khớp với tất cả các tệp js trong tất cả các thư mụ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.
    })
    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ộ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 ở 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á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.
    })
    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
    $ echo a*s*d*f
    a*s*d*f
    
    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
  • 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 {5
  • 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.
    })
    77 Đối tượng hệ thống tệp với API
    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.
    })
    77 của Node. Theo mặc định, mô-đun
    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.
    })
    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 đề

Python có thể chạy không đồng bộ không?

Lập trình bất đồng bộ là kiểu lập trình trong đó chúng ta có thể thực thi nhiều hơn một tác vụ mà không chặn Tác vụ chính (chức năng). Trong Python, có nhiều cách để thực thi đồng thời nhiều chức năng, một trong những cách đó là sử dụng asyncio .

Chủ đề không đồng bộ có an toàn với Python không?

Nói một cách đơn giản, an toàn theo luồng có nghĩa là an toàn khi có nhiều hơn một luồng truy cập vào cùng một tài nguyên và tôi biết Asyncio về cơ bản sử dụng một luồng duy nhất. Tuy nhiên, nhiều Tác vụ Asyncio có thể truy cập nhiều lần vào một tài nguyên cùng một lúc như đa luồng

Python có hỗ trợ async đang chờ không?

Từ khóa async/await đã được chuẩn hóa trong Python 3. 7 . Họ đơn giản hóa lập trình không đồng bộ trong Python. Từ khóa async được sử dụng để tạo một coroutine Python. Từ khóa chờ tạm dừng việc thực thi một coroutine cho đến khi nó hoàn thành và trả về dữ liệu kết quả.

Bộ ba Python là gì?

Trio là thư viện Python hiện đại để viết các ứng dụng không đồng bộ – nghĩa là các chương trình muốn thực hiện nhiều việc cùng lúc với các ứng dụng song song .