Skip to content

Commit

Permalink
Move getWindowsVersionName to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
lancedikson committed Jun 30, 2018
1 parent 3530ca1 commit 9cb04fc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
21 changes: 4 additions & 17 deletions src/parser-os.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
import { getFirstMatch } from './utils';

function getWindowsVersionName(version) {
switch (version) {
case 'NT': return 'NT';
case 'XP': return 'XP';
case 'NT 5.0': return '2000';
case 'NT 5.1': return 'XP';
case 'NT 5.2': return '2003';
case 'NT 6.0': return 'Vista';
case 'NT 6.1': return '7';
case 'NT 6.2': return '8';
case 'NT 6.3': return '8.1';
case 'NT 10.0': return '10';
default: return undefined;
}
}
import {
getFirstMatch,
getWindowsVersionName,
} from './utils';

export default [
/* Windows Phone */
Expand Down
16 changes: 16 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ class Utils {
}
return void (0);
}

static getWindowsVersionName(version) {
switch (version) {
case 'NT': return 'NT';
case 'XP': return 'XP';
case 'NT 5.0': return '2000';
case 'NT 5.1': return 'XP';
case 'NT 5.2': return '2003';
case 'NT 6.0': return 'Vista';
case 'NT 6.1': return '7';
case 'NT 6.2': return '8';
case 'NT 6.3': return '8.1';
case 'NT 10.0': return '10';
default: return undefined;
}
}
}

module.exports = Utils;
10 changes: 9 additions & 1 deletion test/unit/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import test from 'ava';
import { getFirstMatch } from '../../src/utils';
import {
getFirstMatch,
getWindowsVersionName,
} from '../../src/utils';

test('getFirstMatch', (t) => {
const matchedVersion = getFirstMatch(/version\/(\S+)/i, 'Chrome Version/11.11.11');
t.is(matchedVersion, '11.11.11');
});

test('getWindowsVersionName', (t) => {
t.is(getWindowsVersionName('NT 5.0'), '2000');
t.is(getWindowsVersionName('XXX'), void 0);
});

0 comments on commit 9cb04fc

Please sign in to comment.