npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bugz

v0.1.2

Published

Composable User Agent Detection

Downloads

11

Readme

Bugz npm version Build Status Coverage Status

Composable user agent detection using Ramda, powered by ua-parser-js.

Why?

Because browsers have bugs bugz.

MDN offers some good advice about when and when not to use user agent detection.

Yeah, but why another UA library?

Bugz isn't really another library, it's just a lightweight* functional wrapper around ua-parser-js.

* for those already using Ramda.

Install

$ npm install ramda
$ npm install bugz

Ramda is defined as a peer dependency meaning it needs to be defined in your own package.json.

Usage

import { isOSName } from 'bugz';

const isWindows = isOSName('Windows');

if (isWindows(window.navigator.userAgent)) {
    console.log('OS is Windows');
}
import { isOSName, isBrowserName } from 'bugz';
import { allPass } from 'ramda';

const isWindows = isOSName('Windows');
const isFirefox = isBrowserName('Firefox');
const isWindowsFirefox = allPass([
    isWindows,
    isFirefox
]);

if (isWindowsFirefox(window.navigator.userAgent)) {
    console.log('OS is Windows and Browser is Firefox');
}
import { isOSName, isBrowserName, isBrowserVersionLt } from 'bugz';
import { allPass } from 'ramda';

const isWindows = isOSName('Windows');
const isFirefox = isBrowserName('Firefox');
const isBrowserVersionLt3_7 = isBrowserVersionLt('3.7');
const isWindowsFirefoxLt3_7 = allPass([
    isWindows,
    isFirefox,
    isBrowserVersionLt3_7
]);

if (isWindowsFirefoxLt3_7(window.navigator.userAgent)) {
    console.log('OS is Windows and Browser is Firefox < 3.7');
}

API

All functions are curried by default.

about (ua: string) → void
Logs all information obtained from the user agent string to the console.

getBrowser (ua: string) → { name: string, version: string, majorVersion: number }
Returns the browser from the user agent string.

getBrowserName (ua: string) → string
Returns the browser name from the user agent string.

getBrowserVersion (ua: string) → string
Returns the browser version from the user agent string.

getEngine (ua: string) → { name: string, version: string }
Returns the engine from the user agent string.

getEngineName (ua: string) → string
Returns the engine name from the user agent string.

getEngineVersion (ua: string) → string
Returns the engine version from the user agent string.

getOS (ua: string) → { name: string, version: string }
Returns the OS from the user agent string.

getOSName (ua: string) → string
Returns the OS name from the user agent string.

getOSVersion (ua: string) → string
Returns the OS version from the user agent string.

isAndroid (ua: string) → boolean
Returns whether or not the operating system is Android.

isAndroidBrowser (ua: string) → boolean
Returns whether or not the browser is Android Browser.

isBrowserName (name: string) → (ua: string) → boolean
Returns whether or not the browser name is name.

isBrowserVersion (version: string) → (ua: string) → boolean
Returns whether or not the browser version is version.

isBrowserVersionGt (version: string) → (ua: string) → boolean
Returns whether or not the browser version is greater than version.

isBrowserVersionGte (version: string) → (ua: string) → boolean
Returns whether or not the browser version is greater than or equal to version.

isBrowserVersionLt (version: string) → (ua: string) → boolean
Returns whether or not the browser version is less than version.

isBrowserVersionLte (version: string) → (ua: string) → boolean
Returns whether or not the browser version is less than or equal to version.

isChrome (ua: string) → boolean
Returns whether or not the browser is Chrome.

isEdge (ua: string) → boolean
Returns whether or not the browser is Edge.

isEdgeHTML (ua: string) → boolean
Returns whether or not the engine is EdgeHTML.

isEngineName (name: string) → (ua: string) → boolean
Returns whether or not the engine name is name.

isEngineVersion (version: string) → (ua: string) → boolean
Returns whether or not the engine version is version.

