@openmrs/esm-utils
Version:
Helper utilities for OpenMRS
15 lines (14 loc) • 634 B
JavaScript
/**
* Determines if the application should behave as if it is online.
* When offline mode is enabled (`window.offlineEnabled`), this returns the
* provided `online` parameter or falls back to `navigator.onLine`.
* When offline mode is disabled, this always returns `true`.
*
* @param online Optional override for the online status. If provided and offline
* mode is enabled, this value is returned directly.
* @returns `true` if the application should behave as online, `false` otherwise.
*
* @category Utility
*/ export function isOnline(online) {
return window.offlineEnabled ? online ?? navigator.onLine : true;
}