convert macOS check to utility function

This commit is contained in:
David Lechner
2021-01-14 15:25:57 -06:00
parent a48f3f381e
commit 25c0d104a9
4 changed files with 29 additions and 4 deletions
+15
View File
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2021 The Pybricks Authors
import { isMacOS } from './os';
describe('isMacOS', () => {
test('is true', () => {
jest.spyOn(navigator, 'platform', 'get').mockReturnValue('MacIntel');
expect(isMacOS()).toBeTruthy();
});
test('is false', () => {
jest.spyOn(navigator, 'platform', 'get').mockReturnValue('Win32');
expect(isMacOS()).toBeFalsy();
});
});
+8
View File
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2021 The Pybricks Authors
// Utility functions for dealing with operating systems.
export function isMacOS(): boolean {
return /mac/i.test(navigator.platform);
}