1 | # vue-identify-network ⚡️
|
2 |
|
3 | [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/vinayakkulkarni/vue-identify-network/ci?logo=github-actions)](https://github.com/vinayakkulkarni/vue-identify-network/actions/workflows/ci.yml)
|
4 | [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/vinayakkulkarni/vue-identify-network/Ship%20js%20trigger?label=⛴%20Ship.js%20trigger)](https://github.com/vinayakkulkarni/vue-identify-network/actions/workflows/shipjs-trigger.yml)
|
5 | [![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/vinayakkulkarni/vue-identify-network?sort=semver&logo=github)](https://github.com/vinayakkulkarni/vue-identify-network/releases)
|
6 | [![npm](https://img.shields.io/npm/v/vue-identify-network?logo=npm)](https://www.npmjs.com/package/vue-identify-network)
|
7 | [![npm](https://img.shields.io/npm/dm/vue-identify-network?logo=npm)](http://npm-stat.com/charts.html?package=vue-identify-network)
|
8 | [![npm bundle size (version)](https://img.shields.io/bundlephobia/min/vue-identify-network/latest)](https://bundlephobia.com/package/vue-identify-network@latest)
|
9 | [![npm type definitions](https://img.shields.io/npm/types/vue-identify-network)](https://github.com/vinayakkulkarni/vue-identify-network/blob/master/package.json)
|
10 | [![DeepScan grade](https://deepscan.io/api/teams/9055/projects/18331/branches/446995/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=9055&pid=18331&bid=446995)
|
11 | [![Snyk Vulnerabilities for GitHub Repo](https://img.shields.io/snyk/vulnerabilities/github/vinayakkulkarni/vue-identify-network)](https://snyk.io/test/github/vinayakkulkarni/vue-identify-network)
|
12 | [![LGTM Alerts](https://img.shields.io/lgtm/alerts/github/vinayakkulkarni/vue-identify-network?logo=lgtm)](https://lgtm.com/projects/g/vinayakkulkarni/vue-identify-network/alerts/)
|
13 | [![LGTM Grade](https://img.shields.io/lgtm/grade/javascript/github/vinayakkulkarni/vue-identify-network?logo=lgtm)](https://lgtm.com/projects/g/vinayakkulkarni/vue-identify-network/context:javascript)
|
14 | [![GitHub contributors](https://img.shields.io/github/contributors/vinayakkulkarni/vue-identify-network)](https://github.com/vinayakkulkarni/vue-identify-network/graphs/contributors)
|
15 |
|
16 | [![built using janak](https://img.shields.io/badge/built%20using-janak-brightgreen)](https://github.com/vinayakkulkarni/janak)
|
17 | [![eslint](https://img.shields.io/npm/dependency-version/vue-identify-network/dev/eslint?logo=eslint)](https://eslint.org/)
|
18 | [![prettier](https://img.shields.io/npm/dependency-version/vue-identify-network/dev/prettier?logo=prettier)](https://prettier.io/)
|
19 | [![rollup](https://img.shields.io/npm/dependency-version/vue-identify-network/dev/rollup?logo=rollup.js)](https://rollupjs.org/guide/en/)
|
20 | [![vue](https://img.shields.io/npm/dependency-version/vue-identify-network/dev/vue?logo=vue.js)](https://vuejs.org/)
|
21 | [![typescript](https://img.shields.io/npm/dependency-version/vue-identify-network/dev/typescript?logo=TypeScript)](https://www.typescriptlang.org/)
|
22 |
|
23 | ## Features
|
24 |
|
25 | * Identify the Internet Speed ⚡️ your users have.
|
26 | * Built from scratch usign Vue 2 & Composition API with TypeScript
|
27 | * For Vue 2.x version – `npm i vue-identify-network@2`
|
28 | * For Vue 3.x version – `npm i vue-identify-network@3`
|
29 |
|
30 |
|
31 | ## Table of Contents
|
32 |
|
33 | - [vue-identify-network ⚡️](#vue-identify-network-️)
|
34 | - [Features](#features)
|
35 | - [Table of Contents](#table-of-contents)
|
36 | - [Demo](#demo)
|
37 | - [Requirements](#requirements)
|
38 | - [Installation](#installation)
|
39 | - [Build Setup](#build-setup)
|
40 | - [Usage](#usage)
|
41 | - [Globally](#globally)
|
42 | - [As a component](#as-a-component)
|
43 | - [As a plugin](#as-a-plugin)
|
44 | - [Locally](#locally)
|
45 | - [Example](#example)
|
46 | - [API](#api)
|
47 | - [Slots](#slots)
|
48 | - [Props](#props)
|
49 | - [Events](#events)
|
50 | - [Built with](#built-with)
|
51 | - [Contributing](#contributing)
|
52 | - [Author](#author)
|
53 |
|
54 | ## Demo
|
55 |
|
56 | [![Edit vue-identify-network-demo](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/friendly-swartz-7rpqv?fontsize=14&hidenavigation=1&theme=dark)
|
57 |
|
58 | ## Requirements
|
59 |
|
60 | * [vue](https://vuejs.org/) `^2.x`
|
61 | * [@vue/composition-api](https://v3.vuejs.org/guide/composition-api-introduction.html) `^1.x`
|
62 |
|
63 | ### Installation
|
64 |
|
65 | ```sh
|
66 | npm install --save vue-identify-network
|
67 | npm install --save-dev @vue/composition-api
|
68 | ```
|
69 |
|
70 | CDN: [UNPKG](https://unpkg.com/vue-identify-network/dist/) | [jsDelivr](https://cdn.jsdelivr.net/npm/vue-identify-network/dist/) (available as `window.VueIdentifyNetwork`)
|
71 |
|
72 | ### Build Setup
|
73 |
|
74 | ``` bash
|
75 | # install dependencies
|
76 | $ npm ci
|
77 |
|
78 | # package the library
|
79 | $ npm run build
|
80 | ```
|
81 |
|
82 |
|
83 | ## Usage
|
84 |
|
85 | ### Globally
|
86 |
|
87 | #### As a component
|
88 | ```javascript
|
89 | Vue.component('VueIdentifyNetwork', require('vue-identify-network'));
|
90 | ```
|
91 |
|
92 | #### As a plugin
|
93 |
|
94 | ```javascript
|
95 | import Vue from 'vue';
|
96 | import VueIdentifyNetwork from 'vue-identify-network';
|
97 |
|
98 | Vue.use(VueIdentifyNetwork);
|
99 | ```
|
100 |
|
101 | ### Locally
|
102 |
|
103 | ```javascript
|
104 | import { VueIdentifyNetwork } from 'vue-identify-network';
|
105 | ```
|
106 |
|
107 | #### Example
|
108 | <details>
|
109 | <summary>Locally imported as a component</summary>
|
110 | <br />
|
111 |
|
112 | ```html
|
113 | <vue-identify-network
|
114 | @network-type="handleNetworkIdentified"
|
115 | @network-speed="handleNetworkSpeed"
|
116 | >
|
117 | <template #unknown>
|
118 | REEE! Unable to identify your network type.
|
119 | </template>
|
120 | <template #slow>
|
121 | <img src="cat.gif" alt="you got slow internet" />
|
122 | </template>
|
123 | <template #fast>
|
124 | <video width="400" controls>
|
125 | <source src="mov_bbb.mp4" type="video/mp4" />
|
126 | <source src="mov_bbb.ogg" type="video/ogg" />
|
127 | Your browser does not support HTML5 video.
|
128 | </video>
|
129 | </template>
|
130 | </vue-identify-network>
|
131 | ```
|
132 |
|
133 | ```typescript
|
134 | import { VueIdentifyNetwork } from 'vue-identify-network';
|
135 |
|
136 | Vue.component('example-component', {
|
137 | components: {
|
138 | VueIdentifyNetwork
|
139 | },
|
140 | setup() {
|
141 | function handleNetworkIdentified(type: string) {
|
142 | console.log('connection type: ', type);
|
143 | }
|
144 | function handleNetworkSpeed(speed: number) {
|
145 | console.log('downlink: ', speed);
|
146 | }
|
147 | }
|
148 | });
|
149 | ```
|
150 | </details>
|
151 |
|
152 |
|
153 | ## API
|
154 |
|
155 | ### Slots
|
156 | | Name | Description |
|
157 | | -------------- | ----------------------------------------------------------- |
|
158 | | `unknown` | Named slot for when the type of connection is unidentifyable |
|
159 | | `slow` | Named slot for when `navigator.connection.effectiveType === '2g'` |
|
160 | | `fast` | Named slot for when `navigator.connection.effectiveType !== '2g'` |
|
161 | ### Props
|
162 |
|
163 | | Name | Type | Required? | Default | Description |
|
164 | | -------------- | ------ | --------- | --------- | ----------------------------------------------------------- |
|
165 | | `unknown-class` | String | No | null | Styling the `div` which you want to give if network type is undetected. |
|
166 | | `slow-class` | String | No | null | Styling the `div` which you want to give if network type is slow. |
|
167 | | `fast-class` | String | No | null | Styling the `div` which you want to give if network type is fast. |
|
168 |
|
169 | ### Events
|
170 |
|
171 | | Name | Returns | Description |
|
172 | | --- | --- | --- |
|
173 | | `@network-type` | String | Emits a string value |
|
174 | | `@network-speed` | String | Emits a number value |
|
175 |
|
176 | ## Built with
|
177 |
|
178 | - [TypeScript](https://www.typescriptlang.org/).
|
179 | - [Vue 2](https://v3.vuejs.org)
|
180 |
|
181 | ## Contributing
|
182 |
|
183 | 1. Fork it ( [https://github.com/vinayakkulkarni/vue-identify-network/fork](https://github.com/vinayakkulkarni/vue-identify-network/fork) )
|
184 | 2. Create your feature branch (`git checkout -b feat/new-feature`)
|
185 | 3. Commit your changes (`git commit -Sam 'feat: add feature'`)
|
186 | 4. Push to the branch (`git push origin feat/new-feature`)
|
187 | 5. Create a new [Pull Request](https://github.com/vinayakkulkarni/vue-identify-network/compare)
|
188 |
|
189 | _Note_:
|
190 | 1. Please contribute using [Github Flow](https://guides.github.com/introduction/flow/)
|
191 | 2. Commits & PRs will be allowed only if the commit messages & PR titles follow the [conventional commit standard](https://www.conventionalcommits.org/), _read more about it [here](https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional#type-enum)_
|
192 | 3. PS. Ensure your commits are signed. _[Read why](https://withblue.ink/2020/05/17/how-and-why-to-sign-git-commits.html)_
|
193 |
|
194 |
|
195 | ## Author
|
196 |
|
197 | **vue-identify-network** © [Vinayak](https://vinayakkulkarni.dev), Released under the [MIT](./LICENSE) License.<br>
|
198 | Authored and maintained by Vinayak Kulkarni with help from contributors ([list](https://github.com/vinayakkulkarni/vue-identify-network/contributors)).
|
199 |
|
200 | > [vinayakkulkarni.dev](https://vinayakkulkarni.dev) · GitHub [@vinayakkulkarni](https://github.com/vinayakkulkarni) · Twitter [@\_vinayak_k](https://twitter.com/_vinayak_k)
|