1
0
mirror of https://github.com/lancedikson/bowser synced 2024-10-27 20:34:22 +00:00

Compare commits

...

18 Commits

Author SHA1 Message Date
Denis Demchenko
8c489bd98b
chore: move the token to secrets 2024-08-12 13:42:09 +03:00
Meir Roth
5bab4ee97d
docs: remove non-existing links in README 2024-04-28 23:42:58 +03:00
Naor Peled
16c9f22546
ci: attempt to resolve merge to master errors (#546) 2024-04-20 14:54:03 +03:00
Naor Peled
327e6f5e51
ci: add release drafter (#545) 2024-04-20 14:35:56 +03:00
pastak
0626bf8c8c
Fix link to doc page on README.md (#543) 2023-12-11 10:37:33 +02:00
Naor Peled
94ab87ec0e
feat(constants): add bot as a platform (#540) (#541)
Co-authored-by: Lucio Martinez <martinezlucio.com@gmail.com>
2023-11-27 16:21:18 +02:00
Amelie
07462efb6a
feat: update types of parser methods (#449) 2023-11-17 21:01:45 +02:00
idmadj
f8fcea59e7
docs: fix getBrowserTypeByAlias docs (#467) 2023-11-17 20:55:43 +02:00
daniol
4481f5aab3
feat: add Nokia Vendor (#448) 2023-11-17 20:54:44 +02:00
James Cleveland
0c7380dbf9
fix: use default export in type definitions (#465) 2023-11-17 20:49:07 +02:00
Mehmet Akif Yücel
bb8f94efcd
feat: add Pale Moon browser support (#495) 2023-11-17 20:47:16 +02:00
Matheus Hahn
29222b2fcf
docs: update Typescript definition file (#500) 2023-11-17 20:46:29 +02:00
Naor Peled
69bc6c2dbf
revert(workflows): rollback to Node 12.16.3 (#537) 2023-11-17 20:45:54 +02:00
Naor Peled
9c1588a43e
chore: add CodeQL config 2023-11-13 11:56:25 +02:00
Naor Peled
fefa53ad95
fix(docs): resolve typos (#528) 2023-11-13 11:11:43 +02:00
Naor Peled
efb8e612a5
ci: move to Github Actions (#530) 2023-11-13 11:11:28 +02:00
Connor Bär
b86bce16af
fix(parser): resolve issues with array detection (#516)
- this change resolves issues with Next.js middlewares
2023-11-13 11:10:39 +02:00
Denis Demchenko
f09411489c Merge tag '2.11.0'
2.11.0 2.11.0
2020-09-12 11:22:47 +03:00
18 changed files with 346 additions and 58 deletions

View File

@ -1 +1 @@
repo_token: Ba2bS7pOlSLZWuESBnff8qxDjIS8Mg1Z0

19
.github/release-drafter.yml vendored Normal file
View File

@ -0,0 +1,19 @@
name-template: 'v$RESOLVED_VERSION 🌈'
tag-template: 'v$RESOLVED_VERSION'
version-resolver:
major:
labels:
- major
minor:
labels:
- minor
patch:
labels:
- patch
default: patch
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
change-title-escapes: '\<*_&'
template: |
## Changes
$CHANGES

View File

@ -0,0 +1,20 @@
name: 📝 Draft or update next release
concurrency: draft_or_update_next_release
on:
push:
branches:
- main
workflow_dispatch:
jobs:
prepare-deployment:
name: 📝 Draft or update next release
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v1
- uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

38
.github/workflows/merge-to-master.yml vendored Normal file
View File

@ -0,0 +1,38 @@
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 i -g nyc
- 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 }}

View File

@ -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

29
.github/workflows/publish.yml vendored Normal file
View File

@ -0,0 +1,29 @@
name: Release
on:
# This job runs when a new release is published
release:
types: [published]
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
registry-url: https://registry.npmjs.org
- uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }}
# Store the name of the release
# See https://stackoverflow.com/questions/58177786/get-the-current-pushed-tag-in-github-actions
- run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- run: npm ci
- run: npm version $RELEASE_VERSION --no-git-tag-version
- run: npm run build
- run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.BOWSER_NPM_PUBLISH_TOKEN }}

44
.github/workflows/pull-request.yml vendored Normal file
View File

@ -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

View File

@ -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

View File

@ -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]

View File

@ -11,8 +11,6 @@ Don't hesitate to support the project on Github or [OpenCollective](https://open
# Contents
- [Overview](#overview)
- [Use cases](#use-cases)
- [Advanced usage](#advanced-usage)
- [How can I help?](#contributing)
# Overview
@ -20,7 +18,7 @@ The library is made to help to detect what browser your user has and gives you a
### ⚠️ Version 2.0 breaking changes ⚠️
Version 2.0 has drastically changed the API. All available methods are on the [docs page](https://lancedikson.github.io/bowser/docs).
Version 2.0 has drastically changed the API. All available methods are on the [docs page](https://bowser-js.github.io/bowser/docs/).
_For legacy code, check out the [1.x](https://github.com/lancedikson/bowser/tree/v1.x) branch and install it through `npm install bowser@1.9.4`._
@ -149,7 +147,7 @@ list of aliases can be found in [the file](src/constants.js).
### Code Contributors
This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
This project exists thanks to all the people who contribute. [[Contribute](.github/CONTRIBUTING.md)].
<a href="https://github.com/lancedikson/bowser/graphs/contributors"><img src="https://opencollective.com/bowser/contributors.svg?width=890&button=false" /></a>
### Financial Contributors

79
index.d.ts vendored
View File

@ -2,7 +2,7 @@
// Project: https://github.com/lancedikson/bowser
// Definitions by: Alexander P. Cerutti <https://github.com/alexandercerutti>,
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
@ -130,10 +138,44 @@ declare namespace Bowser {
* Is anything? Check if the browser is called "anything",
* the OS called "anything" or the platform called "anything"
* @param {String} anything
* @param [includingAlias=false] The flag showing whether alias will be included into comparison
* @returns {Boolean}
*/
is(anything: any): boolean;
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
@ -191,18 +233,41 @@ declare namespace Bowser {
satisfies(checkTree: checkTree): boolean | undefined;
/**
/**
* Check if the browser name equals the passed string
* @param browserName The string to compare with the browser name
* @param {string} 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 any of the given values satifies `.is(anything)`
* Check if the engine name equals the passed string
* @param {string} engineName The string to compare with the engine name
* @returns {boolean}
*/
isEngine(engineName: string): boolean;
/**
* Check if the platform type equals the passed string
* @param {string} platformType The string to compare with the platform type
* @returns {boolean}
*/
isPlatform(platformType: string): boolean;
/**
* Check if the OS name equals the passed string
* @param {string} osName The string to compare with the OS name
* @returns {boolean}
*/
isOS(osName: string): boolean;
/**
* Check if any of the given values satisfies `.is(anything)`
* @param {string[]} anythings
* @returns {boolean} true if at least one condition is satisfied, false otherwise.
*/

View File

@ -1,6 +1,5 @@
{
"name": "bowser",
"version": "2.11.0",
"description": "Lightweight browser detector",
"keywords": [
"browser",
@ -72,7 +71,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",

View File

@ -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',
@ -88,6 +90,7 @@ export const PLATFORMS_MAP = {
mobile: 'mobile',
desktop: 'desktop',
tv: 'tv',
bot: 'bot',
};
export const OS_MAP = {

View File

@ -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) {

View File

@ -12,7 +12,7 @@ export default [
test: [/googlebot/i],
describe() {
return {
type: 'bot',
type: PLATFORMS_MAP.bot,
vendor: 'Google',
};
},
@ -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],

View File

@ -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));
}
@ -408,7 +408,7 @@ class Parser {
/**
* Check if the browser name equals the passed string
* @param browserName The string to compare with the browser name
* @param {string} browserName The string to compare with the browser name
* @param [includingAlias=false] The flag showing whether alias will be included into comparison
* @returns {boolean}
*/
@ -459,14 +459,29 @@ class Parser {
) > -1;
}
/**
* Check if the OS name equals the passed string
* @param {string} osName The string to compare with the OS name
* @returns {boolean}
*/
isOS(osName) {
return this.getOSName(true) === String(osName).toLowerCase();
}
/**
* Check if the platform type equals the passed string
* @param {string} platformType The string to compare with the platform type
* @returns {boolean}
*/
isPlatform(platformType) {
return this.getPlatformType(true) === String(platformType).toLowerCase();
}
/**
* Check if the engine name equals the passed string
* @param {string} engineName The string to compare with the engine name
* @returns {boolean}
*/
isEngine(engineName) {
return this.getEngineName(true) === String(engineName).toLowerCase();
}

View File

@ -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}

View File

@ -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"