Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kennethanceyer/browser-detect
:globe_with_meridians: simplify detecting your browser.
https://github.com/kennethanceyer/browser-detect
browser detect javascript navigator nodejs
Last synced: 5 days ago
JSON representation
:globe_with_meridians: simplify detecting your browser.
- Host: GitHub
- URL: https://github.com/kennethanceyer/browser-detect
- Owner: KennethanCeyer
- License: mit
- Created: 2017-05-13T08:27:40.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-04-22T18:28:29.000Z (over 1 year ago)
- Last Synced: 2024-04-14T22:13:50.955Z (7 months ago)
- Topics: browser, detect, javascript, navigator, nodejs
- Language: TypeScript
- Homepage:
- Size: 1.88 MB
- Stars: 132
- Watchers: 5
- Forks: 17
- Open Issues: 34
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## :package: Installation
#### npm
```bash
$ npm install browser-detect
```#### yarn
```bash
$ yarn add browser-detect
```## :page_with_curl: Example
### Web
```html
```
```javascript
const result = browserDetect();
console.log(result);
```**output**
```javascript
{
name: 'chrome',
version: '58.0.3029',
versionNumber: 58.03029,
mobile: false,
os: 'Windows NT 10.0'
}
```### Web with module
```javascript
import browser from 'browser-detect';const result = browser();
console.log(result);
```**output**
```javascript
{
name: 'chrome',
version: '58.0.3029',
versionNumber: 58.03029,
mobile: false,
os: 'Windows NT 10.0'
}
```### NodeJS
Just simple :trollface:
```javascript
const browser = require('browser-detect');
const result = browser();console.log(result);
```**output**
```javascript
{
name: 'node',
version: '9.9.0',
versionNumber: 9.9,
mobile: false,
os: 'win32'
}
```### NodeJS with Express
```javascript
const router = express.Router();
const browser = require('browser-detect');router.get('/', req => {
const result = browser(req.headers['user-agent']);
console.log(result);
});return router;
```**output**
```javascript
{
name: 'ie',
version: '9.0',
versionNumber: 9,
mobile: false,
os: 'Windows NT 10.0'
}
```Or set a middleware and send to `res.locals`.
```javascript
// browserDetectMiddleware.js
const browser = require('browser-detect');const MiddleWare = () => req => {
res.locals.browser = browser(req.headers['user-agent']);
next();
};module.exports = MiddleWare;
``````javascript
// app.jsconst express = require('express');
const browserDetectMiddleware = require('./browserDetectMiddleware');const app = express();
app.use(browserDetectMiddleware())
```View will can access `browser` variable.
```ejs
<%=JSON.stringify(browser)%>
```**output**
```javascript
"{ name: 'firefox', version: '53.0.0', versionNumber: 53, mobile: false, os: 'Windows NT 10.0' }"
```## :page_with_curl: Demo
#### Web
- open `examples/client.html` by your browser.
#### NodeJS
- open command or terminal
- move directory to `browser-detect` path that you download
- type following code```bash
$ node ./examples/server.js
```## :zap: Type
| name | type | description | example |
| ---- | ---- | ----------- | ------- |
| name | string | a browser name | ie, chrome, firefox |
| version | string | browser or node version | 59.2.22 |
| versionNumber | number | browser or node number casted to number | 59.222 |
| mobile | boolean | if browser is in mobile environment, it will be true | true |
| os | string | os type name | Windows NT 10.0 |## :triangular_flag_on_post: Roadmap
- [x] detect browser both compatible client and server
- [x] support AMD and CommonJS module feature
- [x] support typings
- [x] support guideline and documentations for contributors
- [x] support browser compatity to IE7
- [x] support to detect mobile and OS
- [x] support CI (TravisCI)
- [x] support unit tests
- [ ] support e2e tests
- [ ] suport cdn## :mag_right: Compatibility
- [x] IE 7+
- [x] Chrome (Windows, MacOS)
- [x] Edge
- [x] Firefox
- [x] Safari (Windows, MacOS)
- [x] Opera
- [x] Android
- [x] Chromium Browsers (Will be named chrome)## :octocat: Contribution
### environment
1. clone project from Github
```bash
$ git clone [email protected]:KennethanCeyer/browser-detect.git
```2. install npm packages
```bash
$ cd browser-detect
$ npm install
```3. build sources
```bash
$ npm run build
```### test
```bash
$ npm run test
```## :yellow_heart: Contributors
- [**yarkeev**](https://github.com/yarkeev)
- [**vlewin**](https://github.com/vlewin)## :mag_right: License
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2FKennethanCeyer%2Fbrowser-detect.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2FKennethanCeyer%2Fbrowser-detect?ref=badge_large)