Os
Runtime: Node.js; degrades in browsers — probes for process / window / navigator and falls back instead of throwing
The handful of operating-system facts worth a named helper — platform, architecture, release, home and temp directories. Each one guards on process being present and returns undefined off Node rather than throwing, so a shared module can call them without a runtime check. They are passthroughs, so you get exactly what Node reports ('darwin', not 'macOS'); for browser-side platform sniffing use system.
For the platform itself use getProcessPlatform.
Example
import { getHomeDir, getOsArch, getTmpDir } from '@rtorcato/js-common/os'
// Off Node these return `undefined` instead of throwing, so a module shared with
// the browser can call them without a runtime guard.
const cacheDir = `${getHomeDir() ?? getTmpDir()}/.myapp`
getOsArch() // 'arm64' | 'x64' — Node's own strings, unmapped
Import
import { getHomeDir, getOsArch, getOsRelease } from '@rtorcato/js-common/os'
Exports
| Name | Summary |
|---|---|
getHomeDir | Returns the user's home directory (Node.js only). |
getOsArch | Returns the OS architecture (Node.js only). |
getOsRelease | Returns the OS release/version (Node.js only). |
getTmpDir | Returns the system's temporary directory (Node.js only). |