All files / src/utils platform.js

0% Statements 0/7
0% Branches 0/4
0% Functions 0/1
0% Lines 0/7

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                                               
// Define regex patterns for different OS types
const patterns = [
  { name: "iPad", regex: /iPad; CPU OS (\d[_\d]*)/ },
  { name: "iOS", regex: /iPhone OS (\d[_\d]*)/ },
  { name: "Ubuntu", regex: /Ubuntu(;|\/) ([^;\s]+)/ },
  { name: "CrOS", regex: /CrOS ([^;)]+)/ },
  { name: "Linux", regex: /Linux ([^;)]+)/ },
  { name: "Mac OS X", regex: /Mac OS X (\d[._\d]*)/ },
  { name: "Windows", regex: /Windows NT (\d[.\d]*)/ },
  { name: "Android", regex: /Android (\d[.\d]*)/ },
];
 
export function extractOSVersion(userAgent) {
  for (const pattern of patterns) {
    const match = userAgent.match(pattern.regex);
    if (match) {
      if (pattern.name === "Ubuntu") {
        return `${pattern.name}; ${match[2].replace(/_/g, ".")}`;
      }
      return `${pattern.name} ${match[1].replace(/_/g, ".")}`;
    }
  }
}