diff --git a/README.md b/README.md index d649930..fa2b080 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,14 @@ -# sua.js +# ☕️ sua.js [![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE) [![Build Status](https://travis-ci.org/fkei/sua.js.svg?branch=master)](https://travis-ci.org/fkei/sua.js) [![npm version](https://badge.fury.io/js/sua.js.svg)](https://badge.fury.io/js/sua.js) -Simple user agent detection library. (Node.js or Browser supported) +A simple User-Agent string parser. -## Install +(Node.js or Browser supported) + +## 🔰 Install ```bash $ npm install sua.js @@ -14,7 +16,33 @@ or $ bower install sua.js ``` -## Feature +## 🎬 Quick Start + +Browser + +```html + +``` + +NodeJS + +```js +var SUA = require('sua.js'); +var sua = new SUA('Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1'); +if (!!sua.ios11) { + // OK!! +} +``` + +## ✨ Feature Supported Browsers @@ -72,68 +100,29 @@ Supported Browsers - [x] ua.vivaldi - [x] ua.wiiu (Wii U) - [x] ua.nintendo_switch (Nintendo Switch) +- [x] ua.chromecast +- [x] ua.roku.ultra +- [x] ua.amazon.4k +- [x] ua.fire.tv +- [x] ua.google.nexus.player +- [x] ua.apple.tv +- [x] ua.playstation.3 +- [x] ua.playstation.4 -## Usage - -#### example iOS 11 - -``` - ``` - -#### example detail view! - - +sua.js (size: 14K) +sua.min.js (size: 5.2K) minified with uglify2 ``` - -``` - -## File size - -``` -sua.js (size: 12,935 byte) -sua.min.js (size: 4,497 byte) minified with uglify2 -``` - -## Debug -### Build +## 🏗 Build ```sh $ make build # output: sua.min.js ``` -### Test +## 🐛 Test ``` Browser : $ ./spec/index.html @@ -141,6 +130,6 @@ Browser : $ ./spec/index.html Terminal : $ make test ``` -## License +## 📄 License @see : [LICENSE](https://github.com/fkei/sua.js/blob/master/LICENSE) diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..a3247f9 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,423 @@ +{ + "name": "sua.js", + "version": "2.3.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "assertion-error": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", + "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==" + }, + "balanced-match": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" + }, + "brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "browser-stdout": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz", + "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==" + }, + "chai": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chai/-/chai-4.1.2.tgz", + "integrity": "sha1-D2RYS6ZC8PKs4oBiefTwbKI61zw=", + "requires": { + "assertion-error": "^1.0.1", + "check-error": "^1.0.1", + "deep-eql": "^3.0.0", + "get-func-name": "^2.0.0", + "pathval": "^1.0.0", + "type-detect": "^4.0.0" + } + }, + "check-error": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz", + "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=" + }, + "cli": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/cli/-/cli-1.0.1.tgz", + "integrity": "sha1-IoF1NPJL+klQw01TLUjsvGIbjBQ=", + "requires": { + "exit": "0.1.2", + "glob": "^7.1.1" + } + }, + "commander": { + "version": "2.15.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.15.1.tgz", + "integrity": "sha512-VlfT9F3V0v+jr4yxPc5gg9s62/fIVWsd2Bk2iD435um1NlGMYdVCq+MjcXnhYq2icNOizHr1kK+5TI6H0Hy0ag==" + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" + }, + "console-browserify": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/console-browserify/-/console-browserify-1.1.0.tgz", + "integrity": "sha1-8CQcRXMKn8YyOyBtvzjtx0HQuxA=", + "requires": { + "date-now": "^0.1.4" + } + }, + "core-util-is": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" + }, + "date-now": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/date-now/-/date-now-0.1.4.tgz", + "integrity": "sha1-6vQ5/U1ISK105cx9vvIAZyueNFs=" + }, + "debug": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "requires": { + "ms": "2.0.0" + } + }, + "deep-eql": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz", + "integrity": "sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==", + "requires": { + "type-detect": "^4.0.0" + } + }, + "diff": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", + "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==" + }, + "dom-serializer": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.1.0.tgz", + "integrity": "sha1-BzxpdUbOB4DOI75KKOKT5AvDDII=", + "requires": { + "domelementtype": "~1.1.1", + "entities": "~1.1.1" + }, + "dependencies": { + "domelementtype": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-1.1.3.tgz", + "integrity": "sha1-vSh3PiZCiBrsUVRJJCmcXNgiGFs=" + }, + "entities": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/entities/-/entities-1.1.1.tgz", + "integrity": "sha1-blwtClYhtdra7O+AuQ7ftc13cvA=" + } + } + }, + "domelementtype": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-1.3.0.tgz", + "integrity": "sha1-sXrtguirWeUt2cGbF1bg/BhyBMI=" + }, + "domhandler": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-2.3.0.tgz", + "integrity": "sha1-LeWaCCLVAn+r/28DLCsloqir5zg=", + "requires": { + "domelementtype": "1" + } + }, + "domutils": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/domutils/-/domutils-1.5.1.tgz", + "integrity": "sha1-3NhIiib1Y9YQeeSMn3t+Mjc2gs8=", + "requires": { + "dom-serializer": "0", + "domelementtype": "1" + } + }, + "entities": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-1.0.0.tgz", + "integrity": "sha1-sph6o4ITR/zeZCsk/fyeT7cSvyY=" + }, + "escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" + }, + "exit": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/exit/-/exit-0.1.2.tgz", + "integrity": "sha1-BjJjj42HfMghB9MKD/8aF8uhzQw=" + }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" + }, + "get-func-name": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz", + "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=" + }, + "glob": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", + "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "growl": { + "version": "1.10.5", + "resolved": "https://registry.npmjs.org/growl/-/growl-1.10.5.tgz", + "integrity": "sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA==" + }, + "has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=" + }, + "he": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz", + "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=" + }, + "htmlparser2": { + "version": "3.8.3", + "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.8.3.tgz", + "integrity": "sha1-mWwosZFRaovoZQGn15dX5ccMEGg=", + "requires": { + "domelementtype": "1", + "domhandler": "2.3", + "domutils": "1.5", + "entities": "1.0", + "readable-stream": "1.1" + } + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" + }, + "isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=" + }, + "jshint": { + "version": "2.9.5", + "resolved": "https://registry.npmjs.org/jshint/-/jshint-2.9.5.tgz", + "integrity": "sha1-HnJSkVzmgbQIJ+4UJIxG006apiw=", + "requires": { + "cli": "~1.0.0", + "console-browserify": "1.1.x", + "exit": "0.1.x", + "htmlparser2": "3.8.x", + "lodash": "3.7.x", + "minimatch": "~3.0.2", + "shelljs": "0.3.x", + "strip-json-comments": "1.0.x" + } + }, + "lodash": { + "version": "3.7.0", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-3.7.0.tgz", + "integrity": "sha1-Nni9irmVBXwHreg27S7wh9qBHUU=" + }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "minimist": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" + }, + "mkdirp": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "requires": { + "minimist": "0.0.8" + } + }, + "mocha": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-5.2.0.tgz", + "integrity": "sha512-2IUgKDhc3J7Uug+FxMXuqIyYzH7gJjXECKe/w43IGgQHTSj3InJi+yAA7T24L9bQMRKiUEHxEX37G5JpVUGLcQ==", + "requires": { + "browser-stdout": "1.3.1", + "commander": "2.15.1", + "debug": "3.1.0", + "diff": "3.5.0", + "escape-string-regexp": "1.0.5", + "glob": "7.1.2", + "growl": "1.10.5", + "he": "1.1.1", + "minimatch": "3.0.4", + "mkdirp": "0.5.1", + "supports-color": "5.4.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "requires": { + "wrappy": "1" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" + }, + "pathval": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz", + "integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA=" + }, + "readable-stream": { + "version": "1.1.14", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", + "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.1", + "isarray": "0.0.1", + "string_decoder": "~0.10.x" + } + }, + "shelljs": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.3.0.tgz", + "integrity": "sha1-NZbmMHp4FUT1kfN9phg2DzHbV7E=" + }, + "should": { + "version": "13.2.1", + "resolved": "https://registry.npmjs.org/should/-/should-13.2.1.tgz", + "integrity": "sha512-l+/NwEMO+DcstsHEwPHRHzC9j4UOE3VQwJGcMWSsD/vqpqHbnQ+1iSHy64Ihmmjx1uiRPD9pFadTSc3MJtXAgw==", + "requires": { + "should-equal": "^2.0.0", + "should-format": "^3.0.3", + "should-type": "^1.4.0", + "should-type-adaptors": "^1.0.1", + "should-util": "^1.0.0" + } + }, + "should-equal": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/should-equal/-/should-equal-2.0.0.tgz", + "integrity": "sha512-ZP36TMrK9euEuWQYBig9W55WPC7uo37qzAEmbjHz4gfyuXrEUgF8cUvQVO+w+d3OMfPvSRQJ22lSm8MQJ43LTA==", + "requires": { + "should-type": "^1.4.0" + } + }, + "should-format": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/should-format/-/should-format-3.0.3.tgz", + "integrity": "sha1-m/yPdPo5IFxT04w01xcwPidxJPE=", + "requires": { + "should-type": "^1.3.0", + "should-type-adaptors": "^1.0.1" + } + }, + "should-type": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/should-type/-/should-type-1.4.0.tgz", + "integrity": "sha1-B1bYzoRt/QmEOmlHcZ36DUz/XPM=" + }, + "should-type-adaptors": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/should-type-adaptors/-/should-type-adaptors-1.1.0.tgz", + "integrity": "sha512-JA4hdoLnN+kebEp2Vs8eBe9g7uy0zbRo+RMcU0EsNy+R+k049Ki+N5tT5Jagst2g7EAja+euFuoXFCa8vIklfA==", + "requires": { + "should-type": "^1.3.0", + "should-util": "^1.0.0" + } + }, + "should-util": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/should-util/-/should-util-1.0.0.tgz", + "integrity": "sha1-yYzaN0qmsZDfi6h8mInCtNtiAGM=" + }, + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==" + }, + "string_decoder": { + "version": "0.10.31", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", + "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=" + }, + "strip-json-comments": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-1.0.4.tgz", + "integrity": "sha1-HhX7ysl9Pumb8tc7TGVrCCu6+5E=" + }, + "supports-color": { + "version": "5.4.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.4.0.tgz", + "integrity": "sha512-zjaXglF5nnWpsq470jSv6P9DwPvgLkuapYmfDm3JWOm0vkNTVF2tI4UrN2r6jH1qM/uc/WtxYY1hYoA2dOKj5w==", + "requires": { + "has-flag": "^3.0.0" + } + }, + "type-detect": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", + "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==" + }, + "uglify-js": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.4.0.tgz", + "integrity": "sha512-Jcf5naPkX3rVPSQpRn9Vm6Rr572I1gTtR9LnqKgXjmOgfYQ/QS0V2WRStFR53Bdj520M66aCZqt9uzYXgtGrJQ==", + "requires": { + "commander": "~2.15.0", + "source-map": "~0.6.1" + } + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" + } + } +} diff --git a/package.json b/package.json index ee3d1c2..3d823d7 100644 --- a/package.json +++ b/package.json @@ -1,40 +1,34 @@ { - "name": "sua.js", - "version": "2.2.0", - "description": "Simple user agent detection library.", - "license": "MIT", - "keywords": [ - "browser" - ], - "scripts": { - "test": "mocha tests/*.js" - }, - "homepage": "https://github.com/fkei/sua.js", - "bugs": { - "email": "kei.topaz@gmail.com", - "url": "https://github.com/fkei/sua.js/issues" - }, - "author": { - "name": "Kei Funagayama", - "email": "kei.topaz@gmail.com", - "url": "https://github.com/fkei" - }, - "repository": { - "type": "git", - "url": "git@github.com:fkei/sua.js.git" - }, - "dependencies": { - "uglify-js": "*" - }, - "devDependencies": { - "mocha": ">=1.0.1", - "chai": ">=1.8.0", - "should": ">=0.6.1", - "jshint": ">=0.7.0" - }, - "engines": { - "node": ">=0.12.0", - "npm": ">=2.5.0" - }, - "main": "./sua.js" + "name": "sua.js", + "version": "2.3.0", + "description": "Simple user agent detection library.", + "license": "MIT", + "keywords": [ + "browser" + ], + "scripts": { + "test": "mocha --recursive tests --timeout 10000 --exit" + }, + "homepage": "https://github.com/fkei/sua.js", + "bugs": { + "email": "kei.topaz@gmail.com", + "url": "https://github.com/fkei/sua.js/issues" + }, + "author": { + "name": "Kei Funagayama", + "email": "kei.topaz@gmail.com", + "url": "https://github.com/fkei" + }, + "repository": { + "type": "git", + "url": "git@github.com:fkei/sua.js.git" + }, + "main": "./sua.js", + "dependencies": { + "chai": "^4.1.2", + "jshint": "^2.9.5", + "mocha": "^5.2.0", + "should": "^13.2.1", + "uglify-js": "^3.4.0" + } } \ No newline at end of file diff --git a/setver b/setver index d5c7051..8779e29 100755 --- a/setver +++ b/setver @@ -12,7 +12,7 @@ for (var i = 0; i < list.length; i++) { var file = list[i]; var data = JSON.parse(fs.readFileSync(file, 'utf-8')); data.version = VERSION; - data = JSON.stringify(data, null, ' '); + data = JSON.stringify(data, null, ' '); fs.writeFileSync(file, data, 'utf-8'); console.log('set version:', VERSION, 'file:', file); } diff --git a/sua.js b/sua.js index 9800c98..5a8ab86 100644 --- a/sua.js +++ b/sua.js @@ -30,253 +30,283 @@ * @memberof ua * @return {Boolean} */ - this.ie = !!(useragent.indexOf('MSIE') >= 0 || useragent.indexOf('Trident') >= 0 || useragent.indexOf('Edge') >= 0), - - /** - * Decision: webkit - * @name webkit - * @memberof ua - * @return {Array} - */ - this.webkit = useragent.match(/(WebKit|Webkit)\/([\d.]+)/), - /** - * Decision: android - * @name android - * @memberof ua - * @return {Array} - */ - this.android = useragent.match(/(Android)\s+([\d.]+)/), - /** - * Decision: android2.3 - * @name android - * @memberof ua - * @return {Array} - */ - this.android23 = useragent.match(/(Android)\s+(2\.3)([\d.]+)/), - /** - * Decision: android4.x - * @name android - * @memberof ua - * @return {Array} - */ - this.android4 = useragent.match(/(Android)\s+(4)([\d.]+)/), - /** - * Decision: android5.x - * @name android - * @memberof ua - * @return {Array} - */ - this.android5 = useragent.match(/(Android)\s+(5)([\d.]+)/), - /** - * Decision: android6.x - * @name android - * @memberof ua - * @return {Array} - */ - this.android6 = useragent.match(/(Android)\s+(6)([\d.]+)/), - /** - * Decision: android7.x - * @name android - * @memberof ua - * @return {Array} - */ - this.android7 = useragent.match(/(Android)\s+(7)([\d.]+)/), - /** - * Decision: android8.x - * @name android - * @memberof ua - * @return {Array} - */ - this.android8 = useragent.match(/(Android)\s+(8)([\d.]+)/), - /** - * Decision: ipad - * @name ipad - * @memberof ua - * @return {Array} - */ - this.ipad = useragent.match(/(iPad).*OS\s([\d_]+)/), - /** - * Decision: iphone - * @name iphone - * @memberof ua - * @return {Array} - */ - this.iphone = !this.ipad && useragent.match(/(iPhone\sOS)\s([\d_]+)/), - - /** - * Decision: webos - * @name webos - * @memberof ua - * @return {Array} - */ - this.webos = useragent.match(/(webOS|hpwOS)[\s\/]([\d.]+)/), - /** - * Decision: touchpad - * @name touchpad - * @memberof ua - * @return {Array} - */ - this.touchpad = this.webos && useragent.match(/TouchPad/), - /** - * Decision: kindle - * @name kindle - * @memberof ua - * @return {Array} - */ - //this.kindle = useragent.match(/Kindle\/([\d.]+)/), - this.kindle = useragent.match(/(Kindle)/), - /** - * Decision: silk - * @name silk - * @memberof ua - * @return {Array} - */ - //this.silk = useragent.match(/Silk\/([\d._]+)/), - this.silk = useragent.match(/(Silk)/), - - /** - * Decision: blackberry - * @name blackberry - * @memberof ua - * @return {Array} - */ - //this.blackberry = useragent.match(/(BlackBerry).*Version\/([\d.]+)/), - this.blackberry = useragent.match(/(BlackBerry).*/), - - /** - * Decision: bb10 - * @name bb10 - * @memberof ua - * @return {Array} - */ - this.bb10 = useragent.match(/(BB10).*Version\/([\d.]+)/), - /** - * Decision: rimtabletos - * @name rimtabletos - * @memberof ua - * @return {Array} - */ - this.rimtabletos = useragent.match(/(RIM\sTablet\sOS)\s([\d.]+)/), - /** - * Decision: playbook - * @name playbook - * @memberof ua - * @return {Array} - */ - this.playbook = useragent.match(/PlayBook/), - /** - * Decision: chrome - * @name chrome - * @memberof ua - * @return {Array} - */ - this.chrome = useragent.match(/Chrome\/([\d.]+)/) || useragent.match(/CriOS\/([\d.]+)/), - /** - * Decision: firefox - * @name firefox - * @memberof ua - * @return {Array} - */ - this.firefox = useragent.match(/Firefox\/([\d.]+)/), - /** - * Decision: wii - * @name wii - * @memberof ua - * @return {Array} - */ - this.wii = useragent.match(/Nintendo (Wii);/), - /** - * Decision: Wii U - * @name wii - * @memberof ua - * @return {Array} - */ - this.wiiu = useragent.match(/Nintendo (WiiU)/), - - /** - * Decision: ds - * @name ds - * @memberof ua - * @return {Array} - */ - this.ds = useragent.match(/Nintendo (DS|3DS|DSi);/), - - /** - * Decision: Nintendo Switch - * @name nintendo_switch - * @memberof ua - * @return {Array} - */ - this.nintendo_switch = useragent.match(/Nintendo (Switch);/), - /** - * Decision: ps3 - * @name ps3 - * @memberof ua - * @return {Array} - */ - this.ps3 = useragent.match(/PLAYSTATION 3/), - /** - * Decision: psp - * @name psp - * @memberof ua - * @return {Array} - */ - this.psp = useragent.match(/(PlayStation Portable)/), - /** - * Decision: psvita - * @name psvita - * @memberof ua - * @return {Array} - */ - this.psvita = useragent.match(/(PlayStation Vita)/), - /** - * Decision: Windows Phone - * @name windowsphone - * @memberof ua - * @return {Array} - */ - this.windowsphone = useragent.match(/(Windows Phone |Windows Phone OS )([\d.]+)/), - /** - * Decision: safari - * @name safari - * @memberof ua - * @return {Array} - */ - this.safari = useragent.match(/(Version)\/([0-9\.]+).*Safari\/([0-9\.]+)/), - /** - * Decision: trident - * @name trident - * @memberof ua - * @return {Array} - */ - this.trident = useragent.match(/Trident\/([\d\.]+)/), - /** - * Decision: xbox - * @name xbox - * @memberof ua - * @return {Array} - */ - this.xbox = useragent.match(/Xbox/), - - /** - * Decision: iphone5 - * ToDo: need to check the evaluation method again after the release of iPhone5S(and later version) - * @name iphone5 - * @memberof ua - * @return {boolean} - */ - this.iphone5 = !(typeof module !== 'undefined' && module.exports) && this.iphone && screen && screen.width === 320 && screen.height === 568, - - /** - * Decision: Vivaldi - * @name vivaldi - * @memberof ua - * @return {Array} - */ - this.vivaldi = useragent.match(/Vivaldi\/([\d.]+)/) - - ; + this.ie = !!(useragent.indexOf('MSIE') >= 0 || useragent.indexOf('Trident') >= 0 || useragent.indexOf('Edge') >= 0); + /** + * Decision: webkit + * @name webkit + * @memberof ua + * @return {Array} + */ + this.webkit = useragent.match(/(WebKit|Webkit)\/([\d.]+)/); + + /** + * Decision: android + * @name android + * @memberof ua + * @return {Array} + */ + this.android = useragent.match(/(Android)\s+([\d.]+)/); + + /** + * Decision: android2.3 + * @name android + * @memberof ua + * @return {Array} + */ + this.android23 = useragent.match(/(Android)\s+(2\.3)([\d.]+)/); + + /** + * Decision: android4.x + * @name android + * @memberof ua + * @return {Array} + */ + this.android4 = useragent.match(/(Android)\s+(4)([\d.]+)/); + + /** + * Decision: android5.x + * @name android + * @memberof ua + * @return {Array} + */ + this.android5 = useragent.match(/(Android)\s+(5)([\d.]+)/); + + /** + * Decision: android6.x + * @name android + * @memberof ua + * @return {Array} + */ + this.android6 = useragent.match(/(Android)\s+(6)([\d.]+)/); + + /** + * Decision: android7.x + * @name android + * @memberof ua + * @return {Array} + */ + this.android7 = useragent.match(/(Android)\s+(7)([\d.]+)/); + + /** + * Decision: android8.x + * @name android + * @memberof ua + * @return {Array} + */ + this.android8 = useragent.match(/(Android)\s+(8)([\d.]+)/); + + /** + * Decision: ipad + * @name ipad + * @memberof ua + * @return {Array} + */ + this.ipad = useragent.match(/(iPad).*OS\s([\d_]+)/); + + /** + * Decision: iphone + * @name iphone + * @memberof ua + * @return {Array} + */ + this.iphone = !this.ipad && useragent.match(/(iPhone\sOS)\s([\d_]+)/); + + /** + * Decision: webos + * @name webos + * @memberof ua + * @return {Array} + */ + this.webos = useragent.match(/(webOS|hpwOS)[\s\/]([\d.]+)/); + + /** + * Decision: touchpad + * @name touchpad + * @memberof ua + * @return {Array} + */ + this.touchpad = this.webos && useragent.match(/TouchPad/); + + /** + * Decision: kindle + * @name kindle + * @memberof ua + * @return {Array} + */ + //this.kindle = useragent.match(/Kindle\/([\d.]+)/), + this.kindle = useragent.match(/(Kindle)/); + + /** + * Decision: silk + * @name silk + * @memberof ua + * @return {Array} + */ + //this.silk = useragent.match(/Silk\/([\d._]+)/), + this.silk = useragent.match(/(Silk)/); + + /** + * Decision: blackberry + * @name blackberry + * @memberof ua + * @return {Array} + */ + //this.blackberry = useragent.match(/(BlackBerry).*Version\/([\d.]+)/); + this.blackberry = useragent.match(/(BlackBerry).*/); + + /** + * Decision: bb10 + * @name bb10 + * @memberof ua + * @return {Array} + */ + this.bb10 = useragent.match(/(BB10).*Version\/([\d.]+)/); + + /** + * Decision: rimtabletos + * @name rimtabletos + * @memberof ua + * @return {Array} + */ + this.rimtabletos = useragent.match(/(RIM\sTablet\sOS)\s([\d.]+)/); + + /** + * Decision: playbook + * @name playbook + * @memberof ua + * @return {Array} + */ + this.playbook = useragent.match(/PlayBook/); + + /** + * Decision: chrome + * @name chrome + * @memberof ua + * @return {Array} + */ + this.chrome = useragent.match(/Chrome\/([\d.]+)/) || useragent.match(/CriOS\/([\d.]+)/); + + /** + * Decision: firefox + * @name firefox + * @memberof ua + * @return {Array} + */ + this.firefox = useragent.match(/Firefox\/([\d.]+)/); + + /** + * Decision: wii + * @name wii + * @memberof ua + * @return {Array} + */ + this.wii = useragent.match(/Nintendo (Wii);/); + + /** + * Decision: Wii U + * @name wii + * @memberof ua + * @return {Array} + */ + this.wiiu = useragent.match(/Nintendo (WiiU)/); + + /** + * Decision: ds + * @name ds + * @memberof ua + * @return {Array} + */ + this.ds = useragent.match(/Nintendo (DS|3DS|DSi);/); + + /** + * Decision: Nintendo Switch + * @name nintendo_switch + * @memberof ua + * @return {Array} + */ + this.nintendo_switch = useragent.match(/Nintendo (Switch);/); + + /** + * Decision: Play Station 3 + * @name ps3 + * @memberof ua + * @return {Array} + */ + this.ps3 = useragent.match(/PLAYSTATION 3/i); + + /** + * Decision: Play Station 4 + * @name ps4 + * @memberof ua + * @return {Array} + */ + this.ps4 = useragent.match(/PLAYSTATION 4/i); + + /** + * Decision: psp + * @name psp + * @memberof ua + * @return {Array} + */ + this.psp = useragent.match(/(PlayStation Portable)/); + + /** + * Decision: psvita + * @name psvita + * @memberof ua + * @return {Array} + */ + this.psvita = useragent.match(/(PlayStation Vita)/); + + /** + * Decision: Windows Phone + * @name windowsphone + * @memberof ua + * @return {Array} + */ + this.windowsphone = useragent.match(/(Windows Phone |Windows Phone OS )([\d.]+)/); + + /** + * Decision: safari + * @name safari + * @memberof ua + * @return {Array} + */ + this.safari = useragent.match(/(Version)\/([0-9\.]+).*Safari\/([0-9\.]+)/); + + /** + * Decision: trident + * @name trident + * @memberof ua + * @return {Array} + */ + this.trident = useragent.match(/Trident\/([\d\.]+)/); + + /** + * Decision: xbox + * @name xbox + * @memberof ua + * @return {Array} + */ + this.xbox = useragent.match(/Xbox/i); + + /** + * Decision: iphone5 + * ToDo: need to check the evaluation method again after the release of iPhone5S(and later version) + * @name iphone5 + * @memberof ua + * @return {boolean} + */ + this.iphone5 = !(typeof module !== 'undefined' && module.exports) && this.iphone && screen && screen.width === 320 && screen.height === 568; + + /** + * Decision: Vivaldi + * @name vivaldi + * @memberof ua + * @return {Array} + */ + this.vivaldi = useragent.match(/Vivaldi\/([\d.]+)/); /** * Decision: iphone3 @@ -286,6 +316,79 @@ */ this.iphone3 = this.iphone && global.devicePixelRatio === 1 ? true : false; + /** + * Decision: Chrome Cast + * @name chromecast + * @memberof ua + * @return {Array} + */ + this.chromecast = useragent.match(/CrKey/); + + /** + * Decision: Roku + * @name roku + * @memberof ua + * @return {Array} + */ + this.roku = useragent.match(/Roku([\w.]+)/); + + /** + * Decision: Amazon Fire TV Gen 1 (AFTB) + * @name firetv1 + * @memberof ua + * @return {Array} + */ + this.firetv1 = useragent.match(/AFTB/); + + /** + * Decision: Amazon Fire TV Gen 2 (AFTAFTSB) + * @name firetv2 + * @memberof ua + * @return {Array} + */ + this.firetv2 = useragent.match(/AFTS/); + + /** + * Decision: Amazon Fire TV Stick Gen 1 (AFTM) + * @name firetvstick1 + * @memberof ua + * @return {Array} + */ + this.firetvstick1 = useragent.match(/AFTM/); + + /** + * Decision: Amazon Fire TV Stick Gen 2 (AFTT) + * @name firetvstick2 + * @memberof ua + * @return {Array} + */ + this.firetvstick2 = useragent.match(/AFTT/); + + /** + * Decision: Amazon Fire TV Series + * @name firetv + * @memberof ua + * @return {Array} + */ + this.firetv = !!this.firetv1 || !!this.firetv2 || !!this.firetvstick1 || !!this.firetvstick2; + + /** + * Decision: Nexus Player + * @name nexusplayer + * @memberof ua + * @return {Array} + */ + this.nexusplayer = useragent.match(/Nexus Player/); + + /** + * Decision: Apple TV + * @name appletv + * @memberof ua + * @return {Array} + */ + this.appletv = useragent.match(/AppleTV/); + + ///////////////////////////////////// /** * browser information @@ -328,6 +431,7 @@ //console.log('Failed to parse user agent string of Android.', useragent); } } + if (this.iphone) { this.os.ios = this.os.iphone = true; this.os.version = this.iphone[2].replace(/_/g, '.'); @@ -456,7 +560,7 @@ * @return {boolean} */ this.os.phone = !!(!this.os.tablet && (this.android || this.iphone || this.webos || this.blackberry || this.bb10 || - (this.chrome && useragent.match(/Android/)) || (this.chrome && useragent.match(/CriOS\/([\d.]+)/)) || (this.firefox && useragent.match(/Mobile/)) || (this.windowsphone && useragent.match(/IEMobile/)))); + (this.chrome && useragent.match(/Android/)) || (this.chrome && useragent.match(/CriOS\/([\d.]+)/)) || (this.firefox && useragent.match(/Mobile/)) || (this.windowsphone && useragent.match(/IEMobile/)))); /** * Decision mobile (tablet or phone) @@ -476,7 +580,7 @@ } } - SUA.VERSION = '2.2.0'; + SUA.VERSION = '2.3.0'; if (typeof module !== 'undefined' && module.exports) { // node diff --git a/sua.min.js b/sua.min.js index b238a46..3eb22eb 100644 --- a/sua.min.js +++ b/sua.min.js @@ -1,6 +1,6 @@ /** * @name sua.min.js - * @version 2.2.0 + * @version 2.3.0 * @overview Simple user agent detection library. */ -!function(i){"use strict";function s(s){if(!s&&i&&i.navigator&&i.navigator.userAgent&&(s=i.navigator.userAgent),!s)throw new Error("useragent setup error. useragent not found.");if(this.ie=!!(s.indexOf("MSIE")>=0||s.indexOf("Trident")>=0||s.indexOf("Edge")>=0),this.webkit=s.match(/(WebKit|Webkit)\/([\d.]+)/),this.android=s.match(/(Android)\s+([\d.]+)/),this.android23=s.match(/(Android)\s+(2\.3)([\d.]+)/),this.android4=s.match(/(Android)\s+(4)([\d.]+)/),this.android5=s.match(/(Android)\s+(5)([\d.]+)/),this.android6=s.match(/(Android)\s+(6)([\d.]+)/),this.android7=s.match(/(Android)\s+(7)([\d.]+)/),this.android8=s.match(/(Android)\s+(8)([\d.]+)/),this.ipad=s.match(/(iPad).*OS\s([\d_]+)/),this.iphone=!this.ipad&&s.match(/(iPhone\sOS)\s([\d_]+)/),this.webos=s.match(/(webOS|hpwOS)[\s\/]([\d.]+)/),this.touchpad=this.webos&&s.match(/TouchPad/),this.kindle=s.match(/(Kindle)/),this.silk=s.match(/(Silk)/),this.blackberry=s.match(/(BlackBerry).*/),this.bb10=s.match(/(BB10).*Version\/([\d.]+)/),this.rimtabletos=s.match(/(RIM\sTablet\sOS)\s([\d.]+)/),this.playbook=s.match(/PlayBook/),this.chrome=s.match(/Chrome\/([\d.]+)/)||s.match(/CriOS\/([\d.]+)/),this.firefox=s.match(/Firefox\/([\d.]+)/),this.wii=s.match(/Nintendo (Wii);/),this.wiiu=s.match(/Nintendo (WiiU)/),this.ds=s.match(/Nintendo (DS|3DS|DSi);/),this.nintendo_switch=s.match(/Nintendo (Switch);/),this.ps3=s.match(/PLAYSTATION 3/),this.psp=s.match(/(PlayStation Portable)/),this.psvita=s.match(/(PlayStation Vita)/),this.windowsphone=s.match(/(Windows Phone |Windows Phone OS )([\d.]+)/),this.safari=s.match(/(Version)\/([0-9\.]+).*Safari\/([0-9\.]+)/),this.trident=s.match(/Trident\/([\d\.]+)/),this.xbox=s.match(/Xbox/),this.iphone5=!("undefined"!=typeof module&&module.exports)&&this.iphone&&screen&&320===screen.width&&568===screen.height,this.vivaldi=s.match(/Vivaldi\/([\d.]+)/),this.iphone3=!(!this.iphone||1!==i.devicePixelRatio),this.browser={locale:void 0,lang:void 0,country:void 0},this.os={},this.webkit&&!this.ie&&(this.browser.webkit=!0,this.browser.version=this.webkit[1]),this.trident&&(this.browser.trident=!0,this.browser.version=this.trident[1]),this.android){this.os.android=!0,this.os.version=this.android[2];try{this.browser.locale=s.match(/(Android)\s(.+);\s([^;]+);/)[3],this.browser.lang=this.browser.locale.substring(0,2),this.browser.country=this.browser.locale.substring(3)}catch(i){}}if(this.iphone&&(this.os.ios=this.os.iphone=!0,this.os.version=this.iphone[2].replace(/_/g,".")),this.ipad&&(this.os.ios=this.os.ipad=!0,this.os.version=this.ipad[2].replace(/_/g,".")),this.os.ios){var t=null;this.os.version&&(t=this.os.version.split(".")[0]);for(var h=3;h<12;h++)this["ios"+h]=t===""+h}this.webos&&(this.os.webos=!0,this.os.version=this.webos[2]),this.touchpad&&(this.os.touchpad=!0),this.blackberry&&(this.os.blackberry=!0),this.bb10&&(this.os.bb10=!0,this.os.version=this.bb10[2]),this.rimtabletos&&(this.os.rimtabletos=!0,this.os.version=this.rimtabletos[2]),this.playbook&&(this.browser.playbook=!0),this.kindle&&(this.os.kindle=!0),this.silk&&(this.browser.silk=!0),!this.silk&&this.os.android&&s.match(/Kindle Fire/)&&(this.browser.silk=!0),this.chrome&&!this.ie&&(this.browser.chrome=!0,this.browser.version=this.chrome[1]),this.firefox&&(this.browser.firefox=!0,this.browser.version=this.firefox[1],s.match(/Android/)&&(this.android=["Android","Android",""])),(this.wii||this.ds||this.wiiu||this.nintendo_switch)&&(this.os.nintendo=!0,(this.wiiu||this.nintendo_switch)&&(this.browser.nintendo=s.match(/NintendoBrowser\/([\d.]+)/),this.browser.version=this.browser.nintendo[1])),this.windowsphone&&(this.browser.windowsphone=!0,this.browser.version=this.windowsphone[2]),this.safari&&(this.browser.safari=!0,this.browser.version=this.safari[2]),this.ie&&(this.browser.ie=/(MSIE|rv:?)\s?([\d\.]+)/.exec(s),this.edge=!1,this.browser.ie?this.windowsphone||(this.browser.version=this.browser.ie?this.browser.ie[2]:""):(this.browser.ie=/(Edge\/)(\d.+)/.exec(s),this.browser.version=this.browser.ie[2],this.edge=!0,this.chrome=!1,this.webkit=!1),0