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

snifferjs

v4.1.0

Published

Browser/engine/os/device detection tool

Downloads

6,755

Readme

Sniffer

Sniffer is a browser/engine/os/device detection tool. Works both in a browser and with Node.

Live demo (tests your browser UA string)

Test suite

You have three options:

1. Default Sniffer build

Get sniffer.js from dist/. Drop the script tag in the <head>:

<script src="path/to/sniffer.js"></script>

It will run automatically, collect the information on current device/os/browser and put the results in window.Sniff object (or expose it via module.exports, if available). See “Detection results” for details. Now you can do horrible things:

if (Sniff.os.name=='android' &&
	Sniff.os.majorVersion &&
	Sniff.os.majorVersion < 3 &&
	!Sniff.browser.name &&
	Sniff.browser.engine=='webkit') {
		//looks like default Android 2.x browser!
		myMagicOverflowScrollPolyfill();
}

It will also add browser name shortcode, browser engine shortcode, OS name shortcode and device features’ shortcodes to <html> tag’s className, so you can alter the styles accordingly (pretty much the Modernizr way):

/* contrast colors for monochrome devices */
html.bw body {
	color: black;
	background: white;
}

/* make sure code snippets are readable in Opera Mini */
html.operamini pre code {
	white-space: pre-wrap;
}

2. Sniffer module

Get sniffer.module.js from dist/. It exposes Sniffer function into global scope or via module.exports, if available. Compatible with Node. Just feed it a user agent string:

Sniffer(userAgent);

It will return detection result, see “Detection results” for details.

Also available via npm: npm install snifferjs.

3. Pure Sniffer function

Get sniffer.pure.js from dist/. It contains pure Sniffer function (no wrap, no autolaunch, no css classes, no exports), you decide how to use it.

Detection results

Sniffer returns an object which looks like this:

{
	browser: {
		fullName: String, // full human readable name
		name: String, // shortcode
		version: String, // semantic version, up to three parts (major.minor.patch)
		majorVersion: Number,
		minorVersion: Number,
		patchVersion: Number,
		engine: String // shortcode
	},
	os: {
		fullName: String, // full human readable name
		name: String, // shortcode
		version: String, // semantic version, up to three parts (major.minor.patch)
		versionName: String, // human readable version name, e.g. 'Vista', 'Mavericks', etc.
		versionAltNames: Array, // possible alternatives, e.g. Windows NT 5.2 can be 'XP' or 'Server 2003'
		majorVersion: Number,
		minorVersion: Number,
		patchVersion: Number
	},
	features: {
		bw: Boolean, /* black and white (e-book readers) */
		mobile: Boolean, /* includes phones, tablets, e-book readers, portable game consoles, etc. */
		tv: Boolean, /* smart tv */
		proxy: Boolean /* serverside js & rendering, like in Opera Mini */
	}
}

Detects

Class names/shortcodes in square brackets.

Browsers:

  • Chrome [chrome]
  • Firefox [firefox]
  • IE [ie]
  • Edge [edge]
  • Safari [safari]
  • Opera [opera]
  • Opera Mini [operamini]
  • Opera Coast [coast]
  • Nokia Browser [nokiabrowser] (!= Nokia Xpress) — Symbian Belle phones
  • Ovi Browser a.k.a Nokia Xpress [ovi] — Nokia Asha, Series40 & Series60 phones, etc.
  • Sailfish Browser [sailfishbrowser]

Engines:

  • WebKit [webkit]
  • Gecko [gecko]
  • Trident [trident]
  • Presto [presto]
  • EdgeHTML [edgehtml]

OS/Devices:

  • Windows [win]
  • Mac OS X [osx]
  • Ubuntu [ubuntu]
  • Fedora [fedora]
  • Windows Phone [winphone]
  • Android [android]
  • iOS [ios]
  • BlackBerry [blackberry]
  • Sailfish OS [sailfish]
  • Symbian [symbian]
  • Kindle [kindle] (Kindle Fire should be detected as Android)
  • PlayStation [playstation]
  • PlayStation Vita [psvita]
  • Nintendo DSi [dsi]
  • Nintendo 3DS [3ds]
  • New Nintendo 3DS [n3ds]
  • Viera [viera] (Panasonic Viera smart tv)

Features:

  • Black and white [bw]
  • Mobile [mobile]
  • TV [tv]
  • Proxy broswer (serverside rendering) [proxy]

License

MIT license.

Have fun, lads.