zena:glob
import {…} from 'zena:glob';
Pattern matching and regular expression translation for glob patterns.
Supports standard glob wildcards:
*matches characters within a single path segment (not crossing/)**matches across directory boundaries?matches any single character[...]matches character ranges and classes[!...]matches inverted character classes{a,b}matches any one of its comma-separated alternatives, each of which may hold wildcards or further braces ({src,test}/**,index.{js,d.ts},main{,.test}.zena)
GlobSet reads a list of patterns with ! exclusions, the way
.gitignore does.
Examples ​
import { matchGlob, GlobPattern } from 'zena:glob';
let matches = matchGlob('tests/*_test.zena', 'tests/foo_test.zena');
let pattern = new GlobPattern('*.zena');
let isZena = pattern.matches('main.zena');
Classes
GlobPattern
class GlobPattern
A compiled glob pattern for efficient repeated matching against paths.
GlobSet
class GlobSet
An ordered list of patterns in which a ! prefix excludes, read the
way .gitignore and wireit read theirs: a path is in the set when the
last pattern that matches it is a positive one.
['src/**', '!src/tmp/**', 'src/tmp/keep.ts'] takes src/a.ts and
src/tmp/keep.ts and leaves out src/tmp/x.ts. A path no pattern
matches is not in the set, so a list of only negations is empty.
Functions
hasMagic
function hasMagic(pattern: String): boolean
Returns true if pattern contains any glob syntax ('*', '?', '[', '{').
globToRegex
function globToRegex(pattern: String): String
Translates a glob pattern to an anchored regular expression string.
matchGlob
function matchGlob(pattern: String, path: String): boolean
Tests if path matches pattern.