github.com/web-platform-tests/wpt.fyi@v0.0.0-20240530210107-70cf978996f1/shared/browsers.go (about)

     1  package shared
     2  
     3  import (
     4  	"strings"
     5  
     6  	mapset "github.com/deckarep/golang-set"
     7  )
     8  
     9  // A list of browsers that are shown on the homepage by default.
    10  // (Must be sorted alphabetically!)
    11  var defaultBrowsers = []string{
    12  	"chrome", "edge", "firefox", "safari",
    13  }
    14  
    15  // An extra list of known browsers.
    16  var extraBrowsers = []string{
    17  	"android_webview", "chrome_android", "chrome_ios", "chromium", "deno", "epiphany", "firefox_android", "flow", "node.js", "servo", "uc", "wktr", "webkitgtk",
    18  }
    19  
    20  var allBrowsers mapset.Set
    21  
    22  func init() {
    23  	allBrowsers = mapset.NewSet()
    24  	for _, b := range defaultBrowsers {
    25  		allBrowsers.Add(b)
    26  	}
    27  	for _, b := range extraBrowsers {
    28  		allBrowsers.Add(b)
    29  	}
    30  }
    31  
    32  // GetDefaultBrowserNames returns an alphabetically-ordered array of the names
    33  // of the browsers which are to be included by default.
    34  func GetDefaultBrowserNames() []string {
    35  	// Slice to make source immutable
    36  	tmp := make([]string, len(defaultBrowsers))
    37  	copy(tmp, defaultBrowsers)
    38  	return tmp
    39  }
    40  
    41  // IsBrowserName determines whether the given name string is a valid browser name.
    42  // Used for validating user-input params for browsers.
    43  func IsBrowserName(name string) bool {
    44  	name = strings.TrimSuffix(name, "-"+ExperimentalLabel)
    45  	return IsStableBrowserName(name)
    46  }
    47  
    48  // IsStableBrowserName determines whether the given name string is a valid browser name
    49  // of a stable browser (i.e. not using the -experimental suffix).
    50  func IsStableBrowserName(name string) bool {
    51  	return allBrowsers.Contains(name)
    52  }