How to use the default function from glob

Find comprehensive JavaScript glob.default code examples handpicked from public code repositorys.

glob.default is a function that takes a pattern and options as input and returns a promise that resolves with an array of matching file paths.

38
39
40
41
42
43
44
45
46
47
function getFiles() {
    return __awaiter(this, void 0, void 0, function* () {
        if (isInitialGetFiles) {
            isInitialGetFiles = false;
            const resolvedGlobs = yield Promise.all(includedGlobPatterns.map((globPattern) => new Promise((resolve) => {
                glob_1.default(globPattern, (error, resolvedFiles) => {
                    if (error) {
                        // fail silently
                        resolve([]);
                    }
fork icon0
star icon0
watch icon1

17
18
19
20
21
22
23
24
25
26
require("hardhat-gas-reporter");
require("hardhat-contract-sizer");
require("hardhat-log-remover");
require("hardhat-spdx-license-identifier");
if (!process.env.SKIP_LOAD) {
    glob_1.default.sync('./tasks/**/*.ts').forEach(function (file) {
        require(path_1.default.resolve(file));
    });
}
const DEFAULT_BLOCK_GAS_LIMIT = 12450000;
fork icon0
star icon0
watch icon0

How does glob.default work?

glob.default is a function provided by the glob package that takes a pattern and options as input, searches for all the matching file paths that match the pattern, and returns them in an array. It uses glob patterns (wildcard characters) to match file paths, and supports options such as ignore, nodir, and absolute paths.

32
33
34
35
36
37
38
39
40
41
    return {};
var lintConfig = {
    fix: Boolean(fix),
    allowEmptyInput: true,
};
var lintConfigFiles = glob_1.default.sync('.stylelintrc?(.@(js|yaml|yml|json))', { cwd: cwd });
if (lintConfigFiles.length === 0 && !pkg.stylelint) {
    lintConfig.configBasedir = path_1.default.resolve(__dirname, '../../node_modules/');
    lintConfig.config = {
        extends: 'stylelint-config-ali',
fork icon0
star icon0
watch icon1

62
63
64
65
66
67
68
69
70
71
        .concat(glob_1.default.sync('.stylelintrc?(.@(yaml|yml|json))', { cwd: cwd }))
        .concat(glob_1.default.sync('.markdownlint@(rc|.@(yaml|yml|jsonc))', { cwd: cwd }))
        .concat(glob_1.default.sync('.prettierrc?(.@(cjs|config.js|config.cjs|yaml|yml|json|json5|toml))', { cwd: cwd }));
};
var checkReWriteConfig = function (cwd) {
    return glob_1.default
        .sync('**/*.ejs', { cwd: path_1.default.resolve(__dirname, '../config') })
        .map(function (name) { return name.replace(/^_/, '.').replace(/\.ejs$/, ''); })
        .filter(function (filename) { return fs_extra_1.default.existsSync(path_1.default.resolve(cwd, filename)); });
};
fork icon0
star icon0
watch icon1

Ai Example

1
2
3
4
5
6
7
8
9
10
const glob = require("glob");

// match all JavaScript files in current directory and subdirectories
glob("**/*.js", function (err, files) {
  if (err) {
    console.error(err);
  } else {
    console.log(files);
  }
});

In this example, the glob function takes two arguments: a pattern to match against file paths and a callback function to be called with the results. The pattern **/*.js matches all .js files in the current directory and its subdirectories, and the callback function logs the resulting file paths to the console.

186
187
188
189
190
191
192
193
194
195
    _c.label = 18;
case 18:
    _c.trys.push([18, 20, , 21]);
    files = options.files
        ? getLintFiles(constants_1.MARKDOWN_LINT_FILE_EXT)
        : glob_1.default.sync('**/*.md', { cwd: cwd, ignore: 'node_modules/**' });
    return [4, markdownLint.lint(__assign(__assign({}, markdownLint.getLintConfig(options)), { files: files }))];
case 19:
    data = _c.sent();
    results = results.concat(markdownLint.formatResults(data, quiet));
fork icon0
star icon0
watch icon1