@bemoje/os
v2.0.0
Published
Operating system detection and platform-specific utilities.
Maintainers
Readme
@bemoje/os
Operating system detection and platform-specific utilities.
Exports
- defaultOpenInEditorCommand: Get the default command to open a file in in a text editor. If VSCode is installed, this is used. Otherwise, the default text editor of the OS is used.
- getAppDataPath.
- getDefaultBrowserWindows: Gets the default browser identifier on Windows by querying the registry.
- getHomeDirectory: Returns the home directory of the current user.
- getOS: Determines the current operating system. It uses the isWindows, isOSX, and isLinux functions to determine the current operating system.
- getTempDataPath: Returns a path to the os tmpdir location.
- getTempFilepath: Returns a path to a temporary file with the given basename and subpath.
- isLinux: Checks if the current platform is Linux. It checks the 'process' object and the 'platform' property to determine if the platform is 'linux'.
- isLinuxProgramInstalled: LINUX ONLY: Returns whether a program is installed on the system. Always returns false of OS is not linux.
- isOSX: Checks if the current platform is OSX. It checks the 'process' object and the 'platform' property to determine if the platform is 'darwin'.
- isVsCodeInstalled: Returns whether Visual Studio Code is installed on the system.
- isWindows: Checks if the current platform is Windows.
- openInDefaultBrowserCommand: Gets the command to open a URL in the default browser for the current operating system.
- winExplorerOpenDirectory: Opens a directory in Windows Explorer. Works on Windows only.
Installation
npm install @bemoje/osUsage
Platform Detection
import { getOS, isWindows, isLinux, isOSX } from '@bemoje/os'
getOS() // 'windows' | 'osx' | 'linux' | 'unknown'
isWindows() // true/false
isLinux() // true/false
isOSX() // true/falseSystem Paths
import { getAppDataPath, getHomeDirectory, getTempDataPath, getTempFilepath } from '@bemoje/os'
getAppDataPath('MyApp') // C:\Users\user\AppData\Roaming\MyApp (Windows)
getHomeDirectory() // /home/user (Linux) or C:\Users\user
getTempDataPath('cache') // /tmp/cache
getTempFilepath('output.json') // /tmp/tmp/1234567890/output.jsonBrowser and Editor Detection
import { isVsCodeInstalled, openInDefaultBrowserCommand, defaultOpenInEditorCommand } from '@bemoje/os'
isVsCodeInstalled() // true if `code` command exists
openInDefaultBrowserCommand('https://example.com')
// 'msedge "https://example.com"' (Windows) or 'open safari "https://example.com"' (macOS)
defaultOpenInEditorCommand()
// 'code -w' if VS Code is installed, otherwise OS default editorWindows Utilities
import { winExplorerOpenDirectory, getDefaultBrowserWindows } from '@bemoje/os'
await winExplorerOpenDirectory('C:\\Users\\user\\Desktop')
getDefaultBrowserWindows()
// { name: 'Chrome', run: 'chrome', id: 'com.google.chrome' }