Code Monkey home page Code Monkey logo

perl5-text-gitignore's Introduction

NAME

Text::Gitignore - Match .gitignore patterns

SYNOPSIS

use Text::Gitignore qw(match_gitignore build_gitignore_matcher);

my @matched_files = match_gitignore(['pattern1', 'pattern2/*'], @files);

# Precompile patterns
my $matcher = build_gitignore_matcher(['*.js']);

if ($matcher->('foo.js')) {

    # Matched
}

DESCRIPTION

Text::Gitignore matches .gitignore patterns. It combines Text::Glob and File::FnMatch functionality with several .gitignore-specific tweaks.

EXPORTED FUNCTIONS

match_gitignore

my @matched_files = match_gitignore(['pattern1', 'pattern2/*'], @files);

Returns matched paths (if any). Accepts a string (slurped file for example), or an array reference

build_gitignore_matcher

# Precompile patterns
my $matcher = build_gitignore_matcher(['*.js']);

if ($matcher->('foo.js')) {

    # Matched
}

Returns a code reference. The produced function accepts a single file as a first parameter and returns true when it was matched. In case no pattern is matched, it returns a false value with the following convention:

  • if the no-match reason is because of a negated pattern, then a false but defined value is returned (e.g. 0);
  • otherwise, if the no-match reason is that no direct pattern matched, then undef is returned.

The use of different false values is inspired to the wantarray() built-in function.

Example:

my $matcher  = build_gitignore_matcher(['f*', '!foo*', 'foobar']);
my $matched  = $matcher->('foobar');  # $matched set to true
my $ignored  = $matcher->('bar');     # $ignored set to undef
my $excluded = $matcher->('foolish'); # $excluded set to false but defined (e.g. 0)

LICENSE

Originally developed for https://kritika.io.

Copyright (C) Viacheslav Tykhanovskyi.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

CREDITS

Flavio Poletti

Eric A. Zarko

AUTHOR

Viacheslav Tykhanovskyi [email protected]

perl5-text-gitignore's People

Contributors

polettix avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.