UNPKG

2.38 kBJavaScriptView Raw
1const getConfirmation = (win, message, callback) => (callback(win.confirm(message)));
2const isModifiedEvent = (ev) => (ev.metaKey || ev.altKey || ev.ctrlKey || ev.shiftKey);
3/**
4 * Returns true if the HTML5 history API is supported. Taken from Modernizr.
5 *
6 * https://github.com/Modernizr/Modernizr/blob/master/LICENSE
7 * https://github.com/Modernizr/Modernizr/blob/master/feature-detects/history.js
8 * changed to avoid false negatives for Windows Phones: https://github.com/reactjs/react-router/issues/586
9 */
10const supportsHistory = (win) => {
11 const ua = win.navigator.userAgent;
12 if ((ua.indexOf('Android 2.') !== -1 || ua.indexOf('Android 4.0') !== -1) &&
13 ua.indexOf('Mobile Safari') !== -1 &&
14 ua.indexOf('Chrome') === -1 &&
15 ua.indexOf('Windows Phone') === -1) {
16 return false;
17 }
18 return win.history && 'pushState' in win.history;
19};
20/**
21 * Returns true if browser fires popstate on hash change.
22 * IE10 and IE11 do not.
23 */
24const supportsPopStateOnHashChange = (nav) => (nav.userAgent.indexOf('Trident') === -1);
25/**
26 * Returns false if using go(n) with hash history causes a full page reload.
27 */
28const supportsGoWithoutReloadUsingHash = (nav) => (nav.userAgent.indexOf('Firefox') === -1);
29const isExtraneousPopstateEvent = (nav, event) => (event.state === undefined &&
30 nav.userAgent.indexOf('CriOS') === -1);
31const storageAvailable = (win, type) => {
32 const storage = win[type];
33 const x = '__storage_test__';
34 try {
35 storage.setItem(x, x);
36 storage.removeItem(x);
37 return true;
38 }
39 catch (e) {
40 return e instanceof DOMException && (
41 // everything except Firefox
42 e.code === 22 ||
43 // Firefox
44 e.code === 1014 ||
45 // test name field too, because code might not be present
46 // everything except Firefox
47 e.name === 'QuotaExceededError' ||
48 // Firefox
49 e.name === 'NS_ERROR_DOM_QUOTA_REACHED') &&
50 // acknowledge QuotaExceededError only if there's something already stored
51 storage.length !== 0;
52 }
53};
54
55export { supportsHistory as a, supportsPopStateOnHashChange as b, isExtraneousPopstateEvent as c, supportsGoWithoutReloadUsingHash as d, getConfirmation as g, isModifiedEvent as i, storageAvailable as s };