Skip to content

Commit 99355c7

Browse files
committed
Merge pull request DefinitelyTyped#8637 from isman-usoh/express-useragent-patch-1
add express-useragent typedefinition
2 parents 7ab10dc + e0d03cc commit 99355c7

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
/// <reference path="../express/express.d.ts" />
3+
/// <reference path="./express-useragent.d.ts" />
4+
5+
import express = require("express");
6+
import useragent = require("express-useragent");
7+
8+
var app = express();
9+
app.use(useragent.express());
10+
app.get("/", function(req, res) {
11+
var userAgentString =
12+
"isMobile:" + req.useragent.isMobile + "," +
13+
"isDesktop:" + req.useragent.isDesktop + "," +
14+
"isBot:" + req.useragent.isDesktop + "," +
15+
"browser:" + req.useragent.isDesktop + "," +
16+
"version:" + req.useragent.isDesktop + "," +
17+
"os:" + req.useragent.isDesktop + "," +
18+
"platform:" + req.useragent.isDesktop + "," +
19+
"source :" + req.useragent.isDesktop;
20+
21+
res.end(userAgentString);
22+
});
23+
24+
app.get("/parse", function(req, res) {
25+
var source = req.headers['user-agent'],
26+
ua = useragent.parse(source);
27+
res.writeHead(200, {'Content-Type': 'text/plain'});
28+
res.end(JSON.stringify(ua));
29+
});
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Type definitions for express-useragent 0.2.4
2+
// Project: https://www.npmjs.org/package/express-useragent
3+
// Definitions by: Isman Usoh <https://github.com/isman-usoh/>
4+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5+
6+
/// <reference path="../express/express.d.ts" />
7+
8+
declare namespace Express {
9+
interface ExpressUserAgent {
10+
isMobile: boolean;
11+
isTablet: boolean;
12+
isiPad: boolean;
13+
isiPod: boolean;
14+
isiPhone: boolean;
15+
isAndroid: boolean;
16+
isBlackberry: boolean;
17+
isOpera: boolean;
18+
isIE: boolean;
19+
isEdge: boolean;
20+
isIECompatibilityMode: boolean;
21+
isSafari: boolean;
22+
isFirefox: boolean;
23+
isWebkit: boolean;
24+
isChrome: boolean;
25+
isKonqueror: boolean;
26+
isOmniWeb: boolean;
27+
isSeaMonkey: boolean;
28+
isFlock: boolean;
29+
isAmaya: boolean;
30+
isEpiphany: boolean;
31+
isDesktop: boolean;
32+
isWindows: boolean;
33+
isWindowsPhone: boolean;
34+
isLinux: boolean;
35+
isLinux64: boolean;
36+
isMac: boolean;
37+
isChromeOS: boolean;
38+
isBada: boolean;
39+
isSamsung: boolean;
40+
isRaspberry: boolean;
41+
isBot: boolean;
42+
isCurl: boolean;
43+
isAndroidTablet: boolean;
44+
isWinJs: boolean;
45+
isKindleFire: boolean;
46+
isSilk: boolean;
47+
isCaptive: boolean;
48+
isSmartTV: boolean;
49+
silkAccelerated: boolean;
50+
browser: string;
51+
version: string;
52+
os: string;
53+
platform: string;
54+
geoIp: any;
55+
source: string;
56+
}
57+
58+
interface Request {
59+
useragent?: ExpressUserAgent;
60+
}
61+
}
62+
63+
declare module "express-useragent" {
64+
import express = require("express");
65+
66+
export function parse(source: string): Express.ExpressUserAgent;
67+
export function express(): (req: express.Request, res: express.Response, next?: Function) => void;
68+
}

0 commit comments

Comments
 (0)