parseBrowser method

Browser? parseBrowser(
  1. String userAgent
)

Parse a Browser from the userAgent string.

Returns null if no match.

Implementation

Browser? parseBrowser(String userAgent) {
  for (BrowserParser browserParser in browserParsers) {
    for (String regex in browserParser.regexes) {
      RegExp regExp = RegExp(regex, caseSensitive: false);

      if (regExp.hasMatch(userAgent)) {
        Iterable<RegExpMatch> matches = regExp.allMatches(userAgent);
        String unformattedName = matches.first.namedGroup('unformattedName')!;
        String version = matches.first.namedGroup('version') ?? '';

        return Browser(
          name: browserParser.name,
          unformattedName: unformattedName,
          version: version,
          type: browserParser.type,
          parsedWithRegex: regex,
        );
      }
    }
  }

  return null;
}