@metreeca/core - v0.9.19
    Preparing search index...

    Function matchTag

    • Checks if a language tag matches a basic language range.

      Implements Basic Filtering per RFC 4647 § 3.3.1. Matching is case-insensitive:

      • The standalone * range matches any language tag
      • Otherwise the range matches if it equals the tag, or equals a prefix of the tag ending at a subtag boundary (the tag character following the prefix is -)

      Parameters

      • tag: string

        The language tag to test

      • range: string

        The basic language range to match against

      Returns boolean

      true if the tag matches the range pattern; false otherwise

      TypeError If tag is not a valid language tag or range is not a valid basic language range

      import { matchTag } from "@metreeca/core/language";

      matchTag("de-CH", "de"); // true - de-CH has subtag prefix de
      matchTag("de-CH", "de-CH"); // true - exact match
      matchTag("de", "de-CH"); // false - range is longer than tag
      matchTag("deu", "de"); // false - de is not a subtag prefix of deu
      matchTag("en-US", "*"); // true - wildcard matches any tag