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

ua-parser-caps

v0.2.2

Published

capabilities for ua-parser2

Downloads

34

Readme

ua-parser-caps

Adding capabilities to ua-parser2

NOTE: This projects data-sets (yaml files) are outdated as not beiing maintained any more...

NPM version Build Status

ua-parser-caps is a parser build upon the extracted data provided by ua-parser2. It adds capabilities to User-Agent String(s) with the following features:

  • Capabilities can be added using the dimensions OS, User-Agent and device.
  • Capabilities can be applied per regular-expression either on complete User-Agent strings or on any extracted value provided by the parsing result from ua-parser2.
  • Capabilities can be extended per OS, User-Agent and Device.
    • Extends can be chained (use capability3 based on capability2 based on capability1 ...).
  • Capabilities can be overwritten if criterias from another dimension match.
  • Capabilities can be attributed within separate files. This allows to choose the proper capabilities for your use-case.

Table of Contents

Capability Files

Within this project the following capability-files are provided:

  • caps_device_type.yaml contains a device-type classification of a User-Agent String.
  • caps_user_view.yaml contains a user view default preference classification.
  • caps_ie_compatibility.yaml contains information on Internet Explorer capability mode.

Details of the capabilities can be found within the files.

The set of capability files you want to use in your project can be changed within the file js/config.js.

Fastloading

To speed up the loading and parsing of the YAML files a preparsed js-module is generated.

Use js/bin/caps2js.js -c or make caps to generate a new version if the YAML files have changed.

npm packages always contain the latest capability files.

Usage

A sample usage is provided using the file js/test/sample.js.

var uaparser = require('ua-parser2')();
var capsparser = require('ua-parser-caps')();
var userAgent = 'Mozilla/5.0 (Linux; Android 4.3.1; LG-E980 Build/JLS36I) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.59 Mobile Safari/537.36';

var uaparsed = uaparser.parse(userAgent);
var capabilities = capsparser.parse(uaparsed);
console.log(capabilities);

outputs:

{ device: { type: 'phablet' },
  user: { view: 'mobile' },
  info:
   { href:
      { '1': 'http://www.lg.com/uk/mobile',
        '2': 'http://www.lg.com/us/',
        '3': 'https://support.google.com/googleplay/answer/1727131?hl=en#L' } },
  screen: { size: 5.5, width: 1080, height: 1920 } }

See sample.js.

Asynchronous Loading

var userAgent = "Mozilla/5.0 (Linux; Android 4.3.1; LG-E980 Build/JLS36I) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.59 Mobile Safari/537.36";

var uaparser = require('ua-parser2')();
require('ua-parser-caps')(function(err, capsparser){
  /// async loading completed
  if (!err) {
    var uaparsed = uaparser.parse(userAgent);
    var capabilities = capsparser.parse(uaparsed);
    console.log(capabilities);
  }
});

See sampleAsync.js.

Specification

If you are interested to contribute data or even write your own capability files then please take a look into the specification.

Files

  • ./

    • caps_*.yaml capability files
  • ./doc

    • specification.md Specification on capability files.
  • ./js

    • index.js A node.js implementation of ua-parser-cap.
    • config.js Configuration file for the parser.
  • ./js/test

    • test files for the parser.
  • ./test/resources/parser

    • test files as yaml files to test a ua-parser-cap implementation.

Contribution and License Agreement

If you contribute code to this project, you are implicitly allowing your code to be distributed under the MIT license. You are also implicitly verifying that all code is your original work.

If you contribute data to this project, you are implicitly allowing your code to be distributed under the CC-BY-4.0 license. You are also implicitly verifying that all data is your original work.

Please read the contributors' guide.

License

Copyright (c) 2013 commenthol

Software is released under MIT. Data provided within Yaml-Files is released under CC-BY-4.0.