{"id":18569021,"url":"https://github.com/filipchalupa/connection-state","last_synced_at":"2025-05-15T21:08:45.819Z","repository":{"id":163477687,"uuid":"638954410","full_name":"FilipChalupa/connection-state","owner":"FilipChalupa","description":"Detect online and offline network state.","archived":false,"fork":false,"pushed_at":"2023-05-10T15:59:25.000Z","size":398,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-15T21:08:19.000Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/connection-state","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FilipChalupa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-10T13:03:38.000Z","updated_at":"2023-12-29T12:12:37.000Z","dependencies_parsed_at":"2023-09-07T01:31:01.840Z","dependency_job_id":null,"html_url":"https://github.com/FilipChalupa/connection-state","commit_stats":{"total_commits":15,"total_committers":1,"mean_commits":15.0,"dds":0.0,"last_synced_commit":"7ef723e8002234fc6afe515c89411448a09c2518"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FilipChalupa%2Fconnection-state","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FilipChalupa%2Fconnection-state/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FilipChalupa%2Fconnection-state/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FilipChalupa%2Fconnection-state/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FilipChalupa","download_url":"https://codeload.github.com/FilipChalupa/connection-state/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254422798,"owners_count":22068681,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T22:31:41.534Z","updated_at":"2025-05-15T21:08:45.671Z","avatar_url":"https://github.com/FilipChalupa.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Connection state [![npm](https://img.shields.io/npm/v/connection-state.svg)](https://www.npmjs.com/package/connection-state) ![npm type definitions](https://img.shields.io/npm/types/connection-state.svg)\n\nDetect online and offline network state.\n\nYou can see it in action here [filipchalupa.cz/connection-state](https://filipchalupa.cz/connection-state/). Try to disconnect your device from the internet after loading the page.\n\n## Installation\n\n```bash\nnpm install connection-state\n```\n\n## Usage\n\n```js\nimport { connectionState } from 'connection-state'\n\nconst connection = connectionState()\n\nconsole.log(`You are ${connection.getState()}.`)\n// connection.getState() returns 'online' or 'offline'\n\nconnection.addListener((state) =\u003e {\n\tconsole.log(`Your connection state has changed. You are now ${state}.`)\n})\n// state is 'online' or 'offline'\n```\n\n### Endpoints\n\nYou can specify endpoints to check if you are online. The library will try to fetch the endpoints. If it succeeds, you are online. If it fails, you are offline.\n\n```js\nconst connection = connectionState({\n\tendpoints: ['https://www.google.com'],\n})\n```\n\n## Development\n\n- Install dependencies: `npm ci`\n- Run: `npm run dev`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffilipchalupa%2Fconnection-state","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffilipchalupa%2Fconnection-state","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffilipchalupa%2Fconnection-state/lists"}