Function: GlobSync()
GlobSync(
pattern,options?):string[]
Find the files and directories matching glob patterns synchronously, blocking the event loop while the file system is walked: the same patterns, options and results as Glob, for the startup code and the scripts.
Parameters
pattern
string | string[]
A pattern or several (their results are merged), relative to options.cwd or absolute; an empty array gives [].
options?
How the paths are matched and given, see GlobOptions.
Returns
string[]
The matching paths, sorted, without duplicates; [] when nothing matches.
Example
typescript
import path from 'node:path'
import {GlobSync} from 'lakutata/utils'
//The absolute paths of the JSON files of a directory, its hidden ones included
const configs: string[] = GlobSync('*.json', {cwd: path.resolve('config'), absolute: true, dot: true})
console.log(configs)
//['/srv/app/config/.local.json', '/srv/app/config/default.json']