get-private-browsing-name
Advanced tools
Comparing version 0.1.1 to 0.2.0
128
index.js
@@ -1,127 +0,1 @@ | ||
const getPrivateBrowsingName = () => { | ||
const ua = navigator && navigator.userAgent; | ||
const osDict = [ | ||
{ | ||
os: 'iOS', | ||
regex: /iP(hone|od|ad)/ | ||
}, | ||
{ | ||
os: 'Linux', | ||
regex: /(Linux)|(X11)/ | ||
}, | ||
{ | ||
os: 'Mac OS', | ||
regex: /(Mac_PowerPC)|(Macintosh)/ | ||
}, | ||
{ | ||
os: 'Windows', | ||
regex: /Win/ | ||
} | ||
]; | ||
const browserDict = [ | ||
{ | ||
browser: 'edge', | ||
mode: 'InPrivate Browsing', | ||
linkMethod: 'Open link in InPrivate window', | ||
macMethod: 'Command⌘+Shift+p', | ||
windowsMethod: 'Ctrl+Shift+p', | ||
regex: /Edge\/([0-9\._]+)/ | ||
}, | ||
{ | ||
browser: 'edge-ios', | ||
mode: 'InPrivate Browsing', | ||
linkMethod: 'Open link in InPrivate window', | ||
macMethod: 'Command⌘+Shift+p', | ||
windowsMethod: 'Ctrl+Shift+p', | ||
regex: /EdgiOS\/([0-9\._]+)/ | ||
}, | ||
{ | ||
browser: 'firefox', | ||
mode: 'Private Browsing', | ||
linkMethod: 'Open in New Private Window', | ||
macMethod: 'Command⌘+Shift+p', | ||
windowsMethod: 'Ctrl+Shift+p', | ||
regex: /Firefox\/([0-9\.]+)(?:\s|$)/ | ||
}, | ||
{ | ||
browser: 'safari', | ||
mode: 'Private Browsing', | ||
linkMethod: null, | ||
macMethod: 'Command⌘+Shift+n', | ||
windowsMethod: null, | ||
regex: /Version\/([0-9\._]+).*Safari/ | ||
}, | ||
{ | ||
browser: 'chrome', | ||
mode: 'Incognito', | ||
linkMethod: 'Open Link in Incognito Window', | ||
macMethod: 'Command⌘+Shift+n', | ||
windowsMethod: 'Ctrl+Shift+n', | ||
regex: /(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/ | ||
}, | ||
{ | ||
browser: 'ie', | ||
mode: 'InPrivate Browsing', | ||
linkMethod: null, | ||
macMethod: 'Command⌘+Shift+p', | ||
windowsMethod: 'Ctrl+Shift+p', | ||
regex: /Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/ | ||
}, | ||
{ | ||
browser: 'ie', | ||
mode: 'InPrivate Browsing', | ||
linkMethod: null, | ||
macMethod: 'Command⌘+Shift+p', | ||
windowsMethod: 'Ctrl+Shift+p', | ||
regex: /MSIE\s([0-9\.]+);.*Trident\/[4-7].0/ | ||
}, | ||
{ | ||
browser: 'ie', | ||
mode: 'InPrivate Browsing', | ||
linkMethod: null, | ||
macMethod: 'Command⌘+Shift+p', | ||
windowsMethod: 'Ctrl+Shift+p', | ||
regex: /MSIE\s(7\.0)/ | ||
} | ||
]; | ||
const lookup = (dict, str) => { | ||
for (let i = 0, count = dict.length; i < count; i++) { | ||
const { regex } = dict[i]; | ||
const match = regex.exec(str); | ||
if (match) { | ||
return dict[i]; | ||
} | ||
} | ||
return null; | ||
} | ||
const getOs = (str) => { | ||
const result = lookup(osDict, str); | ||
return result && result.os || null; | ||
} | ||
const getBrowser = (str) => { | ||
return lookup(browserDict, str); | ||
} | ||
const os = getOs(ua); | ||
const browser = getBrowser(ua); | ||
let detectedMethod = null; | ||
if (os === 'Windows' || os === 'Linux') { | ||
detectedMethod = browser.windowsMethod; | ||
} else if (os === 'Mac OS' || os === 'iOS') { | ||
detectedMethod = browser.macMethod; | ||
} | ||
return browser && { | ||
...browser, | ||
detectedMethod, | ||
} || null; | ||
} | ||
module.exports = getPrivateBrowsingName; | ||
module.exports = require('./dist'); |
{ | ||
"name": "get-private-browsing-name", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "jest" | ||
"test": "jest", | ||
"build": "babel src --out-dir dist" | ||
}, | ||
@@ -25,5 +26,11 @@ "repository": { | ||
"devDependencies": { | ||
"@babel/cli": "^7.12.10", | ||
"@babel/core": "^7.12.10", | ||
"@babel/preset-env": "^7.12.11", | ||
"jest": "^25.1.0", | ||
"jest-useragent-mock": "^0.0.3" | ||
}, | ||
"dependencies": { | ||
"@babel/polyfill": "^7.12.1" | ||
} | ||
} |
@@ -5,2 +5,6 @@ ### WIP - Under development | ||
### General rule of thumb: | ||
- **Safari MacOs, iOS:** Private Browsing Mode | ||
- **Gooogle Chrome:** Incognito Mode | ||
```js | ||
@@ -7,0 +11,0 @@ // Example Running in Chrome |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
170
22
7995
1
5
1
+ Added@babel/polyfill@^7.12.1
+ Added@babel/polyfill@7.12.1(transitive)
+ Addedcore-js@2.6.12(transitive)
+ Addedregenerator-runtime@0.13.11(transitive)