ua-parser-caps

0.2.2 • Public • Published

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.

Dependencies (6)

Dev Dependencies (5)

Package Sidebar

Install

npm i ua-parser-caps

Weekly Downloads

3

Version

0.2.2

License

none

Unpacked Size

7.61 MB

Total Files

29

Last publish

Collaborators

  • commenthol