-
-
Notifications
You must be signed in to change notification settings - Fork 487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Types definition for v2 #272
Comments
Well, okay, I made more tests. import Bowser = require("bowser"); Even if I use I think now that now is just a matter of if the typings are correct. If you, @lancedikson, think they are correct, I will make a pull request. 👍 |
Currently, I user this (for v1.9.4): export type BrowserFlag = 'a' | 'b' | 'c'
| 'android' | 'bada' | 'blackberry'
| 'chrome' | 'chromium' | 'firefox' | 'gecko' | 'ios' | 'msie'
| 'msedge' | 'opera' | 'phantom' | 'safari'
| 'sailfish' | 'seamonkey' | 'silk' | 'tizen'
| 'webkit' | 'webos' | 'chromeos' | 'iphone'
| 'ipad' | 'ipod' | 'firefoxos' | 'linux' | 'mac'
| 'touchpad' | 'windows' | 'windowsphone';
export interface BrowserInfo {
name: string;
osversion: string;
version: string;
/** grades a - This browser has full capabilities */
a: boolean;
/** grades b - This browser has degraded capabilities. */
b: boolean;
/** grades c - This browser has degraded capabilities. Serve simpler version */
c: boolean;
// engines
android: boolean;
bada: boolean;
blackberry: boolean;
chrome: boolean;
chromium: boolean;
firefox: boolean;
gecko: boolean;
ios: boolean;
msie: boolean;
msedge: boolean;
opera: boolean;
phantom: boolean;
safari: boolean;
sailfish: boolean;
seamonkey: boolean;
silk: boolean;
tizen: boolean;
webkit: boolean;
webos: boolean;
mobile: boolean;
tablet: boolean;
// operating systems
chromeos: boolean;
iphone: boolean;
ipad: boolean;
ipod: boolean;
firefoxos: boolean;
linux: boolean;
mac: boolean;
touchpad: boolean;
windows: boolean;
windowsphone: boolean;
test(browserList: BrowserFlag[]): boolean;
/**
* Check if browser is supported
*
* @param [ua] user agent string
*/
detect(userAgent: string): BrowserInfo;
/**
* Check if browser is supported
*
* @param minVersions map of minimal version to browser
*/
check(browser: { [version: string]: string }): boolean;
/**
* Check if browser is supported
*
* @param minVersions map of minimal version to browser
* @param [ua] user agent string
*/
// tslint:disable-next-line:unified-signatures
check(browser: { [version: string]: string }, userAgent: string): boolean;
/**
* Check if browser is supported
*
* @param minVersions map of minimal version to browser
* @param [strictMode = false] flag to return false if browser wasn't found in map
*/
// tslint:disable-next-line:unified-signatures
check(browser: { [version: string]: string }, strict: boolean): boolean;
/**
* Check if browser is supported
*
* @param minVersions map of minimal version to browser
* @param [strictMode = false] flag to return false if browser wasn't found in map
* @param [ua] user agent string
*/
// tslint:disable-next-line:unified-signatures
check(browser: { [version: string]: string }, strict: boolean, userAgent: string): boolean;
/**
* Calculate browser version weight
*
* @example
* compareVersions(['1.10.2.1', '1.8.2.1.90']) // 1
* compareVersions(['1.010.2.1', '1.09.2.1.90']); // 1
* compareVersions(['1.10.2.1', '1.10.2.1']); // 0
* compareVersions(['1.10.2.1', '1.0800.2']); // -1
*
* @param versions versions to compare
* @return comparison result
*/
compareVersions(versions: string[]): number;
/**
* Check if browser is unsupported
*
* @example
* bowser.isUnsupportedBrowser({
* msie: "10",
* firefox: "23",
* chrome: "29",
* safari: "5.1",
* opera: "16",
* phantom: "534"
* });
*
* @param minVersions map of minimal version to browser
* @param [strictMode = false] flag to return false if browser wasn't found in map
* @param [ua] user agent string
*/
isUnsupportedBrowser(minVersions: Object, strictMode?: Boolean, ua?: string): boolean;
}
declare var require: any;
export class Browser {
private static _browser: any = undefined;
static getInfo(): BrowserInfo {
if (!Browser._browser) {
Browser._browser = require('bowser');
}
return Browser._browser;
}
} |
@Zefling I cannot find in the code where BrowserInfo and BrowserFlags are defined. It seems like your typings are taken from v1 or sort of. I don't think they are valid anymore for v2. Moreover, I don't even know if v2 is still an alpha or beta version. |
I've updated my version of typings and since for the comments I copied the code ones, I discovered that |
@alexandercerutti Oups, sorry, it's based on version 1.9.4. The V2 it's still in beta. |
Okay, no problem. I putted a "down-thumb" reaction on your comment only to indicate that they are not good for v2. |
Hi guys. I'm sorry for late response. Not always have enough time to arrange the open source stuff. So, regarding these types definitions, I think they look great and I would appreciate if you send a PR. |
Great! I'll create a PR asap. 👍 Tomorrow I'll test them more on the project I'm using bowser in. I heard about this topic some other times and saw few tools that create not-that-much reliable typings from Closure Compiler Docs or JSDocs, if I remember correctly. For me, it really depends on how many new methods you think you'll integrate, @lancedikson, and how many methods you still plan to integrate, since v2 is still a beta. About the beta, is there any ETA about the stable releasing? Thank you! Another thing I have to say is that all the typings I wrote above, are based on the code. |
Okay, @lancedikson, before creating a PR, I tried to create a But if I create the definition file as At this point, I can access to syntax, but when I use webpack with babel to compile all together, it gives me error as it cannot find Bowser as default export. No, it does not work even with Moreover, I read that import x = require("bowser") is kept only for retro-compatibility with previous typescript versions and is maybe deprecated... I dunno... I have to investigate more, because probably babel compilation to es5 does not make this. |
I found that the only way it seems work, is using:
|
I don't have any other needed methods in my mind for now and it doesn't seem coming as requests from the community. Thus, I'd rather release the stable 2.0 version as soon as we got those typings defined based on current codebase. But, what stops me from it is that I can't be sure in the correctness of typings definition made by me, because I don't write on TS and don't know the right way to settle those. So, I'd need help with that here and thank you for providing it :)
I can't be sure here again as I don't use TS and don't know it's correct syntax. But, if you create the PR, I can participate in testing the typings in WebStorm and check if they're fully correct for JS files at least :) |
Okay, I'm going to create the pull request 👍 |
Closing since the pull request has been merged! |
I was trying to create types definition for this lib, as I need them in a TS+Webpack project and with the intent of creating later a pull request (as types are missing and last issue got opened over 3 months ago).
I created the following typings, and it reflects the provided documentation. But when applying it to an app, I encounter a series of complications.
One of them is: we know that Bowser class is the one that gets exported. At least examples say this.
But if I do both
I cannot access both
new Bowser
orBowser.getParser
(and, so, to all the parser methods).If I want to make it work, I have to do:
So, what does the transpiled version export? It should be the same, but it seems to be not equal.
Thank you.
EDIT: If I have typings imported with
/// <reference path="typings/bowser.d.ts" />
(yes, I have a specific folder), but the typings below are not commented, I get this error:
========
This is the type definition that one corrected may be pushed if you want.
The text was updated successfully, but these errors were encountered: