mirror of
https://github.com/lancedikson/bowser
synced 2025-12-05 06:02:14 +00:00
Compare commits
No commits in common. "master" and "v2.13.0" have entirely different histories.
@ -6,7 +6,7 @@ A small, fast and rich-API browser/platform/engine detector for both browser and
|
|||||||
|
|
||||||
Don't hesitate to support the project on Github or [OpenCollective](https://opencollective.com/bowser) if you like it ❤️ Also, contributors are always welcome!
|
Don't hesitate to support the project on Github or [OpenCollective](https://opencollective.com/bowser) if you like it ❤️ Also, contributors are always welcome!
|
||||||
|
|
||||||
[](https://opencollective.com/bowser) [](https://travis-ci.org/bowser-js/bowser/) [](https://greenkeeper.io/) [](https://coveralls.io/github/bowser-js/bowser?branch=master) 
|
[](https://opencollective.com/bowser) [](https://travis-ci.org/lancedikson/bowser/) [](https://greenkeeper.io/) [](https://coveralls.io/github/lancedikson/bowser?branch=master) 
|
||||||
|
|
||||||
# Contents
|
# Contents
|
||||||
- [Overview](#overview)
|
- [Overview](#overview)
|
||||||
@ -20,7 +20,7 @@ The library is made to help to detect what browser your user has and gives you a
|
|||||||
|
|
||||||
Version 2.0 has drastically changed the API. All available methods are on the [docs page](https://bowser-js.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/bowser-js/bowser/tree/v1.x) branch and install it through `npm install bowser@1.9.4`._
|
_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`._
|
||||||
|
|
||||||
# Use cases
|
# Use cases
|
||||||
|
|
||||||
@ -148,7 +148,7 @@ list of aliases can be found in [the file](src/constants.js).
|
|||||||
### Code Contributors
|
### Code Contributors
|
||||||
|
|
||||||
This project exists thanks to all the people who contribute. [[Contribute](.github/CONTRIBUTING.md)].
|
This project exists thanks to all the people who contribute. [[Contribute](.github/CONTRIBUTING.md)].
|
||||||
<a href="https://github.com/bowser-js/bowser/graphs/contributors"><img src="https://opencollective.com/bowser/contributors.svg?width=890&button=false" /></a>
|
<a href="https://github.com/lancedikson/bowser/graphs/contributors"><img src="https://opencollective.com/bowser/contributors.svg?width=890&button=false" /></a>
|
||||||
|
|
||||||
### Financial Contributors
|
### Financial Contributors
|
||||||
|
|
||||||
|
|||||||
9
index.d.ts
vendored
9
index.d.ts
vendored
@ -1,10 +1,17 @@
|
|||||||
// Type definitions for Bowser v2
|
// Type definitions for Bowser v2
|
||||||
// Project: https://github.com/bowser-js/bowser
|
// Project: https://github.com/lancedikson/bowser
|
||||||
// Definitions by: Alexander P. Cerutti <https://github.com/alexandercerutti>,
|
// Definitions by: Alexander P. Cerutti <https://github.com/alexandercerutti>,
|
||||||
|
|
||||||
export = Bowser;
|
export = Bowser;
|
||||||
export as namespace Bowser;
|
export as namespace Bowser;
|
||||||
|
|
||||||
|
export function getParser(UA: string, skipParsing?: boolean): Bowser.Parser.Parser;
|
||||||
|
export function parse(UA: string): Bowser.Parser.ParsedResult;
|
||||||
|
export const BROWSER_MAP: Record<string, string>;
|
||||||
|
export const ENGINE_MAP: Record<string, string>;
|
||||||
|
export const OS_MAP: Record<string, string>;
|
||||||
|
export const PLATFORMS_MAP: Record<string, string>;
|
||||||
|
|
||||||
declare namespace Bowser {
|
declare namespace Bowser {
|
||||||
/**
|
/**
|
||||||
* Creates a Parser instance
|
* Creates a Parser instance
|
||||||
|
|||||||
@ -11,7 +11,7 @@
|
|||||||
"ender",
|
"ender",
|
||||||
"sniff"
|
"sniff"
|
||||||
],
|
],
|
||||||
"homepage": "https://github.com/bowser-js/bowser",
|
"homepage": "https://github.com/lancedikson/bowser",
|
||||||
"author": "Dustin Diaz <dustin@dustindiaz.com> (http://dustindiaz.com)",
|
"author": "Dustin Diaz <dustin@dustindiaz.com> (http://dustindiaz.com)",
|
||||||
"contributors": [
|
"contributors": [
|
||||||
{
|
{
|
||||||
@ -29,7 +29,7 @@
|
|||||||
"types": "index.d.ts",
|
"types": "index.d.ts",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/bowser-js/bowser.git"
|
"url": "git+https://github.com/lancedikson/bowser.git"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/cli": "^7.11.6",
|
"@babel/cli": "^7.11.6",
|
||||||
@ -65,7 +65,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/bowser-js/bowser/issues"
|
"url": "https://github.com/lancedikson/bowser/issues"
|
||||||
},
|
},
|
||||||
"directories": {
|
"directories": {
|
||||||
"test": "test"
|
"test": "test"
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*!
|
/*!
|
||||||
* Bowser - a browser detector
|
* Bowser - a browser detector
|
||||||
* https://github.com/bowser-js/bowser
|
* https://github.com/lancedikson/bowser
|
||||||
* MIT License | (c) Dustin Diaz 2012-2015
|
* MIT License | (c) Dustin Diaz 2012-2015
|
||||||
* MIT License | (c) Denis Demchenko 2015-2019
|
* MIT License | (c) Denis Demchenko 2015-2019
|
||||||
*/
|
*/
|
||||||
@ -75,3 +75,9 @@ class Bowser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default Bowser;
|
export default Bowser;
|
||||||
|
|
||||||
|
export const { getParser } = Bowser;
|
||||||
|
export const { parse } = Bowser;
|
||||||
|
export {
|
||||||
|
BROWSER_MAP, ENGINE_MAP, OS_MAP, PLATFORMS_MAP,
|
||||||
|
};
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import test from 'ava';
|
import test from 'ava';
|
||||||
import Bowser from '../../src/bowser';
|
import Bowser, { getParser, parse, BROWSER_MAP, ENGINE_MAP, OS_MAP, PLATFORMS_MAP } from '../../src/bowser';
|
||||||
import Parser from '../../src/parser';
|
import Parser from '../../src/parser';
|
||||||
|
|
||||||
const UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36 OPR/43.0.2442.1165';
|
const UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36 OPR/43.0.2442.1165';
|
||||||
@ -16,3 +16,64 @@ test('Bowser`s constructor fails if UA is empty', (t) => {
|
|||||||
test('Bowser.parse parses UA and returns result', (t) => {
|
test('Bowser.parse parses UA and returns result', (t) => {
|
||||||
t.deepEqual(Bowser.parse(UA), browser.getResult());
|
t.deepEqual(Bowser.parse(UA), browser.getResult());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Named export getParser works like Bowser.getParser', (t) => {
|
||||||
|
const namedExportParser = getParser(UA);
|
||||||
|
t.truthy(namedExportParser instanceof Parser);
|
||||||
|
t.deepEqual(namedExportParser.getResult(), browser.getResult());
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Named export getParser with skipParsing parameter', (t) => {
|
||||||
|
const parserWithSkip = getParser(UA, true);
|
||||||
|
t.truthy(parserWithSkip instanceof Parser);
|
||||||
|
// With skipParsing=true, the result should be undefined until we explicitly parse
|
||||||
|
t.deepEqual(parserWithSkip.getResult(), Bowser.getParser(UA, true).getResult());
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Named export getParser throws error for invalid UA', (t) => {
|
||||||
|
t.throws(() => getParser(undefined), { message: 'UserAgent should be a string' });
|
||||||
|
t.throws(() => getParser(123), { message: 'UserAgent should be a string' });
|
||||||
|
t.throws(() => getParser(null), { message: 'UserAgent should be a string' });
|
||||||
|
t.throws(() => getParser({}), { message: 'UserAgent should be a string' });
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Named export parse works like Bowser.parse', (t) => {
|
||||||
|
t.deepEqual(parse(UA), Bowser.parse(UA));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Named export parse produces consistent results', (t) => {
|
||||||
|
const result1 = parse(UA);
|
||||||
|
const result2 = parse(UA);
|
||||||
|
t.deepEqual(result1, result2);
|
||||||
|
t.deepEqual(result1, Bowser.parse(UA));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Named exports of constants are available', (t) => {
|
||||||
|
t.truthy(BROWSER_MAP);
|
||||||
|
t.truthy(ENGINE_MAP);
|
||||||
|
t.truthy(OS_MAP);
|
||||||
|
t.truthy(PLATFORMS_MAP);
|
||||||
|
t.is(BROWSER_MAP, Bowser.BROWSER_MAP);
|
||||||
|
t.is(ENGINE_MAP, Bowser.ENGINE_MAP);
|
||||||
|
t.is(OS_MAP, Bowser.OS_MAP);
|
||||||
|
t.is(PLATFORMS_MAP, Bowser.PLATFORMS_MAP);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Named exports constants are objects with expected structure', (t) => {
|
||||||
|
t.is(typeof BROWSER_MAP, 'object');
|
||||||
|
t.is(typeof ENGINE_MAP, 'object');
|
||||||
|
t.is(typeof OS_MAP, 'object');
|
||||||
|
t.is(typeof PLATFORMS_MAP, 'object');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('All named exports work together', (t) => {
|
||||||
|
// Test that we can use multiple named exports in the same scope
|
||||||
|
const result = parse(UA);
|
||||||
|
const parser = getParser(UA);
|
||||||
|
|
||||||
|
t.deepEqual(result, parser.getResult());
|
||||||
|
t.truthy(BROWSER_MAP);
|
||||||
|
t.truthy(ENGINE_MAP);
|
||||||
|
t.truthy(OS_MAP);
|
||||||
|
t.truthy(PLATFORMS_MAP);
|
||||||
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user