# All files / src/helpers/matchers matchStringProp.ts

100% Statements 5/5
100% Branches 4/4
100% Functions 1/1
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24

    366x
    39x

    327x
    317x

    10x

     import { TextMatch } from '../../matches';

    /**
     * Matches the given string property again string or regex matcher.
     *
     * @param prop - The string prop to match.
     * @param matcher - The string or regex to match.
     * @returns - Whether the string prop matches the given string or regex.
     */
    export function matchStringProp(
      prop: string | undefined,
      matcher: TextMatch
    ): boolean {
      if (!prop) {
        return false;
      }

      if (typeof matcher === 'string') {
        return prop === matcher;
      }

      return prop.match(matcher) != null;
    }