-
Notifications
You must be signed in to change notification settings - Fork 4
/
browser.js
63 lines (46 loc) · 779 Bytes
/
browser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"use strict";
var output = {};
var g, hasNative;
if (typeof window !== "undefined")
{
g = window;
}
else if (typeof global !== "undefined")
{
g = global;
}
else if (typeof self !== "undefined")
{
g = self;
}
else
{
g = this;
}
try
{
var url = new g.URL("http://domain.com");
var params = new g.URLSearchParams("?param=value")
hasNative = "searchParams" in url && params.get("param") === "value";
}
catch (error)
{
hasNative = false;
}
if (hasNative)
{
output.URL = g.URL;
output.URLSearchParams = g.URLSearchParams;
}
else
{
var lib = require("whatwg-url");
output.URL = lib.URL;
output.URLSearchParams = lib.URLSearchParams;
}
output.shim = function()
{
g.URL = output.URL;
g.URLSearchParams = output.URLSearchParams;
};
module.exports = output;