Coder Social home page Coder Social logo

gilzoide / wildcard_pattern-lua Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 33 KB

Lua library for using shell-like wildcards as string patterns with support for importing gitignore-like file content

License: The Unlicense

Lua 100.00%
lua lua-library ignore-list gitignore-files wildcard

wildcard_pattern-lua's Introduction

wildcard_pattern.lua

Build Status

Lua library for using shell-like wildcards as string patterns with support for importing gitignore-like file content.

Installation

Copy wildcard_pattern.lua to your LUA_PATH or install with LuaRocks:

$ luarocks install wildcard_pattern

Usage

local wildcard_pattern = require 'wildcard_pattern'

-- Create simple lua string patterns from wildcard ones
local patt = wildcard_pattern.from_wildcard("*.lua")
assert(string.match("hello_world.lua", patt))

-- Or import a gitignore-like content from file
local ignore_patterns = wildcard_pattern.aggregate.from(io.open(".gitignore"))
-- local ignore_patterns = wildcard_pattern.aggregate.from(io.open(".gitignore"):read('*a'))  -- or from text
-- local ignore_patterns = wildcard_pattern.aggregate.from(io.lines(".gitignore"))  -- or from an iterator function
assert(not wildcard_pattern.any_match(ignore_patterns, "hello_world.lua"))  -- assuming your .gitignore have no rules for ignoring hello_world.lua
-- `any_match` is also a method and __call metamethod for ignore files
assert(not ignore_patterns:any_match("hello_world.lua"))
assert(not ignore_patterns("hello_world.lua"))

-- You can extend your aggregate wildcard with `insert`, `extend` or `extend_from` methods
ignore_patterns:insert("hello_world.lua")
ignore_patterns:extend("hello_world.lua", "hello_world[0-9].lua")
ignore_patterns:extend_from([[
# `extend_from` uses gitignore-like file content, just like `wildcard_pattern.aggregate.from`
world_hello?.lua
**.ignore
]])

What is supported

  • A single asterisk * matches zero or more characters that are not directory separators /
  • Two consecutive asterisks ** match zero or more characters
  • A question mark ? match any character that is not a directory separator /
  • Brackets [...] denote character sets and ranges, like [abcd] and [a-d]
  • Brackets may be negated with an exclamation mark [!...]
  • Backslash \ escapes are maintained

What is not supported

  • Prefix exclamation mark ! for negating the pattern in ignore files

Running tests

Run tests using busted

$ busted

wildcard_pattern-lua's People

Contributors

gilzoide avatar

Stargazers

 avatar  avatar  avatar

Watchers

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