forked from jsonwebtoken/jsonwebtoken.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
59 lines (48 loc) · 1.42 KB
/
Copy pathutils.js
File metadata and controls
59 lines (48 loc) · 1.42 KB
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
//import { KEYUTIL } from 'jsrsasign';
import log from 'loglevel';
import clipboard from 'clipboard-polyfill';
export function httpGet(url, cache = true) {
return new Promise((resolve, reject) => {
const request = new XMLHttpRequest();
request.onreadystatechange = () => {
if (request.readyState === XMLHttpRequest.DONE) {
if (request.status === 200) {
resolve(request.responseText);
} else {
reject({
status: request.status,
response: request.responseText
});
}
}
};
request.open('GET', url);
if (!cache) {
request.setRequestHeader("Cache-Control", "no-cache");
}
request.send();
});
}
export function deferToNextLoop(func) {
setTimeout(func, 1);
}
export function copyTokenLink(token, publicKeyOptional) {
let url = `https://jwt.io/#debugger-io?token=${encodeURIComponent(token)}`;
if(publicKeyOptional) {
url += `&publicKey=${encodeURIComponent(publicKeyOptional)}`;
}
clipboard.writeText(url);
return url;
}
export function isWideScreen() {
return window.matchMedia('(min-width: 768px)').matches;
}
export function safeLocalStorageSetItem(key, value) {
try {
localStorage.setItem(key, value);
} catch (e) {
log.info('Cannot save token to Local Storage ' +
'(private browsing enabled?), ignoring...', e);
// Safari when in private browsing doesn't allow it
}
}