How to use glob

Comprehensive glob code examples:

How to use glob.call:

31
32
33
34
35
36
37
38
39
40
41
42
     *
     * Use `Symbol` as much as possible to avoid confliction.
     */
    this[IGNORE] = shouldIgnore;


    Sync.call(this, pattern, options);
}


util.inherits(GlobSync, Sync);

How to use glob.prototype:

53
54
55
56
57
58
59
60
61
62
63
64
65
66


    if (this[IGNORE](marked)) {
        return null;
    }


    return Sync.prototype._readdir.call(this, abs, inGlobStar);
};




module.exports = GlobSync;

How to use glob.default:

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([]);
                    }

How to use glob.glob:

66
67
68
69
70
71
72
73
74
75
 * cancelled request temp data is also removed.
 */
server.addHook("onSend", async (req, _res, payload) => {
	if (req.conversionResults?.docLocation) {
		// Remove files from temp directory after response sent
		const files = await glob(
			`${path.joinSafe(
				req.conversionResults.docLocation.directory,
				req.conversionResults.docLocation.id
			)}*`

How to use glob.globIterateSync:

40
41
42
43
44
45
46
47
48
49
50
  return
}


function globFiles(path='./**/*') {
  const tick = makeAnimation()
  for (const file of globIterateSync(path)) {
    try {
      tick()
      let size = fs.statSync(file).size

How to use glob.globSync:

43
44
45
46
47
48
49
50
51
52
};
/** 获取样式 */
const getLibraryStyle = (scanDir, extension) => {
    const id = getHash(JSON.stringify({ scanDir, extension }));
    const createLibraryCache = () => {
        const files = glob.globSync(extension, {
            matchBase: true,
            cwd: scanDir
        }).map((path) => vite.normalizePath(path));
        cache.set(id, files);

How to use glob.sync:

230
231
232
233
234
235
236
237
238
239
/**
 * We do not need to ship the Electron binaries.
 */
function deleteElectronBinaries() {
    const preBuildsFolder = path.join(__dirname, 'node_modules', 'zeromqold', 'prebuilds');
    glob.sync('**/electron.napi.*.node', { sync: true, cwd: preBuildsFolder }).forEach((file) => {
        console.log(`Deleting ${file}`);
        fs.rmSync(path.join(preBuildsFolder, file), { force: true });
    });
}