zena:glob

zena
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 ​

zena
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

zena
class GlobPattern

A compiled glob pattern for efficient repeated matching against paths.

Constructors
zena
new(pattern: String)
#
Properties
zena
pattern: String
#
Methods
zena
matches(path: String): boolean
#

Returns true if path matches this glob pattern.

GlobSet

zena
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.

Constructors
zena
new(patterns: Array<String>)
#
Properties
zena
size: i32 { get; }
#

How many patterns the set holds, negations included.

Methods
zena
matches(path: String): boolean
#

Whether path is in the set.

Functions

hasMagic

zena
function hasMagic(pattern: String): boolean

Returns true if pattern contains any glob syntax ('*', '?', '[', '{').

globToRegex

zena
function globToRegex(pattern: String): String

Translates a glob pattern to an anchored regular expression string.

Throws Error

if a { has no matching }.

matchGlob

zena
function matchGlob(pattern: String, path: String): boolean

Tests if path matches pattern.