{"library":"offline-detector","title":"Offline Detector","description":"offline-detector is a lightweight TypeScript library designed for robustly detecting network online/offline status exclusively within browser environments. Its current stable version is 1.1.1. The library differentiates itself by combining native browser `online`/`offline` events with intelligent network verification through configurable polling, which significantly enhances detection accuracy. It is built to be bundler-agnostic, supporting modern tools like Webpack, Vite, and Rollup, and is tree-shakable for minimal bundle size. Development is active, with recent minor and patch releases introducing features like network polling (v1.1.0) and updating Node.js engine requirements for development/testing (v1.1.1). It provides full TypeScript support, debounced state changes to prevent rapid status fluctuations, and extensive configuration options for customizing network tests and event handling.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install offline-detector"],"cli":null},"imports":["import { createOfflineDetector } from 'offline-detector';","import type { OfflineDetectorOptions } from 'offline-detector';","import type { OfflineDetector } from 'offline-detector';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { createOfflineDetector } from 'offline-detector';\n\nconst detector = createOfflineDetector({\n  onOnline: () => console.log('Back online!'),\n  onOffline: () => console.log('Gone offline!'),\n  networkVerification: {\n    enabled: true,\n    url: 'https://check.day.app/status.txt', // Example reliable endpoint\n    requestTimeout: 3000,\n    interval: 30000\n  }\n});\n\n// Start monitoring network status\ndetector.start();\n\n// Check current status at any time\nconsole.log('Current status:', detector.isOnline() ? 'Online' : 'Offline');\n\n// Simulate stopping after a while (e.g., component unmount)\nsetTimeout(() => {\n  detector.stop();\n  console.log('Detector stopped.');\n  detector.destroy(); // Clean up resources\n}, 10000);\n","lang":"typescript","description":"This quickstart initializes the offline detector, starts monitoring network status, and logs changes. It also demonstrates checking the current status and properly stopping/destroying the detector.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}