From 9cb04fcbaeebc682f9fe9b24a48a9b2b631518c2 Mon Sep 17 00:00:00 2001 From: Denis Demchenko Date: Sat, 30 Jun 2018 19:40:10 +0300 Subject: [PATCH] Move getWindowsVersionName to utils --- src/parser-os.js | 21 ++++----------------- src/utils.js | 16 ++++++++++++++++ test/unit/utils.js | 10 +++++++++- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/parser-os.js b/src/parser-os.js index fecbb2b..8ca6446 100644 --- a/src/parser-os.js +++ b/src/parser-os.js @@ -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 */ diff --git a/src/utils.js b/src/utils.js index d10359a..b974c7f 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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; diff --git a/test/unit/utils.js b/test/unit/utils.js index eab8415..59919a4 100644 --- a/test/unit/utils.js +++ b/test/unit/utils.js @@ -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); +});