regex-rules
Apply a combination of regexes to an input and see if it passes or fails
Last updated 3 years ago by mheap .
Original npm · Tarball · package.json
$ cnpm install regex-rules 
SYNC missed versions from official npm registry.

regex-rules

This package allows you to specify a list of regexes and test inputs against them.

Build Status

Installation

npm install regex-rules --save

Usage

const RegexRules = require("regex-rules");
const r = new RegexRules(
  {
    empty: "^$",
    "more-than-20-chars": "^.{20,}$",
    "contains-link": "http://"
  },
  {
    "empty-or-long": ["empty", "more-than-20-chars"],
    "long-link": [["contains-link", "more-than-20-chars"]]
  }
);

// You can run individual rules. This can be useful to get a true/false result

// By default, anything provided is an OR e.g.
// The input is empty, or more than 20 characters long
r.evaluateRule("", "empty-or-long")); # true
r.evaluateRule("this-is-really-really-really-long", "empty-or-long")); # true
r.evaluateRule("foo", "empty-or-long")); # false

// If you need an AND, add another array e.g.
// Contains a link AND it's more than 20 characters
r.evaluateRule("http://example-is-long.com", "long-link")); # true
r.evaluateRule("http://foo.com", "long-link"); # false

// You can negate the result too
r.evaluateRule("http://foo.com", "!long-link"); # true

// Alternatively, you can run against all defined rules
r.run("this-is-really-really-really-long");
# {"empty-or-long": true, "long-link": false}
r.run("http://example-is-long.com");
# {"empty-or-long": true, "long-link": true}

Current Tags

  • 0.0.3                                ...           latest (3 years ago)

3 Versions

  • 0.0.3                                ...           3 years ago
  • 0.0.2                                ...           3 years ago
  • 0.0.1                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (7)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |