How to use the detect-browser.parseUserAgent function in detect-browser

To help you get started, we’ve selected a few detect-browser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github UnicornTranscoder / UnicornLoadBalancer / src / core / images.js View on Github external
...((query.width) ? { width: parseInt(query.width) } : {}),
        ...((query.height) ? { height: parseInt(query.height) } : {}),
        ...((query.background) ? { background: query.background } : {}),
        ...((query.opacity) ? { opacity: parseInt(query.opacity) } : {}),
        ...((query.minSize) ? { minSize: parseInt(query.minSize) } : {}),
        ...((query.blur) ? { blur: parseInt(query.blur) } : {}),
        ...((query.format && (query.format === 'webp' || query.format === 'png')) ? { format: query.format } : { format: 'jpg' }),
        ...((query.upscale) ? { upscale: parseInt(query.upscale) } : {}),
        ...((query.quality) ? { quality: parseInt(query.quality) } : ((query.blur) ? { quality: 100 } : { quality: 70 })),
        alpha: (query.format === 'png'),
        ...((query['X-Plex-Token']) ? { "X-Plex-Token": query['X-Plex-Token'] } : {}),
        url
    };

    // Auto select WebP if user-agent support it
    const browser = parseUserAgent(useragent);
    if (browser && browser.name && browser.name === 'chrome' && !query.format) {
        params.format = 'webp';
    }

    // Generate key
    params.key = md5(`${(query.url || '').split('?')[0]}|${params.width || ''}|${params.height || ''}|${params.background || ''}|${params.opacity || ''}|${params.minSize || ''}|${params.blur || ''}|${params.format || ''}|${params.upscale || ''}|${params.quality || ''}`.toLowerCase())

    // Return params
    return params;
}
github veteransaffairscanada / vac-benefits-directory / server.js View on Github external
server.get("*", (req, res) => {
      // Check if browse is less than IE 11
      const ua = req.headers["user-agent"];
      const browser = parseUserAgent(ua);
      const lang = req.query.lng
        ? req.query.lng
        : req.headers["accept-language"];

      req.data = data;
      req.language = lang ? lang.split(",")[0] : "en";
      if (
        browser &&
        browser.name === "ie" &&
        parseInt(browser.version) < 11 &&
        !req.url.includes("all-benefits") &&
        !req.url.includes(".css")
      ) {
        res.sendFile("fallback-pages/browser-incompatible.html", {
          root: __dirname
        });

detect-browser

Unpack a browser type and version from the useragent string

MIT
Latest version published 2 years ago

Package Health Score

74 / 100
Full package analysis