js-helpers

MatchFinder

MatchFinder (String string, String compare[, Object options])

Checks if every item of *String* string returns true from *Function* predicate.

Arguments

String string

Original string to find matches against with *String* compare.

String compare

String to match agains *String* string.

API

const finds = new MatchFinder(“foobar”, “foo”);

finds.matches (Array)

Returns Array of findings

finds.hasMatch (Boolean)

Returns Boolean if there was a match found.

finds.compare (String)

Returns compare string.

Note: When setting; finds.compare = "foo", this will reset finds and find all matches with the new compare value.

Finding

import { MatchFinder } from "@taystack/js-helpers";

MatchFinder("foobar", "foo").matches /*
[{
  string: "foo",
  match: true,
}, {
  string: "bar",
}]
*/

MatchFinder("foobar has the word foo", "foo").matches /*
[{
  string: "foo",
  match: true,
}, {
  string: "bar has the word ",
}, {
  string: "foo",
  match: true,
}]
*/

Source: @taystack/js-helpers hosted on GitHub Author: taystack