0.2.1 • Published 4 years ago

match-str v0.2.1

Weekly downloads
18
License
MIT
Repository
github
Last release
4 years ago

match-str 🧵

npm version Travis Status

Small, no dependency tool to match strings against regular expressions.

Usage

$ match-str -h
Usage: match-str [options]

Options:
  --str, -s       String to match on                      [String]
  --include, -i   If provided, must match pattern         [RegExp]
  --exclude, -e   If provided, cannot match pattern       [RegExp]
  --help, -h      Show help                               [boolean]
  --version, -v   Show version number                     [boolean]

  Examples:
  match-str -s "$(printf 'one\ntwo')"              Exits 0. Matches by default.
  match-str -i "^tw.+" -s "$(printf 'one\ntwo')"   Exits 0. Matches "two" at line start.
  match-str -e "one" -s "$(printf 'one\ntwo')"     Exits 0. Still matches "two".
  match-str -e ".*" -s "$(printf 'one\ntwo')"      Exits 1. Everything excluded.
  match-str -i "^three" -s "$(printf 'one\ntwo')"  Exits 1. No include match.

Notes

  • Provides no stdout, just exit process with 0 for match or 1 for no match.
  • Matching logic is:
    1. Split lines at newline. Then, for each line:
    2. If -i flags are provided, lines are filtered to at least one match.
    3. If -e flags are provided, lines are excluded.
    4. If any lines remain, process exits 0 else 1.
  • Can have multiple -i and -e options.