isEngineVersionGt (version: string) → (ua: string) → boolean
Returns whether or not the engine version is greater than version.

isEngineVersionGte (version: string) → (ua: string) → boolean
Returns whether or not the engine version is greater than or equal to version.

isEngineVersionLt (version: string) → (ua: string) → boolean
Returns whether or not the engine version is less than version.

isEngineVersionLte (version: string) → (ua: string) → boolean
Returns whether or not the engine version is less than or equal to version.

isFirefox (ua: string) → boolean
Returns whether or not the browser is Firefox.

isGecko (ua: string) → boolean
Returns whether or not the engine is Gecko.

isIE (ua: string) → boolean
Returns whether or not the browser is Internet Explorer.

isIEMobile (ua: string) → boolean
Returns whether or not the browser is Internet Explorer Mobile.

isIOS (ua: string) → boolean
Returns whether or not the operating system is iOS.

isMacOS (ua: string) → boolean
Returns whether or not the operating system is Mac OS.

isMobileSafari (ua: string) → boolean
Returns whether or not the browser is Mobile Safari.

isOSName (name: string) → (ua: string) → boolean
Returns whether or not the OS name is name.

isOSVersion (version: string) → (ua: string) → boolean
Returns whether or not the OS version is version.

isOSVersionGt (version: string) → (ua: string) → boolean
Returns whether or not the OS version is greater than version.

isOSVersionGte (version: string) → (ua: string) → boolean
Returns whether or not the OS version is greater than or equal to version.

isOSVersionLt (version: string) → (ua: string) → boolean
Returns whether or not the OS version is less than version.

isOSVersionLte (version: string) → (ua: string) → boolean
Returns whether or not the OS version is less than or equal to version.

isOpera (ua: string) → boolean
Returns whether or not the browser is Opera.

isOperaMobile (ua: string) → boolean
Returns whether or not the browser is Opera Mobile.

isPresto (ua: string) → boolean
Returns whether or not the engine is Presto.

isSafari (ua: string) → boolean
Returns whether or not the browser is Safari (desktop).

isTrident (ua: string) → boolean
Returns whether or not the engine is Trident.

isWebKit (ua: string) → boolean
Returns whether or not the engine is WebKit.

isWindows (ua: string) → boolean
Returns whether or not the operating system is Windows.

isWindowsPhone (ua: string) → boolean
Returns whether or not the operating system is Windows Phone.

parse (ua: string) → { ua: string, browser: { name: string, version: string, majorVersion: string }, engine: { name: string, version: string }, os: { name: string, version: string }
Returns all information obtained from the user agent string.

Module Formats

ES2015

import { isBrowserName } from 'bugz';

Unfortuantely tree shaking isn't particularly effective on Bugz because most exports are pure curried functions which aren't currently susceptible to dead code elimination. Therefore, a modular CommonJS build is additionally offered.

CommonJS

const bugz = require('bugz');
// Or modular for optimized builds
const isBrowserName = require('bugz/isBrowserName');
const isBrowserVersion = require('bugz/isBrowserVersion');

UMD

<script src="bugz.umd.js"></script>
<script>
    const isBrowserName = Bugz.isBrowserName;
</script>
require(['bugz'], bugz => {});

License

MIT

TODO

  • [x] Move Ramda to peer dep.
  • [x] Throw if UA is not passed in to parse as ua-parser-js fallsback to window.navigator.userAgent in a browser env.
  • [x] Add helper functions for popular browsers.
  • [x] Add helper functions for popular engines
  • [x] Add helper functions for popular operating systems.
  • [x] Document umd, cjs and esmodule builds.
  • [x] Document API.
  • [x] Provide more examples.
  • [ ] Add integration tests to test composability.
  • [x] Hook up to Travis and Coveralls.
  • [x] Publish.
  • [ ] Review whether Ramda indeed does need to be a peerdep, i.e. it doesn't matter that it uses the exact same instance as the host app.