Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Spirit

Hierarchy

  • Spirit

Index

Constructors

constructor

  • new Spirit(pattern: string): Spirit
  • Parameters

    • pattern: string

      The string to use as the pattern.

    Returns Spirit

Properties

Private Readonly pattern

pattern: string

The string used to create the Spirit.

Readonly strength

strength: number

Represents how specific the pattern is. Similar to length, but not quite the same.

Methods

allMatch

  • allMatch(...matches: string[]): boolean
  • Checks if multiple strings match against the pattern. Only returns true if all strings match.

    Parameters

    • Rest ...matches: string[]

      The strings to compare to the pattern.

    Returns boolean

findMatches

  • findMatches(...matches: string[]): string[]
  • Allows you to quickly test many strings against the pattern, and see which ones match it.

    Parameters

    • Rest ...matches: string[]

    Returns string[]

    All of the strings that matched against the pattern.

match

  • match(match: string): boolean
  • Checks if a string matches against the pattern.

    Parameters

    • match: string

      The string to compare to the pattern.

    Returns boolean

toString

  • toString(): string
  • Returns the pattern string that was used to construct the Spirit.

    Returns string

Static allMatch

  • allMatch(pattern: Pattern, ...matches: string[]): boolean
  • Provides a way to check if multiple string match a pattern without constructing a Spirit.

    Parameters

    • pattern: Pattern

      The pattern to compare the strings against.

    • Rest ...matches: string[]

      The strings to compare to the pattern.

    Returns boolean

Static bestMatch

  • bestMatch(match: string, ...patterns: Pattern[]): null | Pattern
  • Returns the Spirit or pattern string that best matches the target string. In the case of a tie, the spirit that was passed to the function first will be returned.

    Parameters

    • match: string

      The patterns that will be tested against the string.

    • Rest ...patterns: Pattern[]

    Returns null | Pattern

Static createSpirit

  • createSpirit(pattern: Pattern): Spirit
  • Can be used as an alternate way to construct a Spirit. It can be useful for cases where you might have a string or a Spirit.

    Parameters

    • pattern: Pattern

      The string to use as the pattern.

    Returns Spirit

Static findMatches

  • findMatches(pattern: Pattern, ...matches: string[]): string[]
  • Provides a way to check which strings match a pattern without constructing a Spirit.

    Parameters

    • pattern: Pattern

      The pattern to compare the strings against.

    • Rest ...matches: string[]

      The strings to compare to the pattern.

    Returns string[]

Static map

  • map(patterns: Pattern[], matches: string[]): Map<Pattern, string[]>
  • Returns a map using the pattern as the key and an array of matches as the value. If the pattern given was a string, the key will be a string. If the pattern was a spirit, then that same spirit will be the key.

    Parameters

    • patterns: Pattern[]

      An array of pattern strings or Spirits to check against

    • matches: string[]

      An array of strings that will be checked against the patterns

    Returns Map<Pattern, string[]>

Static match

  • match(pattern: Pattern, match: string): boolean
  • Provides a way to check if a string matches a pattern without constructing a Spirit.

    Parameters

    • pattern: Pattern

      The pattern to compare the string against.

    • match: string

      The string to compare to the pattern.

    Returns boolean

Generated using TypeDoc