@open-tech-world/es-glob
TypeScript icon, indicating that this package has built-in type declarations

0.8.1 • Public • Published

@open-tech-world/es-glob

Build CodeFactor

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-glob

Using Yarn

yarn add @open-tech-world/es-glob

Usage

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)') // false

matchPathGlob

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/*') // false

References

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

Package Sidebar

Install

npm i @open-tech-world/es-glob

Weekly Downloads

0

Version

0.8.1

License

MIT

Unpacked Size

13.9 kB

Total Files

11

Last publish

Collaborators

  • ganapathy