mirror of
https://github.com/lancedikson/bowser
synced 2026-03-02 03:40:27 +00:00
Add a bit of docs
This commit is contained in:
@@ -7,31 +7,38 @@
|
||||
import Parser from './parser';
|
||||
|
||||
/**
|
||||
* Bowser class
|
||||
* Keep it simple as much as it can be
|
||||
* It's supposed to work with collections of Parser instances
|
||||
* 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 Bowser {
|
||||
/**
|
||||
* Creates a Parser instance instead of Bowser's one
|
||||
* Creates a {@link module:parser:Parser} instance
|
||||
*
|
||||
* @param {String} UA — UserAgent string
|
||||
* @param {Boolean} [skipParsing=false] — same as skipParsing for Parser
|
||||
* @param {String} UA UserAgent string
|
||||
* @param {Boolean} [skipParsing=false] same as skipParsing for {@link Parser}
|
||||
* @returns {Parser}
|
||||
* @throws {Error} when UA is not a String
|
||||
*
|
||||
* @example
|
||||
* const bowser = new Bowser(window.navigator.userAgent);
|
||||
* bowser.getResult()
|
||||
*/
|
||||
constructor(UA, skipParsing=false) {
|
||||
static getParser(UA, skipParsing=false) {
|
||||
if (typeof UA !== 'string') {
|
||||
throw new Error('UserAgent should be a string');
|
||||
}
|
||||
return new Parser(UA, skipParsing);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link Parser} instance and runs {@link Parser.getResult} immediately
|
||||
*
|
||||
* @param UA
|
||||
* @return {ParsedResult}
|
||||
*/
|
||||
static parse(UA) {
|
||||
return (new Bowser(UA)).getResult();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user