0.8.1 • Published 4 years ago
@open-tech-world/es-glob v0.8.1
@open-tech-world/es-glob
A glob pattern matching library.
Supported glob patterns
Basic
✔️ * (Wildcard)
✔️ ** (Globstar)
✔️ ? (Wildcard)
✔️ […] (Brackets)
✔️ \\ (Escape Special Characters)
✔️ ! (Negation)
Braces
🚧 {,} (Brace Matching)
Extended glob
❌ ?(pattern-list)
❌ *(pattern-list)
❌ +(pattern-list)
❌ @(pattern-list)
❌ !(pattern-list)
POSIX Character classes
❌ [:class:]
Others
❌ Regular expression
✔️ (|) Logical OR Group
Installation
Using npm
npm install @open-tech-world/es-globUsing Yarn
yarn add @open-tech-world/es-globUsage
import { matchGlob } from '@open-tech-world/es-glob';
matchGlob(str: string, pattern: string): boolean;Examples
matchGlob('/a.json', '/*.json') // true
matchGlob('a/b/.x/c/d', '**/.x/**') // true
matchGlob('abc', 'ab?') // true
matchGlob('b', '[a-c]') // true
matchGlob('a', '[!a-c]') // false
matchGlob('b', '[^a-c]') // false
matchGlob('*.txt', '\\*.txt') // true
matchGlob('node_modules', '!node_modules') // false
matchGlob('a', '(a|b)') // true
matchGlob('config.js', '*.(js|json)') // true
matchGlob('tsconfig.json', '*.(js|json)') // true
matchGlob('index.ts', '*.(js|jsx|tsx)') // falsematchPathGlob
It matches a path in a glob pattern.
import { matchPathGlob } from '@open-tech-world/es-glob';
matchPathGlob('a', 'a/*') // true
matchPathGlob('a/b', 'a/*') // true
matchPathGlob('a/b/c', 'a/*') // falseReferences
https://www.gnu.org/software/bash/manual/html_node/Pattern-Matching.html
https://en.wikipedia.org/wiki/Glob_(programming)
License
Copyright (c) 2021, Thanga Ganapathy (MIT License).