Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
platform-detect
Advanced tools
🃏 Minimalistic isomorphic library for detection of platform, runtime, APIs and more.
🃏 Minimalistic isomorphic library for detection of platform, runtime, APIs and more.
npm install platform-detect
import * as platform from 'platform-detect'
// The script has no window or GUI to render content to.
// It only runs in console / terminal. (Might be a Node script or WebWorker)
platform.isConsole
// App has a window, access to DOM. Can render GUI.
platform.hasWindow
// Fully functional Node & core modules are available. (Might be an Electron / NWJ.JS 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)
platform.web
// App is packaged, compiled or bundled and not served from the web. Could be UWP, Electron, NW.JS, Chrome App, Cordova, etc...
platform.packaged
// Script is executed inside Web Worker.
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
Or import just what you need
import {windows, android, linux, macosx, tizen} from 'platform-detect/os.mjs'
import {chrome, edge, safari} from 'platform-detect/browser.mjs'
import {inputType, mouse, touch, touchscreen, tabletMode, formFactor} from 'platform-detect/formfactor.mjs'
if (formFactor === 'tv' && tizen) {
console.log(`I'm a Samsung Smart TV!`)
}
if (windows && edge && (uwp || pwa)) {
console.log(`I should use Fluent Design System`)
} else if (android || chromeos) {
console.log(`I should use Material Design Language`)
}
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
}
}
You can choose between the old UMD module.
<script src="./node_modules/platform-detect/index.js"></script>
var platform = self['platform-detect']
console.log('pixel ratio of this device is', platform.pixelRatio)
Or the new ES Modules.
<script type="module">
import * as platform from './node_modules/platform-detect/index.js'
platform.on('orientation', orientation => console.log(orientation))
platform.on('tabletMode', tabletMode => console.log('the device', tabletMode ? 'entered' : 'left', 'tablet mode'))
</script>
[1.0.0]
FAQs
🃏 Minimalistic isomorphic library for detection of platform, runtime, APIs and more.
The npm package platform-detect receives a total of 10,492 weekly downloads. As such, platform-detect popularity was classified as popular.
We found that platform-detect demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.