Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

platform-detect

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

platform-detect - npm Package Compare versions

Comparing version 1.2.0 to 2.0.1

2

index.js

@@ -1,1 +0,1 @@

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define("platform-detect",n):e["platform-detect"]=n()}(this,function(){"use strict";function e(e,n){var t=window.matchMedia(e);n(t.matches);var o=()=>n(t.matches);return t.addListener(o),()=>t.removeListener(o)}function n(e,n){Z[e]=Z[e]||new Set,Z[e].add(n)}function t(e,n){Z[e]&&Z[e].delete(n)}function o(e,n){Z[e]&&Z[e].forEach(e=>e(n))}function i(e){w=e,m=!e,g=e,o("inputType",p=e?"touch":"mouse"),o("tabletMode",g);var n=r();n!==u&&(o("formFactor",u),u=n)}function r(){return y.includes("TV")?"tv":w&&ne<600?"phone":w?"tablet":v?"laptop":"desktop"}var c="undefined"!=typeof navigator&&"undefined"!=typeof window;if(c&&"undefined"!=typeof nw)try{nw.Window.get()}catch(e){c=!1}var s,d,a,u,f,l,p,w,m,g,v,h=!c,y=c?navigator.userAgent:void 0,b=Object.freeze({get hasWindow(){return c},isConsole:h,ua:y,registerQuery:e}),x="undefined"!=typeof process&&!!process.versions&&!!process.versions.node,k=c&&window.matchMedia("(display-mode: standalone)").matches&&null!==document.head.querySelector('[rel="manifest"]'),O="undefined"!=typeof Windows&&"undefined"!=typeof MSApp,j=!(!x||!process.versions.nw),M=!(!x||!process.versions.electron),S=!(!c||!window.cordova),z=O||j||M||S||!1,P=!x&&!z,W=P&&!k,A=!c&&"undefined"!=typeof self&&void 0!==self.importScripts,E=A&&!!navigator.serviceWorker.controller,F=Object.freeze({node:x,pwa:k,uwp:O,nwjs:j,electron:M,cordova:S,chromeapp:!1,packaged:z,web:P,website:W,worker:A,serviceWorker:E}),L=!!c&&y.includes("Android"),T=!!c&&y.includes("CrOS"),C=!!c&&y.includes("Tizen"),B=c&&/iPad|iPhone|iPod/.test(y)&&!window.MSStream||!1,D=L||C,N=x?"win32"===process.platform:y.includes("Windows"),V=x?"darwin"===process.platform:y.includes("Macintosh"),_=x?"linux"===process.platform:y.includes("Linux")&&!D,q=Object.freeze({android:L,chromeos:T,tizen:C,ios:B,linuxBased:D,windows:N,macos:V,linux:_}),H=c&&y.includes("Edge/"),Q=c&&y.includes("Chrome")&&!H,R=c&&y.includes("Safari")&&!Q&&!H,G=c&&y.includes("Opera"),I=c&&y.includes("Firefox"),J=H,K=Q,U=K||R,X=I,Y=Object.freeze({edge:H,chrome:Q,safari:R,opera:G,firefox:I,edgeHtml:J,blink:K,webkit:U,gecko:X}),Z={};if(c){f=parseFloat(window.devicePixelRatio.toFixed(2)),l=navigator.maxTouchPoints>0;var $=window.screen.width,ee=window.screen.height,ne=Math.min($,ee);e("(orientation: portrait)",e=>{d=e;a=!e;s=e?"portrait":"landscape";o("orientation",s)}),H?i(l):e("(pointer: coarse)",i)}var te=Object.freeze({on:n,removeListener:t,get orientation(){return s},get portrait(){return d},get landscape(){return a},get formFactor(){return u},get pixelRatio(){return f},get touchscreen(){return l},get inputType(){return p},get touch(){return w},get mouse(){return m},get tabletMode(){return g},hasBattery:v}),oe=O||!1,ie=!1;if(j)ie="sdk"===process.versions["nw-flavor"];else if(M)ie=process.execPath.replace(/\\/g,"/").includes("node_modules/electron/");else if(O)ie=Windows.ApplicationModel.Package.current.isDevelopmentMode;else if(P){let e=/./;e.toString=(()=>ie=!0),console.log("%c",e)}else x&&(ie="production"!==process.env.NODE_ENV);var re=Object.freeze({csp:oe,get dev(){return ie}});return Object.assign({},b,F,q,Y,te,re)});
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?module.exports=o():"function"==typeof define&&define.amd?define("platform-detect",o):e["platform-detect"]=o()}(this,function(){"use strict";function e(e,o){var n=window.matchMedia(e);o(n.matches);var i=()=>o(n.matches);return n.addListener(i),()=>n.removeListener(i)}function o(e,o){a[e]&&a[e].forEach(e=>e(o))}function n(){return t.tv?"tv":t.touch&&s<600?"phone":t.touch&&!t.mouse?"tablet":t.battery?"laptop":"desktop"}var i="undefined"!=typeof navigator&&"undefined"!=typeof window;if(i&&"undefined"!=typeof nw)try{nw.Window.get()}catch(e){i=!1}var t={gui:i,terminal:!i},d=i?navigator.userAgent:void 0;t.node="undefined"!=typeof process&&!!process.versions&&!!process.versions.node,t.pwa=t.gui&&window.matchMedia("(display-mode: standalone)").matches&&null!==document.head.querySelector('[rel="manifest"]'),t.uwp="undefined"!=typeof Windows&&"undefined"!=typeof MSApp,t.nwjs=!(!t.node||!process.versions.nw),t.electron=!(!t.node||!process.versions.electron),t.cordova=!(!t.gui||!window.cordova),t.chromeapp=void 0,t.packaged=t.uwp||t.nwjs||t.electron||t.cordova||t.chromeapp,t.web=!t.node&&!t.packaged,t.website=t.web&&!t.pwa,t.worker=!t.gui&&"undefined"!=typeof self&&void 0!==self.importScripts,t.android=!!t.gui&&d.includes("Android"),t.chromeos=!!t.gui&&d.includes("CrOS"),t.tizen=!!t.gui&&d.includes("Tizen"),t.ios=t.gui&&/iPad|iPhone|iPod/.test(d)&&!window.MSStream||!1,t.linuxBased=t.android||t.tizen,t.windows=t.node?"win32"===process.platform:d.includes("Windows"),t.macos=t.node?"darwin"===process.platform:d.includes("Macintosh"),t.linux=t.node?"linux"===process.platform:d.includes("Linux")&&!t.linuxBased&&!t.macos,t.edge=t.gui&&d.includes("Edge/"),t.chrome=t.gui&&d.includes("Chrome")&&!t.edge,t.safari=t.gui&&d.includes("Safari")&&!t.chrome&&!t.edge,t.opera=t.gui&&d.includes("Opera"),t.firefox=t.gui&&d.includes("Firefox"),t.edgeHtml=t.edge,t.blink=t.chrome,t.webkit=t.blink||t.safari,t.gecko=t.firefox;var a={};if(t.on=function(e,o){a[e]=a[e]||new Set,a[e].add(o)},t.removeListener=function(e,o){a[e]&&a[e].delete(o)},t.gui)if(t.pixelRatio=parseFloat(window.devicePixelRatio.toFixed(2)),t.gameconsole=d.includes("Xbox")||d.includes("PlayStation"),t.gameconsole)t.gamepad=!0,t.mouse=!0,t.touch=!1,t.tv=!0,t.battery=!1,t.phone=t.tablet=t.hybrid=t.laptop=t.desktop=!1,t.gamepads=0,window.addEventListener("gamepadconnected",e=>t.gamepads++),window.addEventListener("gamepaddisconnected",e=>t.gamepads--);else{t.touch=navigator.maxTouchPoints>0,t.tv=d.includes("TV");var r=navigator.getGamepads();t.gamepad=!!r&&Array.from(r).some(e=>null!==e),e("(orientation: portrait)",e=>{t.portrait=e;t.landscape=!e;t.orientation=e?"portrait":"landscape";o("portrait",t.portrait);o("landscape",t.landscape);o("orientation",t.orientation)}),e("(any-pointer: coarse)",e=>{t.touch=e;o("touch",t.touch)}),e("(hover: hover)",e=>{t.mouse=e;t.input=e?"mouse":"touch";t.formFactor=n();o("mouse",t.mouse);o("input",t.input);o("formFactor",t.formFactor)});var s=Math.min(window.screen.width,window.screen.height)}if(t.csp=t.uwp||t.chromeapp||!1,t.nwjs)t.dev="sdk"===process.versions["nw-flavor"];else if(t.electron)t.dev=process.execPath.replace(/\\/g,"/").includes("node_modules/electron/");else if(t.uwp)t.dev=Windows.ApplicationModel.Package.current.isDevelopmentMode;else if(t.web){let e=/./;e.toString=(()=>t.dev=!0),console.log("%c",e)}else t.node?t.dev="production"!==process.env.NODE_ENV:t.dev=!1;return t});
{
"name": "platform-detect",
"version": "1.2.0",
"version": "2.0.1",
"description": "🃏 Minimalistic isomorphic library for detection of platform, runtime, APIs and more.",
"author": "Mike Kovarik",
"license": "MIT",
"keywords": [
"platform",
"detect",
"browser",
"node",
"pwa",
"web",
"chromium",
"uwp",
"electron",
"touch",
"tablet",
"phone",
"os",
"formfactor"
],
"homepage": "http://mutiny.cz/platform-detect",
"bugs": "https://github.com/MikeKovarik/platform-detect/issues/",

@@ -17,3 +34,3 @@ "repository": {

"devDependencies": {
"rollup": "^0.59.4",
"rollup": "^1.11.3",
"rollup-plugin-notify": "^1.0.1",

@@ -20,0 +37,0 @@ "rollup-plugin-uglify-es": "0.0.1"

# platform-detect
[![Build Status](https://travis-ci.org/MikeKovarik/platform-detect.svg)](https://travis-ci.org/MikeKovarik/platform-detect)
[![NPM](https://img.shields.io/npm/v/platform-detect.svg)](https://www.npmjs.com/package/platform-detect)
[![License](http://img.shields.io/npm/l/platform-detect.svg?style=flat)](LICENSE)
[![Dependency Status](https://david-dm.org/MikeKovarik/platform-detect.svg)](https://david-dm.org/MikeKovarik/platform-detect)
[![devDependency Status](https://david-dm.org/MikeKovarik/platform-detect/dev-status.svg)](https://david-dm.org/MikeKovarik/platform-detect#info=devDependencies)
[![Maintenance Status](http://img.shields.io/badge/status-maintained-brightgreen.svg)](https://github.com/MikeKovarik/platform-detect/pulse)
[![Known Vulnerabilities](https://snyk.io/test/github/MikeKovarik/platform-detect/badge.svg)](https://snyk.io/test/github/MikeKovarik/platform-detect)
[![Maintainability](https://api.codeclimate.com/v1/badges/f4c0ee405c46126d6325/maintainability)](https://codeclimate.com/github/MikeKovarik/platform-detect/maintainability)
[![Discord](https://img.shields.io/discord/419198557363634178.svg)](https://discord.gg/v2mUmeD)
[![Gitter](https://badges.gitter.im/MikeKovarik/platform-detect.svg)](https://gitter.im/MikeKovarik/platform-detect?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Maintainability](https://api.codeclimate.com/v1/badges/f4c0ee405c46126d6325/maintainability)](https://codeclimate.com/github/MikeKovarik/platform-detect/maintainability)

@@ -40,17 +42,20 @@ 🃏 Minimalistic isomorphic library for detection of platform, runtime, APIs and more.

Import everything
```js
import platform from 'platform-detect'
// The script has no window or GUI to render content to.
// The script has no GUI to render content to.
// It only runs in console / terminal. (Might be a Node script or WebWorker)
platform.isConsole
platform.terminal
// App has a window, access to DOM. Can render GUI.
platform.hasWindow
platform.gui
```
// Fully functional Node & core modules are available. (Might be an Electron / NWJ.JS app or a good old Node console script)
```js
var platform = require('platform-detect')
// Fully functional Node & core modules are available. (Might be an Electron / NWJS app or a good old Node console script)
platform.node
// App has been loaded as a plain website in a browser.
platform.website
// App is served from web (could be website or PWA)
// App is served from the web (could be website or PWA)
platform.web

@@ -61,9 +66,2 @@ // App is packaged, compiled or bundled and not served from the web. Could be UWP, Electron, NW.JS, Chrome App, Cordova, etc...

platform.worker
// App has been loaded as a PWA / UWP / Electron / NW.JS / Cordova app
platform.pwa
platform.uwp
platform.electron
platform.nwjs
platform.cordova
```

@@ -76,3 +74,3 @@

import {chrome, edge, safari} from 'platform-detect/browser.mjs'
import {inputType, mouse, touch, touchscreen, tabletMode, formFactor} from 'platform-detect/formfactor.mjs'
import {input, mouse, touch, formFactor} from 'platform-detect/formfactor.mjs'

@@ -89,9 +87,10 @@ if (formFactor === 'tv' && tizen) {

if (touchscreen) {
console.log(`This is a device with touchscreen`)
if (!touch) {
console.log(`But mouse is currently the primary input type`)
console.log('inputType', inputType) // 'mouse'
console.log(`The device is likely in tablet mode (Surface Pro with attached keyboard)`)
console.log('tabletMode', tabletMode) // true
if (touch) {
console.log(`I'm a device with touchscreen`)
if (mouse) {
console.log(`But I also have a mouse (it's the primary input type now)`)
console.log(`I'm a laptop with touchscreen or a Surface Pro with attached keyboard`)
} else {
console.log(`Mouse is currently not the primary input type`)
console.log(`I might be phone, tablet, or Surface Pro in tablet mode`)
}

@@ -106,7 +105,6 @@ }

<script src="./node_modules/platform-detect/index.js"></script>
```
```js
var platform = self['platform-detect']
<script>
var platform = window['platform-detect']
console.log('pixel ratio of this device is', platform.pixelRatio)
</script>
```

@@ -118,6 +116,5 @@

<script type="module">
import platform from './node_modules/platform-detect/index.js'
import platform from './node_modules/platform-detect/index.mjs'
console.log(platform.pwa ? `I'm installed PWA app` : `I'm just a website`)
platform.on('orientation', orientation => console.log(orientation))
platform.on('tabletMode', tabletMode => console.log('the device', tabletMode ? 'entered' : 'left', 'tablet mode'))
</script>

@@ -128,7 +125,98 @@ ```

[Check out the demo for full table of APIs](http://htmlpreview.github.io/?https://github.com/MikeKovarik/platform-detect/blob/master/example.html)
[Check out the demo for full table of APIs](http://htmlpreview.github.io/?https://github.com/MikeKovarik/platform-detect/blob/master/demo.html)
## Ideas for the future
By importing the `index.js` bundle you get all of the below. Or you can pick only certain file with the checks you need.
* **`terminal`** bool
<br>Script running in console or terminal (Node, Worker)
* **`gui`** bool
<br>App has a window, access to DOM. Can render GUI
### `runtime.mjs`
* **`node`** bool
<br>True when Node.js & core modules are available. (Node, Electron, NWJS app)
* **`pwa`** bool
<br>App has been loaded as a PWA with separate window. Not just a plain website.
* **`web`** bool
<br>App is served from the web (could be website or PWA)
* **`website`** bool
<br>App has been loaded as a plain website in a browser (and is not PWA)
* **`packaged`** bool
<br>App is packaged, compiled or bundled and not served from the web (UWP, Electron, NW.JS, Chrome App, Cordova, etc...)
* **`worker`** bool
<br>Script is executed inside Web Worker
* **`nwjs`** bool
* **`electron`** bool
* **`cordova`** bool
* **`uwp`** bool
* ~~**`chromeapp`** bool~~
### `formfactor.mjs`
* **`orientation`** string, event
<br>values: `portrait` or `landscape`
* **`portrait`** bool, event
* **`landscape`** bool, event
* **`formFactor`** string, event
<br>values: `phone`, `tablet`, `desktop` or `tv`
* **`pixelRatio`** float
<br>number of the scale of how many physical pixels are used to render one logical pixel.
* **`input`** string, event
<br>values: `mouse` or `touch`
<br>Current primary input type. It's watched and may change when keyboard attached/detached on hybrid devices.
* **`touch`** bool
<br>Always `true` if the device has a touchscreen, regardless of current primary input type, tablet mode, etc...
* **`mouse`** bool, event
<br>True when primary input type is mouse (desktops, laptops, hybrid with attached keyboards)
* **`gamepad`** bool
### `browser.mjs`
Browsers:
* **`edge`** bool
* **`chrome`** bool
* **`safari`** bool
* **`opera`** bool
* **`firefox`** bool
Rendering engines:
* **`edgeHtml`** bool
* **`blink`** bool
* **`webkit`** bool
* **`gecko`** bool
### `os.mjs`
* **`android`** bool
* **`chromeos`** bool
* **`tizen`** bool
* **`ios`** bool
* **`linuxBased`** bool
* **`windows`** bool
* **`macos`** bool
* **`linux`** bool
### Events
Some aspects can change during app's life. You can listen to these changes with EventEmitter-like api.
```js
platform.on('orientation', orientation => console.log('orientation changed': orientation))
platform.on('input', input => {
if (input === 'mouse)
console.log('keyboard attached')
else
console.log('tablet mode')
})
```
## TO-DOs & Ideas for the future
* even better documentation
* fix dev mode detection
* battery (platform.hasBattery)
* battery saver mode (there's hardly any battery api, let alone battery saver in it)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc