npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@molecule/app-platform

v1.0.1

Published

Platform detection and abstraction for molecule.dev

Readme

@molecule/app-platform

Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit src/index.ts JSDoc, not this file.

Platform detection and abstraction for molecule.dev.

Detects the current runtime (web, iOS, Android, Electron/desktop) by inspecting Capacitor / Electron / React Native markers, and provides platform-branching helpers ({@link onPlatform}, {@link isPlatform}) plus a native-startup coordinator ({@link createCapacitorApp}). Pure functions — no bond wiring required.

Quick Start

import { isPlatform, onPlatform, platform } from '@molecule/app-platform'

const info = platform() // cached PlatformInfo
if (info.isNative) initNativePlugins()

const label = onPlatform({
  ios: () => 'App Store',
  android: () => 'Play Store',
  default: () => 'Web', // `default` is required — always a fallback
})

Type

core

Installation

npm install @molecule/app-platform @molecule/app-lifecycle @molecule/app-logger @molecule/app-push

API

Interfaces

CapacitorApp

Capacitor app coordinator return type.

interface CapacitorApp {
  /**
   * Initialize the app. Call this during startup.
   */
  initialize(): Promise<void>

  /**
   * Whether the app is fully ready.
   */
  isReady(): boolean

  /**
   * Get the current initialization state.
   */
  getState(): CapacitorAppState

  /**
   * Subscribe to state changes.
   */
  subscribe(callback: (state: CapacitorAppState) => void): () => void

  /**
   * Register a callback for when the app becomes ready.
   * If already ready, the callback fires immediately.
   */
  onReady(callback: () => void): () => void

  /**
   * Clean up listeners.
   */
  destroy(): void
}

CapacitorAppOptions

Capacitor app configuration options.

interface CapacitorAppOptions {
  /**
   * Callback invoked when the app is fully initialized and ready to render.
   */
  onReady?: () => void | Promise<void>

  /**
   * Whether to initialize push notifications on startup.
   * @default false
   */
  pushNotifications?: boolean

  /**
   * Whether to handle deep links on startup.
   * @default false
   */
  deepLinks?: boolean

  /**
   * Deep link handler callback.
   */
  onDeepLink?: (url: string) => void
}

CapacitorAppState

Capacitor app coordinator state.

interface CapacitorAppState {
  /**
   * Whether the app is fully initialized.
   */
  ready: boolean

  /**
   * Whether device ready has fired.
   */
  deviceReady: boolean

  /**
   * Whether push notifications are initialized.
   */
  pushReady: boolean

  /**
   * Initialization error, if any.
   */
  error: Error | null
}

PlatformInfo

Detected runtime environment details (platform, native/mobile/desktop/web flags, dev/prod mode).

interface PlatformInfo {
  /**
   * The current platform.
   */
  platform: Platform

  /**
   * Whether running in a native app (Capacitor, React Native, Electron).
   */
  isNative: boolean

  /**
   * Whether running in a mobile app (iOS or Android).
   */
  isMobile: boolean

  /**
   * Whether running in a desktop app (Electron, macOS, Windows, Linux).
   */
  isDesktop: boolean

  /**
   * Whether running in a web browser.
   */
  isWeb: boolean

  /**
   * Whether running in development mode.
   */
  isDevelopment: boolean

  /**
   * Whether running in production mode.
   */
  isProduction: boolean

  /**
   * The user agent string (if available).
   */
  userAgent?: string

  /**
   * The app version (if available).
   */
  appVersion?: string
}

Types

Platform

Target runtime platforms: web, ios, android, electron, macos, windows, linux.

type Platform = 'web' | 'ios' | 'android' | 'electron' | 'macos' | 'windows' | 'linux'

Functions

createCapacitorApp(options)

Creates a Capacitor app coordinator.

Orchestrates native app initialization in the correct order:

  1. Wait for device ready
  2. Initialize push notifications (if configured)
  3. Handle deep links (if configured)
  4. Signal readiness
function createCapacitorApp(options?: CapacitorAppOptions): CapacitorApp
  • options — Configuration options.

Returns: A CapacitorApp instance with lifecycle, push notification, and deep link management.

detectPlatform()

Detects the current runtime platform by checking for Capacitor, Electron, React Native, and falling back to 'web'.

function detectPlatform(): Platform

Returns: The detected platform identifier.

getPlatformInfo(env)

Builds comprehensive platform information including platform type, environment flags, and user agent details.

function getPlatformInfo(env?: { isDevelopment?: boolean; isProduction?: boolean }): PlatformInfo
  • env — Optional environment overrides for development/production flags.
  • env.isDevelopment — Override for development mode detection.
  • env.isProduction — Override for production mode detection.

Returns: A PlatformInfo object with all platform details.

isPlatform(platforms)

Checks if the current platform matches any of the specified platforms.

function isPlatform(platforms?: Platform[]): boolean
  • platforms — One or more platform identifiers to check against.

Returns: true if the current platform matches any of the given platforms.

onPlatform(handlers)

Executes a platform-specific handler based on the detected platform. Falls back to the default handler if no handler matches.

function onPlatform(handlers: Partial<Record<Platform, () => T>> & { default: () => T }): T
  • handlers — A map of platform identifiers to handler functions, with a required default.

Returns: The return value of the matched (or default) handler.

platform()

Returns the current platform info, caching the result after first call.

function platform(): PlatformInfo

Returns: The cached PlatformInfo object.

resetPlatformCache()

Resets the cached platform info. Useful for testing or when the platform context changes.

function resetPlatformCache(): void

Injection Notes

Requirements

Peer dependencies:

  • @molecule/app-lifecycle ^1.0.1
  • @molecule/app-logger ^1.0.1
  • @molecule/app-push ^1.0.1

Runtime Dependencies

  • @molecule/app-lifecycle

  • @molecule/app-logger

  • @molecule/app-push

  • A mobile BROWSER is 'web', not 'ios'/'android'. isMobile means "running as a native mobile app" — Safari on an iPhone reports platform: 'web', isMobile: false. Use CSS media queries / viewport checks for responsive layout; use this package only for CAPABILITY branching (native plugins, file paths, store links, push setup).

  • Branch through {@link onPlatform}/{@link isPlatform}, never by parsing navigator.userAgent yourself — hand-rolled UA sniffing is exactly what this package exists to replace.

  • {@link platform} caches after the first call; call {@link resetPlatformCache} in tests or when the runtime context changes.