Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux platform support #24

Merged
merged 1 commit into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/user-agent-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ test('It should get OSX platform', () => {
expect(result.version).toBe('10.15.3');
});

test('It should get Linux platform', () => {
// Given
const userAgent = 'Chrome 80.0.3987.132 / Linux 0.0';

// When
const result = getPlatformFrom(userAgent);

// Then
expect(result.name).toBe('linux');
expect(result.version).toBe('0.0');
});

test('It should get Windows platform on Windows 10', () => {
// Given
const userAgent = 'Chrome 80.0.3987.149 / Windows 10';
Expand Down
14 changes: 14 additions & 0 deletions src/user-agent-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ export function getPlatformFrom(userAgent: string | undefined): Platform {
version: platformInfo.version,
};
}
if (isLinux(platformInfo.name)) {
return {
name: 'linux',
version: platformInfo.version,
};
}
if (isWindows(platformInfo.name)) {
return {
name: 'windows',
Expand Down Expand Up @@ -98,6 +104,14 @@ export function isMacOsX(platformName: string | undefined): boolean {
return result;
}

export function isLinux(platformName: string | undefined): boolean {
if (platformName === undefined) {
return false;
}
const result = platformName.toLowerCase().includes('linux');
return result;
}

export function isWindows(platformName: string | undefined): boolean {
if (platformName === undefined) {
return false;
Expand Down