Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
fscherwi committed Oct 4, 2018
1 parent 4d01833 commit 194c332
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 31 deletions.
30 changes: 2 additions & 28 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,8 @@
function getsysInfo(sysInfo) { /* istanbul ignore next */
function getsysInfo(sysInfo) {
if (sysInfo) {
return sysInfo;
} else {
var os = require("os");
switch (os.platform()) {
case "darwin":
return "Macintosh; Intel Mac OS X " + require("get-osx-version").get();
case "windows":
switch (os.arch()) {
case "x64":
return "Windows; Win64; x64";
case "x86":
return "Windows; Win32; x86";
case "arm":
return "Windows; ARM";
default:
return "Windows";
}
case "linux":
switch (os.arch()) {
case "x64":
return "Linux; x86_64";
case "i686":
return "Linux; i686";
case "arm":
return "Linux; ARM";
default:
return "Linux";
}
}
return require("./sysInfo").get();
}
}
module.exports = {
Expand Down
8 changes: 8 additions & 0 deletions main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,11 @@ test('Safari Advanced', () => {
expect(ua.browser.name).toBe('Safari');
expect(ua.browser.version).toBe(version);
});

test('sysInfo', () => {
var version = '41.0';
var sysInfo = 'Macintosh; Intel Mac OS X 10.11';
ua = parser(useragent.firefox(version, sysInfo));
expect(ua.browser.name).toBe('Firefox');
expect(ua.browser.version).toBe(version);
});
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "get-user-agent",
"version": "3.0.0",
"version": "3.1.0",
"description": "easily get a useragent",
"main": "main.js",
"scripts": {
Expand Down Expand Up @@ -36,6 +36,7 @@
"files": [
"README.md",
"LICENSE",
"main.js"
"main.js",
"sysInfo.js"
]
}
31 changes: 31 additions & 0 deletions sysInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module.exports = {
get: function get() {
var os = require("os");
switch (os.platform()) {
case "darwin":
return "Macintosh; Intel Mac OS X " + require("get-osx-version").get();
case "windows":
switch (os.arch()) {
case "x64":
return "Windows; Win64; x64";
case "x86":
return "Windows; Win32; x86";
case "arm":
return "Windows; ARM";
default:
return "Windows";
}
case "linux":
switch (os.arch()) {
case "x64":
return "Linux; x86_64";
case "i686":
return "Linux; i686";
case "arm":
return "Linux; ARM";
default:
return "Linux";
}
}
}
};

0 comments on commit 194c332

Please sign in to comment.