diff --git a/.github/workflows/merge-to-master.yml b/.github/workflows/merge-to-master.yml new file mode 100644 index 0000000..b22b0a0 --- /dev/null +++ b/.github/workflows/merge-to-master.yml @@ -0,0 +1,37 @@ +name: 'Merge to master' + +on: + push: + branches: [master] + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [12.16.3] + + steps: + - name: Get branch name (merge) + if: github.event_name != 'pull_request' + shell: bash + run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_ENV + + - name: Get branch name (pull request) + if: github.event_name == 'pull_request' + shell: bash + run: echo "BRANCH_NAME=$(echo ${GITHUB_HEAD_REF} | tr / -)" >> $GITHUB_ENV + + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: npm ci + - run: npm run build + - run: nyc npm test && nyc report --reporter=text-lcov | ./node_modules/coveralls/bin/coveralls.js + env: + COVERALLS_SERVICE_NAME: GithubActions + COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} + COVERALLS_GIT_BRANCH: ${{ env.BRANCH_NAME }} diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml deleted file mode 100644 index 492e91c..0000000 --- a/.github/workflows/nodejs.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Node CI - -on: [push] - -jobs: - build: - - runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [12.16.3] - - steps: - - uses: actions/checkout@v1 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - name: npm ci, build, and test - run: | - npm ci - npm run lint - npm run build - npm test - env: - CI: true diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml new file mode 100644 index 0000000..d326d04 --- /dev/null +++ b/.github/workflows/pull-request.yml @@ -0,0 +1,44 @@ +name: 'Pull Request' +on: + pull_request: + types: [opened, reopened, synchronize] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + node: [12.16.3] + name: Node ${{ matrix.node }} + steps: + - name: 'Checkout latest code' + uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha }} + - name: Set up node + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node }} + - name: Install dependencies + run: npm ci + - name: Build + run: npm run build + - name: Run tests + run: npm run test + + lint: + name: 'ESLint' + runs-on: ubuntu-latest + steps: + - name: Checkout latest code + uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha }} + - name: Set up node + uses: actions/setup-node@v3 + with: + node-version: '16' + - name: Install dependencies + run: npm ci + - name: Run ESLint + run: npm run lint:check diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a0a15f8..0000000 --- a/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ -language: node_js -after_success: npm run coverage -node_js: - - "12.16.3" -script: -- npm run lint -- npm run build -- npm test diff --git a/CHANGELOG.md b/CHANGELOG.md index 260a03d..b57bd6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ### 2.11.0 (Sep 12, 2020) - [ADD] Added support for aliases in `Parser#is` method (#437) - [ADD] Added more typings (#438, #427) -- [ADD] Added support for MIUI Browserr (#436) +- [ADD] Added support for MIUI Browser (#436) ### 2.10.0 (Jul 9, 2020) - [FIX] Fix for Firefox detection on iOS 13 [#415] diff --git a/index.d.ts b/index.d.ts index 49d2928..d5b72c4 100644 --- a/index.d.ts +++ b/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/lancedikson/bowser // Definitions by: Alexander P. Cerutti , -export = Bowser; +export default Bowser; export as namespace Bowser; declare namespace Bowser { @@ -34,6 +34,14 @@ declare namespace Bowser { interface Parser { constructor(UA: string, skipParsing?: boolean): Parser.Parser; + /** + * Check if the version is equals the browser version + * @param version The string to compare with the browser version + * @returns {boolean} + */ + + compareVersion(version: string): boolean; + /** * Get parsed browser object * @return {BrowserDetails} Browser's details @@ -54,7 +62,7 @@ declare namespace Bowser { * @return {String} version of browser */ - getBrowserVersion(): string; + getBrowserVersion(): string | undefined; /** * Get OS @@ -136,6 +144,39 @@ declare namespace Bowser { is(anything: any, includingAlias?: boolean): boolean; + /** + * Check if the browser name equals the passed string + * @param browserName The string to compare with the browser name + * @param [includingAlias=false] The flag showing whether alias will be included into comparison + * @returns {boolean} + */ + + isBrowser(browserName: string, includingAlias?: boolean): boolean; + + /** + * Check if the engine name equals the passed string + * @param engineName The string to compare with the engine name + * @returns {boolean} + */ + + isEngine(engineName: string): boolean; + + /** + * Check if the OS name equals the passed string + * @param OSName The string to compare with the OS name + * @returns {boolean} + */ + + isOS(OSName: string): boolean; + + /** + * Check if the platform name equals the passed string + * @param platformName The string to compare with the platform name + * @returns {boolean} + */ + + isPlatform(platformName: string): boolean; + /** * Parse full information about the browser * @returns {Parser.Parser} diff --git a/package.json b/package.json index 3fb7c83..c719065 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,8 @@ "generate-and-deploy-docs": "npm run generate-docs && gh-pages --dist docs --dest docs", "watch": "webpack --watch --config webpack.config.js", "prepublishOnly": "npm run build", - "lint": "eslint ./src", + "lint:check": "eslint ./src", + "lint:fix": "eslint --fix ./src", "testem": "testem", "test": "nyc --reporter=html --reporter=text ava", "test:watch": "ava --watch", diff --git a/src/constants.js b/src/constants.js index f335032..db9fda3 100644 --- a/src/constants.js +++ b/src/constants.js @@ -22,6 +22,7 @@ export const BROWSER_ALIASES_MAP = { 'NAVER Whale Browser': 'naver', Opera: 'opera', 'Opera Coast': 'opera_coast', + 'Pale Moon': 'pale_moon', PhantomJS: 'phantomjs', Puffin: 'puffin', QupZilla: 'qupzilla', @@ -64,6 +65,7 @@ export const BROWSER_MAP = { naver: 'NAVER Whale Browser', opera: 'Opera', opera_coast: 'Opera Coast', + pale_moon: 'Pale Moon', phantomjs: 'PhantomJS', puffin: 'Puffin', qupzilla: 'QupZilla', diff --git a/src/parser-browsers.js b/src/parser-browsers.js index ee7840c..997d724 100644 --- a/src/parser-browsers.js +++ b/src/parser-browsers.js @@ -108,6 +108,21 @@ const browsersList = [ return browser; }, }, + { + test: [/PaleMoon/i], + describe(ua) { + const browser = { + name: 'Pale Moon', + }; + const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:PaleMoon)[\s/](\d+(?:\.\d+)+)/i, ua); + + if (version) { + browser.version = version; + } + + return browser; + }, + }, { test: [/MZBrowser/i], describe(ua) { diff --git a/src/parser-platforms.js b/src/parser-platforms.js index 48b1eb1..bb3be8d 100644 --- a/src/parser-platforms.js +++ b/src/parser-platforms.js @@ -130,6 +130,22 @@ export default [ }, }, + /* Nokia */ + { + test: [/Nokia/i], + describe(ua) { + const model = Utils.getFirstMatch(/Nokia\s+([0-9]+(\.[0-9]+)?)/i, ua); + const platform = { + type: PLATFORMS_MAP.mobile, + vendor: 'Nokia', + }; + if (model) { + platform.model = model; + } + return platform; + }, + }, + /* Mobile */ { test: [/[^-]mobi/i], diff --git a/src/parser.js b/src/parser.js index 78ee69c..db10657 100644 --- a/src/parser.js +++ b/src/parser.js @@ -87,7 +87,7 @@ class Parser { return _browser.test(this); } - if (_browser.test instanceof Array) { + if (Array.isArray(_browser.test)) { return _browser.test.some(condition => this.test(condition)); } @@ -170,7 +170,7 @@ class Parser { return _os.test(this); } - if (_os.test instanceof Array) { + if (Array.isArray(_os.test)) { return _os.test.some(condition => this.test(condition)); } @@ -246,7 +246,7 @@ class Parser { return _platform.test(this); } - if (_platform.test instanceof Array) { + if (Array.isArray(_platform.test)) { return _platform.test.some(condition => this.test(condition)); } @@ -297,7 +297,7 @@ class Parser { return _engine.test(this); } - if (_engine.test instanceof Array) { + if (Array.isArray(_engine.test)) { return _engine.test.some(condition => this.test(condition)); } diff --git a/src/utils.js b/src/utils.js index d1174bf..1ff03e9 100644 --- a/src/utils.js +++ b/src/utils.js @@ -295,10 +295,10 @@ export default class Utils { } /** - * Get short version/alias for a browser name + * Get browser name for a short version/alias * * @example - * getBrowserAlias('edge') // Microsoft Edge + * getBrowserTypeByAlias('edge') // Microsoft Edge * * @param {string} browserAlias * @return {string} diff --git a/test/acceptance/useragentstrings.yml b/test/acceptance/useragentstrings.yml index 6c9fb1a..9fedcb4 100644 --- a/test/acceptance/useragentstrings.yml +++ b/test/acceptance/useragentstrings.yml @@ -336,6 +336,35 @@ type: "tv" engine: name: "Blink" + - + ua: "Mozilla/5.0 (Linux; Android 9; Nokia 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.127 Mobile Safari/537.36" + spec: + browser: + name: "Chrome" + version: "85.0.4183.127" + os: + name: "Android" + version: "9" + versionName: "Pie" + platform: + type: "mobile" + vendor: "Nokia" + model: "5.1" + engine: + name: "Blink" + - + ua: "Mozilla/5.0 (Linux; Android 10; SM-G970F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3396.81 Mobile Safari/537.36" + spec: + browser: + name: "Chrome" + version: "75.0.3396.81" + os: + name: "Android" + version: "10" + platform: + type: "mobile" + engine: + name: "Blink" Google Search: - ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 12_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) GSA/83.0.268992909 Mobile/15E148 Safari/605.1" @@ -1391,6 +1420,7 @@ version: "8.0" platform: type: "mobile" + vendor: "Nokia" engine: name: "Trident" version: "6.0" @@ -1405,6 +1435,7 @@ version: "8.0" platform: type: "mobile" + vendor: "Nokia" engine: name: "Trident" version: "6.0" @@ -1433,6 +1464,7 @@ version: "7.0" platform: type: "mobile" + vendor: "Nokia" engine: name: "Trident" version: "3.1" @@ -3054,3 +3086,32 @@ type: "mobile" engine: name: "Blink" + Pale Moon: + - + ua: "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Goanna/4.8 Firefox/68.0 PaleMoon/29.1.1" + spec: + browser: + name: "Pale Moon" + version: "29.1.1" + os: + name: "Windows" + version: "NT 10.0" + versionName: "10" + platform: + type: "desktop" + engine: + name: "Gecko" + version: "20100101" + - + ua: "Mozilla/5.0 (X11; Linux i686; rv:45.9) Gecko/20100101 Goanna/3.2 Firefox/45.9 PaleMoon/27.2.0" + spec: + browser: + name: "Pale Moon" + version: "27.2.0" + os: + name: "Linux" + platform: + type: "desktop" + engine: + name: "Gecko" + version: "20100101"