0.1.2 • Published 7 months ago

platform-detector-js v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

Platform Detector JS

Platform Detector JS - A seamless way to identify user platforms (Windows, macOS, iOS, Android) in your JS/TS projects!

Features ✨

  • Easy-to-use API for platform detection
  • Compatible with both Browser and Node environments
  • TypeScript support

Installation 🛠️

Install platform-detector-js using npm:

npm install platform-detector-js

Quick Start 🚀

import Platform from "platform-detector-js"

const platform = new Platform()

console.log(platform.isWindows) // true/false
console.log(platform.isMacOS) // true/false
// ... and more!

Specify a custom user-agent string if needed:

const platform = new Platform("Your-Custom-User-Agent-String")

API 📘

Constructor

  • new Platform(userAgent?: string)
    • userAgent (optional): Provide a custom user agent string. If not provided, the browser's user agent string will be used (if in a browser environment).

Methods

  • getUserAgent(): string
  • setUserAgent(userAgent: string): void
  • select(specifics: { platform in PlatformOS?: T } & { default: T }): T (See Usage section for example usage of select method.)

Properties

  • isIOS: boolean
  • isAndroid: boolean
  • isWindows: boolean
  • isMacOS: boolean

Usage 📚

Basic Usage

const platform = new Platform()

if (platform.isWindows) {
  // Your Windows-specific code here
}

Using select Method

const platform = new Platform()
const value = platform.select({
  windows: "Windows Value",
  macos: "macOS Value",
  ios: "iOS Value",
  android: "Android Value",
  default: "Default Value",
})

License 📜

This project is licensed under the MIT License.

0.1.2

7 months ago

0.1.1

7 months ago

0.1.0

7 months ago