Skip to content

Enums Submodule

Import these enums from 'ua-parser-js/enums'

Code Example

  • Match for a specific os.name:
detect-rim.js
js
import { UAParser } from 'ua-parser-js';
import { OSName } from 'ua-parser-js/enums';

const { os } = UAParser();
if (os.is(OSName.RIM_TABLET_OS)) {
    console.log('Are you for real?');
}
  • Match for a specific browser.type:
detect-crawler.js
js
import { UAParser } from 'ua-parser-js';
import { Crawlers } from 'ua-parser-js/extensions';
import { BrowserType } from 'ua-parser-js/enums';

const uaParser = new UAParser(Crawlers);
const typeofBrowser = uaParser
                        .setUA(req.headers['user-agent'])
                        .getBrowser()
                        .type;
if (typeofBrowser == BrowserType.CRAWLER) {
    console.log('Hi, hello there Spidey!');
}

UAParser.js v2 is licensed under AGPLv3 or PRO licenses.