How to use platform-select - 1 common examples

To help you get started, we’ve selected a few platform-select examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github callstack / haul / packages / haul-core / src / server / launchBrowser.ts View on Github external
export default function launchBrowser(runtime: Runtime, url: string) {
  const openWith = (app: string) => () => open(url, { app });

  /**
   * Run Chrome (Chrome Canary) or supported platform.
   * In case of macOS, we can eventually fallback to Safari.
   *
   * select(attemp1, attemp2, attemp3,...) // attempt to run is from left to right
   */
  select(
    {
      // try to find & run Google Chrome
      darwin: openWith('google chrome'),
      win32: openWith('chrome'),
      _: openWith('google-chrome'),
    },
    {
      // On macOS let's try to find & run Canary
      darwin: openWith('google chrome canary'),
    },
    {
      // No Canary / Chrome, let's run Safari
      darwin: openWith('safari'),
    }
  ).catch((error: Error) => {
    runtime.logger.warn(

platform-select

This little library allows you to define precedence which function evaluate based on the platform.

MIT
Latest version published 3 years ago

Package Health Score

42 / 100
Full package analysis

Popular platform-select functions

Similar packages