
Security News
NVD Concedes Inability to Keep Pace with Surging CVE Disclosures in 2025
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
Device detection script to categorize devices as desktop, tv, tablet, or mobile.
Categorizr.js is a port of bjankord’s categorizr.php script. There is planned support for use within node.js and express as well as with the browser.
We are loosely following the semver system for versioning. Odd number releases will bring breaking API changes to existing code. They should be fully stable in their own right. Even numbered releases will be API-freeze and only bug-fixes.
0.3.x is the latest release as of June 14, 2012.
Check out a demo at skookum.github.com/categorizr.js
Currently categorizr has a standard ender.js implementation for usage within an ender build (has not been published to npm, yet) or drop in with your current library scripts.
It works by adding a class to the html element of your current device.
Add categorizr.js or categorizr.min.js to your library build or add to
your ender build with ender add categorizr
.
categorizr()
categorizr(deviceType)
tv
, desktop
,
tablet
and mobile
.categorizr(actualDevice, categorizeAsDevice)
actualDevice
. Target device you want to display as
another.categorizeAsDevice
. Device to display as.categorize('tv', 'tablet')
-> will categorize all known
smart-tv UA’s as a tablet device.categorizr.is(deviceType)
deviceType
. Currently supports tv
, desktop
,
tablet
and mobile
.categorizr.test(ua)
ua
. User-agent string to test.
@return {String} Returns string of device type that it matches.categorizr.isTv
{Bool}categorizr.isDesktop
{Bool}categorizr.isTablet
{Bool}categorizr.isMobile
{Bool}With the Ender integration (see below), we now have a deviceChange event triggered on the window object.
$(window).bind('deviceChange', function(device) {
console.log(device.type)
})
Please note that this API will most likely change (and become more flexible) in upcoming releases as we support additional libraries.
Ender is the only fully tested library supported currently. (jQuery, Zepto, and prototype may or may not work currently. Support is coming.)
A minimal ender bridge is supported namespacing all of this inside the
ender
namespace. Example ender.categorizr('mobile')
-> Set current
instance to be mobile. This assumes a selector library and event library
included in your build.
Additionally, since 0.2.5
ender.is
has been renamed to
ender.isDeviceType
and ender.test
has been renamed to
ender.testUserAgent
to prevent clashes with other libraries. (thanks
@rvagg)
The entirety of the API shown above is also available namedspaced inside
of ender. E.g. ender.categorizr('tablet')
will set the current
deviceType to 'tablet'.
ender.isDeviceType(deviceType)
@return {bool}ender.testUserAgent(UAString)
@return {string} deviceTypeEdit src/*.js
files.
Run make
in terminal.
You’ll need the devDependencies installed for smoosh (build tool) and buster (testing).
I know, I know. This is against “best practice” on the web, but really. Every company who wants to provide a targeted experience for a device does it. This is just making it easier for a front-end developer to integrate this into his development workflow.
Create a fork and add any UA’s that you wish to the appriate file (test/ua-strings/*.js
) and send a pull request.
is(deviceType)
– deviceType <string> of tv|desktop|tablet|mobile. Returns true/false based on current device.
isDesktop()
isTablet()
isTV()
isMobile()
– sugar around the previous method.
getType()
— returns current device type
setType()
– sets current device type and updates html class.
categorizeType(real, faked)
– Sets a device type as another. E.g. categorizr.categorizeType('tv', 'desktop')
sets all tv devices to be desktop.
FAQs
Device detection script to categorize devices as desktop, tv, tablet, or mobile.
We found that categorizr demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
Security Fundamentals
Attackers use obfuscation to hide malware in open source packages. Learn how to spot these techniques across npm, PyPI, Maven, and more.
Security News
Join Socket for exclusive networking events, rooftop gatherings, and one-on-one meetings during BSidesSF and RSA 2025 in San Francisco.