pontil/platform

Cross-runtime platform detection.

Provides typed detection of runtime environment, operating system, and CPU architecture across both Erlang and JavaScript targets.

Types

The CPU architecture.

pub type Arch {
  Arm
  Arm64
  X86
  X64
  Loong64
  Mips
  MipsLittleEndian
  PPC
  PPC64
  RiscV64
  S390
  S390X
  OtherArch(String)
}

Constructors

  • Arm
  • Arm64
  • X86
  • X64
  • Loong64
  • Mips
  • MipsLittleEndian
  • PPC
  • PPC64
  • RiscV64
  • S390
  • S390X
  • OtherArch(String)

The operating system.

pub type Os {
  Aix
  Darwin
  FreeBsd
  Linux
  OpenBsd
  SunOs
  Win32
  OtherOs(String)
}

Constructors

  • Aix
  • Darwin
  • FreeBsd
  • Linux
  • OpenBsd
  • SunOs
  • Win32
  • OtherOs(String)

Platform details.

pub type PlatformInfo {
  PlatformInfo(
    name: String,
    version: String,
    runtime: Runtime,
    runtime_version: String,
    os: Os,
    arch: Arch,
  )
}

Constructors

  • PlatformInfo(
      name: String,
      version: String,
      runtime: Runtime,
      runtime_version: String,
      os: Os,
      arch: Arch,
    )

    Arguments

    name

    The name of the Operating System release. This will be "" if the value cannot be determined.

    version

    The version of the Operating System release. This will be "" if the value cannot be determined.

    runtime

    The runtime environment.

    runtime_version

    The runtime version string.

    os

    The operating system.

The runtime environment.

pub type Runtime {
  Erlang
  Node
  Bun
  Deno
  Browser
  OtherRuntime(String)
}

Constructors

  • Erlang
  • Node
  • Bun
  • Deno
  • Browser
  • OtherRuntime(String)

Values

pub fn arch() -> Arch

Returns the CPU architecture.

pub fn arch_to_string(arch: Arch) -> String

Returns a string representation of an Arch value.

pub fn details() -> PlatformInfo

Returns full platform details including OS release name and version.

pub fn is_linux() -> Bool

Returns True if the host OS is Linux.

pub fn is_macos() -> Bool

Returns True if the host OS is macOS.

pub fn is_windows() -> Bool

Returns True if the host OS is Windows.

pub fn os() -> Os

Returns the host operating system.

pub fn os_to_string(os: Os) -> String

Returns a string representation of an Os value.

pub fn runtime() -> Runtime

Returns the runtime this application is running on.

pub fn runtime_to_string(runtime: Runtime) -> String

Returns a string representation of a Runtime value.

pub fn runtime_version() -> String

Returns the version string of the current runtime.

  • Erlang: OTP release (e.g. "27")
  • Node: version without v prefix (e.g. "24.0.0")
  • Bun: version (e.g. "1.1.0")
  • Deno: version (e.g. "2.0.0")
  • Browser: "browser"

In the browser, the value browser is returned because the only useful value, navigator.appVersion or navigator.userAgent, is completely useless as a simple version. If you are using pontil/platform in a browser, you will need to parse navigator.userAgent directly.

Search Document