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

docs(bowser): improve some JSDocs and Error class

This commit is contained in:
Denis Demchenko 2019-07-16 22:19:07 +03:00
parent 41b66d5450
commit dcadd16ed7

View File

@ -2,7 +2,7 @@
* Bowser - a browser detector
* https://github.com/lancedikson/bowser
* MIT License | (c) Dustin Diaz 2012-2015
* MIT License | (c) Denis Demchenko 2015-2017
* MIT License | (c) Denis Demchenko 2015-2019
*/
import Parser from './parser.js';
import {
@ -12,21 +12,37 @@ import {
PLATFORMS_MAP,
} from './constants.js';
/**
* @class
* @property name
*/
class BowserUAIsNotAStringError extends Error {
constructor(message) {
super(message);
this.name = 'BowserUAIsNotAStringError';
}
}
/**
* Bowser class.
* Keep it simple as much as it can be.
* It's supposed to work with collections of {@link Parser} instances
* rather then solve one-instance problems.
* All the one-instance stuff is located in Parser class.
*
* @class
* @classdesc Bowser is a static object, that provides an API to the Parsers
* @hideconstructor
*/
class Bowser {
/**
* Creates a {@link module:parser:Parser} instance
* Creates a {@link Parser} instance
*
* @param {String} UA UserAgent string
* @param {Boolean} [skipParsing=false] same as skipParsing for {@link Parser}
* @param {Boolean} [skipParsing=false] Will make the Parser postpone parsing until you ask it
* explicitly. Same as `skipParsing` for {@link Parser}.
* @returns {Parser}
* @throws {Error} when UA is not a String
* @throws {BowserUAIsNotAStringError} when UA is not a String
*
* @example
* const parser = Bowser.getParser(window.navigator.userAgent);
@ -34,7 +50,7 @@ class Bowser {
*/
static getParser(UA, skipParsing = false) {
if (typeof UA !== 'string') {
throw new Error('UserAgent should be a string');
throw new BowserUAIsNotAStringError('UserAgent should be a string');
}
return new Parser(UA, skipParsing);
}