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

node-user-agents

v2.0.1

Published

Extended useragent parser for Node. Uses useragent and extends its functionality

Downloads

574

Readme

npm version Build Status

Node User Agents

Smart user-agent parser for Node.

Extends useragent module and provides python-user-agents like functionality. Exposes custom defined functions like isMobile(), isTablet(), isPc()

Installation:

npm install --save node-user-agents
yarn add node-user-agents

Usage:

const UserAgent = require('node-user-agents');
const uaString = 'Mozilla/5.0 (Linux; Android 4.1.1; Galaxy Nexus Build/JRO03C) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19';

const useragent = new UserAgent(uaString);

// logs true
console.log(useragent.isMobile());

While using this module you can still access useragent module through useragent.userAgent property, for example console.log(useragent.userAgent.family);.

Also you can access user agent string via useragent.uaString

There are multiple ways to use this library. You can pass your user-agent string on initialization or you can use ua.parse(uaString) method for multiple user-agent parsing operations.


const UserAgent = require('node-user-agents');
const useragent = new UserAgent();
useragent.parse(uaString); // same result as above
// logs true
console.log(useragent.isMobile());

Options

You can provide an option to this library to change useragent' module behaviour.

  • lookup: uses useragent.lookup instead of useragent.parse
  • update: updates useragent database with latest version

const UserAgent = require('node-user-agents');
const useragent = new UserAgent(uaString, {lookup: true}); // now use userangets.lookup method
// logs true
console.log(useragent.isMobile());

Your own useragentLib

You can pass your own useragent instance with the last parameter in the constructor method. This way instead of using the version shipped with this library you can use your own modified or latest version of useragent.


const myownUserAgentLibrary = require('useragent');
const UserAgent = require('node-user-agents');
const useragent = new UserAgent(uaString, {update: true}, myownUserAgentLibrary);
// logs true
console.log(useragent.isMobile());

Api:

This module provides these additional methods.

  • getBrowser() Returns generic browser name
  • isTouchCapable() Returns true if given device is touch capable
  • isMobile()
  • isTablet()
  • isPc()
  • isBot()
  • getOs() Returns OS String like Windows, Linux, Mac OS X, OpenBSD, Android, iOS
  • isSmartTv()
  • getDevice() Returns device category based on above methods like tablet, mobile, pc, bot