aklump/gitignore

Small library for matching gitignore style (glob) patterns.

0.0.3 2024-02-16 23:18 UTC

This package is auto-updated.

Last update: 2024-11-17 00:59:55 UTC


README

A small library to allow you to work with .gitignore (glob) patterns.

Test a .gitignore pattern

$pattern = new \AKlump\GitIgnore\Pattern('foo/**/*.php');
$pattern->matches('foo/bar/baz/lorem.php') === TRUE;

Convert to RegEx

$pattern = new \AKlump\GitIgnore\Pattern('settings*.php');
$pattern->toRegex() === '#^settings[^/]*\.php/?$#';

Check If String Contains a Pattern

\AKlump\GitIgnore\Analyzer::containsPattern('foo/**') === TRUE
\AKlump\GitIgnore\Analyzer::containsPattern('foo/bar') === FALSE

Known Issues

Not all special characters are yet supported.