Socket
Socket
Sign inDemoInstall

uadetect

Package Overview
Dependencies
83
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.1 to 2.0.0

.vscode/launch.json

5

.vs/VSWorkspaceState.json
{
"ExpandedNodes": [
""
"",
"\\src"
],
"SelectedNode": "\\package.json",
"SelectedNode": "\\src\\ram.ts",
"PreviewInSolutionExplorer": false
}

18

.vscode/settings.json
{
"conventionalCommits.scopes": [
"semver(minor)"
]
"ci",
"config",
"git",
"prettier",
"semver(minor)",
"semver(patch)",
"semver(prerelease)",
"semver(prerelease-minor)",
"semver(prerelease-patch)",
"semver(major)",
"semver(prerelease-major)",
"types",
"tests",
"readme"
],
"typescript.tsdk": "node_modules\\typescript\\lib"
}
{
"name": "uadetect",
"version": "1.0.1",
"description": "The dead-simple way of detecting a device's User Agent",
"main": "index.js",
"version": "2.0.0",
"description": "The dead-simple way of interacting with the navigator API",
"main": "./dist/index.js",
"scripts": {

@@ -25,3 +25,17 @@ "test": "npx serve",

"UADetect",
"ua-detect"
"ua-detect",
"navigator",
"browser",
"online",
"memory",
"cookie",
"device",
"os",
"os-version",
"os-version-name",
"os-version-number",
"pdf",
"webdriver",
"logicalProcessors",
"hardwareConcurrency"
],

@@ -28,0 +42,0 @@ "author": "PorkyProductions",

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

# UA-detect
# UADetect
- [UA-detect](#ua-detect)
- [UADetect](#uadetect)
- [Description](#description)

@@ -8,3 +8,3 @@ - [Technologies Used](#technologies-used)

- [via `npm`](#via-npm)
- [Usage](#usage)
- [Documentation](#documentation)

@@ -14,4 +14,6 @@

The dead-simple way of detecting a device's user agent.
✨The dead-simple way of interacting with the navigator API.✨
It may say "UA", but we're way more than that. UADetect is the eaisiet way to interact with the navigator API. We have lots of componets, and they all are well documented in the [docs](./docs/index.md).
## Technologies Used

@@ -33,33 +35,5 @@ <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/db/Npm-logo.svg/1920px-Npm-logo.svg.png" width="30px">

In a JavaScript (or TypeScript) file, import the `uadetect` module:
```javascript
import { DetectScreenOrientation, DetectDeviceType, finiteMobileDeviceType, ORIENTATION_isLandscape, DEVICE_type, DEVICE_finiteType } from 'uadetect';
```
All done. Now you can use the `ORIENTATION_isLandscape`, `DEVICE_finiteType` and `DEVICE_type` constraints in your code.
## Documentation
## Usage
```javascript
// An example hide element on mobile devices function
function hideOnMobile(element) {
if (DEVICE_type == "mobile") {
element.style.display = "none";
}
}
```
```javascript
// An example show element on different operating systems function
function showOnOS(element, element2) {
if (DEVICE_finiteType == "iOS") {
element.style.display = "block";
}
else if (DEVICE_finiteType == "Android") {
element2.style.display = "block";
}
else {
element.style.display = "none";
element2.style.display = "none";
}
}
```
Read all about how to use the package in the [Docs](/docs/index.md)

@@ -8,74 +8,103 @@ /*

// Browser
import { browser, getBrowser } from "./browser";
// Cookies
import { getCookies, cookieStatus } from "./cookies";
// Device Type
import { DEVICE_type, DetectDeviceType } from "./DetectDeviceType";
// Do Not Track
import { doNotTrackStatus, getDoNotTrack } from "./doNotTrack";
// Finite Mobile Device Type
import {
DEVICE_finiteType,
finiteMobileDeviceType,
} from "./finiteMobileDeviceType";
// Logical Processors
import {
browserSpecificSupportCores,
processorCores,
} from "./logicalProcessors";
// Max Touch Points
import { maxTouchPoints, getMaxTouchPoints } from "./maxTouchPoints";
// Online Status
import { browserOnlineStatus } from "./online";
// standard UA
import { getCurrentUA, currentUA } from "./getCurrentUA";
// Operating System
import { OS, getOS } from "./operatingSystem";
//SCREEN ORIENTATION
let ORIENTATION_isLandscape = true;
$(document).ready(function () {
DetectScreenOrientation();
})
$(window).on("orientationchange", function (event) {
//When screen orientation changes
DetectScreenOrientation();
});
const DetectScreenOrientation = () => {
//detects orientation of device
ORIENTATION_isLandscape = (window.innerHeight <= window.innerWidth);
return ORIENTATION_isLandscape;
}
//DEVICE TYPE
function DetectDeviceType() {
const ua = navigator.userAgent;
if (/(tablet|ipad|playbook|silk)|(android(?!.*mobi))/i.test(ua)) {
return "tablet";
}
else if (/(iPhone|iPod|iPad)/i.test(ua) || /(android)/i.test(ua) || /(windows phone)/i.test(ua) || /(blackberry)/i.test(ua) || /(bb10)/i.test(ua) || /(opera mini)/i.test(ua) || /(opera mobi)/i.test(ua) || /(iemobile)/i.test(ua) || /(symbian)/i.test(ua) || /(maemo)/i.test(ua) || /(webos)/i.test(ua) || /(mobile)/i.test(ua) || /(tablet)/i.test(ua) || /(symbianos)/i.test(ua) || /(up.browser)/i.test(ua) || /(up.link)/i.test(ua) || /(mmp)/i.test(ua) || /(symbianos)/i.test(ua) || /(midp)/i.test(ua) || /(wap)/i.test(ua) || /(phone)/i.test(ua) || /(pocket)/i.test(ua) || /(mobile)/i.test(ua) || /(pda)/i.test(ua) || /(avantgo)/i.test(ua) || /(eudoraweb)/i.test(ua) || /(brew)|(bada)/i.test(ua) || /(blackberry)/i.test(ua) || /(hpwos)/i.test(ua) || /(kindle)/i.test(ua) || /(lge.netcast)/i.test(ua) || /(lg;lx)|(lg;lx)/i.test(ua) || /(lge.netcast)/i.test(ua) || /(nintendo.3ds)/i.test(ua) || /(nintendo.ds)/i.test(ua) || /(nintendo.wiiu)/i.test(ua) || /(nintendo.wii)/i.test(ua) || /(playstation.3ds)/i.test(ua) || /(playstation.ds)/i.test(ua) || /(playstation.wiiu)/i.test(ua) || /(playstation.wii)/i.test(ua) || /(webos)/i.test(ua)) {
return "mobile";
// add "| /(firefox)/i.test(ua) |" if you want to detect Firefox (not tested for mobile)
}
else {
return "desktop";
}
import {
DetectScreenOrientation,
ORIENTATION_isLandscape,
} from "./orientation";
}
let DEVICE_type = DetectDeviceType();
// PDF Viewer
function finiteMobileDeviceType() {
if (/(iPhone|iPod|iPad)/i.test(ua)) {
console.log("iOS");
return "iOS";
}
else if (/Android/i.test(ua)) {
console.log("Android");
return "Android";
}
else if (/BlackBerry/i.test(ua)) {
console.log("BlackBerry");
return "BlackBerry";
}
else if (/Windows Phone/i.test(ua)) {
console.log("Windows Phone");
return "Windows Phone";
}
else if (/webOS/i.test(ua)) {
console.log("webOS");
return "webOS";
}
else {
console.log("ERR: Unknown Device");
return "unknown";
}
}
import { PDFviewerStatus } from "./pdf";
let DEVICE_finiteType = finiteMobileDeviceType();
// RAM
import { getRam, browserSpecificSupportRAM, browserRam } from "./ram";
// Webdriver
import { robotStatus } from "./webdriver";
// Exports
// Make the functions accessible
export { DetectScreenOrientation, DetectDeviceType, finiteMobileDeviceType };
export {
DetectScreenOrientation,
DetectDeviceType,
finiteMobileDeviceType,
getCurrentUA,
getCookies,
getDoNotTrack,
getBrowser,
getRam,
browserSpecificSupportRAM,
browserSpecificSupportCores,
getMaxTouchPoints,
getOS
};
// As well as the returns on those functions
export { ORIENTATION_isLandscape, DEVICE_type, DEVICE_finiteType };
export {
ORIENTATION_isLandscape,
DEVICE_type,
DEVICE_finiteType,
currentUA,
cookieStatus,
doNotTrackStatus,
browser,
browserRam,
processorCores,
maxTouchPoints,
browserOnlineStatus,
PDFviewerStatus,
robotStatus,
OS
};
{
"compilerOptions": {
"target": "es2019",
"outDir": "./"
"outDir": "./dist/"
},
"files": [
"./src/index.ts"
],
"types": [
"jquery",
],
"typeRoots": [
"node_modules/@types"
],
"lib": [
"dom",
"es2019"
]
}

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc