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

@mornya/platform-libs

Package Overview
Dependencies
Maintainers
0
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mornya/platform-libs

Parses UA (user-agent) information of the current platform.

  • 2.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

Platform Libs

npm node types downloads license

Parses UA (user-agent) information of the current platform.

This project has been created by Vessel CLI. For a simple and quick reference about it, click here.

About

ํ˜„์žฌ ์›น ํ”Œ๋žซํผ์—์„œ ์‚ฌ์šฉ์ž ์—์ด์ „ํŠธ ์ •๋ณด๋ฅผ ์ถ”์ถœํ•˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ.

Installation

ํ•ด๋‹น ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉ ํ•  ํ”„๋กœ์ ํŠธ์—์„œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ์˜์กด์„ฑ ๋ชจ๋“ˆ๋กœ ์„ค์น˜ํ•œ๋‹ค.

$ npm install --save @mornya/platform-libs
or
$ yarn add @mornya/platform-libs

Usage

์•„๋ž˜์™€ ๊ฐ™์ด ๋ชจ๋“ˆ์„ importํ•˜์—ฌ ์‚ฌ์šฉํ•œ๋‹ค.

import { Platform } from '@mornya/platform-libs';

Modules in the package

๋ณธ ํŒจํ‚ค์ง€์—๋Š” ์•„๋ž˜์™€ ๊ฐ™์€ ๋ชจ๋“ˆ๋“ค์„ ํฌํ•จํ•œ๋‹ค.
์ œ๊ณต๋˜๋Š” ๋ชจ๋“ˆ๊ณผ ๋ฉ”์†Œ๋“œ ์‚ฌ์šฉ๋ฒ• ๋“ฑ์€ ์ฝ”๋“œ ์Šค๋‹ˆํ•์„ ์ฐธ๊ณ ํ•œ๋‹ค.

Platform module

์ƒ˜ํ”Œ ๋ชจ๋“ˆ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฉ”์†Œ๋“œ๋“ค์„ ์ œ๊ณตํ•œ๋‹ค.

Platform.getInfo

ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ์ „๋‹ฌ๋œ ์‚ฌ์šฉ์ž ์—์ด์ „ํŠธ ๋ฌธ์ž์—ด์„ ๋ถ„์„ํ•˜์—ฌ ์ถ”์ถœ๋œ ๋‚ด์šฉ์„ ์˜ค๋ธŒ์ ํŠธ ํ˜•ํƒœ๋กœ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

import { Platform } from '@mornya/platform-libs';

const platformInfo = Platform.getInfo(navigator.userAgent);

console.log(platformInfo);

๋ฐ˜ํ™˜๋˜๋Š” ์˜ค๋ธŒ์ ํŠธ๋Š” ์•„๋ž˜ ๊ธฐ๋ณธ ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌ์กฐ๋ฅผ ์ฐธ๊ณ .

{
  // OS ๋ฒค๋” ๊ตฌ๋ถ„
  OS: {
    vendor: string; // 'AOS' | 'IOS' | 'WOS' | 'WIN' | 'MAC' | 'LINUX';
    version: string; // OS ๋ฒค๋” ๋ฒ„์ „ (semver ํ˜•ํƒœ)
  };
  // ๋ธŒ๋ผ์šฐ์ €(์›น/์•ฑ) ๊ตฌ๋ถ„ 
  Browser: {
    type: string; // 'APP' | 'MWEB' | 'PC';
    vendor: string; // 'CHROME' | 'SAFARI' | 'FIREFOX' | 'OPERA' | 'IE';
    version: string; // ๋ธŒ๋ผ์šฐ์ € ๋ฒค๋” ๋ฒ„์ „ (semver ํ˜•ํƒœ)
  };
  // UserAgent ๋ฌธ์ž์—ด ์ถ”์ถœ ์ •๋ณด
  UA: {
    productName: string;
    productVersion: string;
    systemInfo: string;
    extras?: string;
  };
  isDesktop: boolean; // ๋ฐ์Šคํฌํƒ‘ PC์—์„œ์˜ ๋ธŒ๋ผ์šฐ์ง• ์—ฌ๋ถ€
  isMobile: boolean; // ๋ชจ๋ฐ”์ผ์—์„œ์˜ ๋ธŒ๋ผ์šฐ์ง• ์—ฌ๋ถ€ (๋„ค์ดํ‹ฐ๋ธŒ ์•ฑ ์ผ๋•Œ์—๋„ true)
  isAOS: boolean; // OS๊ฐ€ Android์ธ์ง€ ์—ฌ๋ถ€
  isIOS: boolean; // OS๊ฐ€ iOS์ธ์ง€ ์—ฌ๋ถ€
}
Platform.checkVersion

semver ํ˜•ํƒœ์˜ ๋ฒ„์ „์„ ์„œ๋กœ ๋น„๊ตํ•˜์—ฌ ๋Œ€์ƒ ๋ฒ„์ „์ด ๋†’์€์ง€(1) ๊ฐ™์€์ง€(0) ๋‚ฎ์€์ง€(-1)๋ฅผ ํŒ๋ณ„ํ•œ๋‹ค.

import { Platform } from '@mornya/platform-libs';

const baseVersion = '1.0.0';
console.log(Platform.checkVersion(baseVersion, '1.1.0')); // 1
console.log(Platform.checkVersion(baseVersion, '1.0.0')); // 0
console.log(Platform.checkVersion(baseVersion, '0.9.0')); // -1
Platform.resolveMatches

์ •๊ทœ์‹์„ ์ด์šฉํ•˜์—ฌ ๋งค์น˜๋˜๋Š” ๋ธŒ๋ผ์šฐ์ € ์ •๋ณด๋ฅผ ์ปค์Šคํ„ฐ๋งˆ์ด์ฆˆํ•˜์—ฌ ์ถ”๊ฐ€ํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•œ๋‹ค.

import { Platform } from '@mornya/platform-libs';

type ExtraBrowserType = 'APP'; // ์ถ”๊ฐ€ ๋  ๋ธŒ๋ผ์šฐ์ € ํƒ€์ž…
type ExtraBrowserVendor = 'APP1' | 'APP2'; // ์ถ”๊ฐ€ ๋  ๋ธŒ๋ผ์šฐ์ € ๋ฒค๋”๋ช…

interface IPlatformExtendInfo extends Platform.Info<ExtraBrowserType, ExtraBrowserVendor> {
  isNative?: boolean;
  isAPP1?: boolean;
  isAPP2?: boolean;
}

const platformInfo = Platform.getInfo<IPlatformExtendInfo>(navigator.userAgent);

// ๋„ค์ดํ‹ฐ๋ธŒ ์•ฑ ๋ธŒ๋ผ์šฐ์ € ์ •๋ณด ๋“ฑ๋ก ์ƒ˜ํ”Œ
// UA ๋ฌธ์ž์—ด์— ์•ฑ ๊ด€๋ จ ์ •๋ณด๊ฐ€ ์žˆ์–ด์•ผ ํ•จ
// ex) my-native-app1/1.2.3
const extras = {
  APP1: [/my-native-app1\/([0-9]+)\.([0-9]+)\.([0-9]+)/],
  APP2: [/my-native-app2\/([0-9]+)\.([0-9]+)\.([0-9]+)/],
};
const { name, matches } = Platform.resolveMatches(extras, platformInfo.UA.extras);

if (['APP1', 'APP2'].includes(name)) {
  platformInfo.Browser.type = 'APP';
  platformInfo.Browser.vendor = name; // ์ •๊ทœ์‹์œผ๋กœ ๋งค์นญ๋œ ํ‚ค (APP1 or APP2)
  platformInfo.Browser.version = [matches[1], matches[2], matches[3]].join('.'); // semver ํ˜•ํƒœ
  platformInfo.isMobile = true;
  platformInfo.isNative = true;
  platformInfo.isAPP1 = name === 'APP1';
  platformInfo.isAPP2 = name === 'APP2';
} else {
  platformInfo.isNative = false;
  platformInfo.isAPP1 = false;
  platformInfo.isAPP2 = false;
}

console.info(platformInfo);
Platform.isTouchDevice

ํ˜„์žฌ ๋””๋ฐ”์ด์Šค๊ฐ€ ํ„ฐ์น˜ ๊ฐ€๋Šฅํ•œ ๋””๋ฐ”์ด์Šค์ธ์ง€ ์—ฌ๋ถ€๋ฅผ ๋ฆฌํ„ดํ•œ๋‹ค.

import { Platform } from '@mornya/platform-libs';

console.log(Platform.isTouchDevice()); // true or false

Change Log

ํ”„๋กœ์ ํŠธ ๋ณ€๊ฒฝ์‚ฌํ•ญ์€ CHANGELOG.md ํŒŒ์ผ ์ฐธ์กฐ.

License

ํ”„๋กœ์ ํŠธ ๋ผ์ด์„ผ์Šค๋Š” LICENSE ํŒŒ์ผ ์ฐธ์กฐ.

Keywords

FAQs

Package last updated on 11 Jul 2024

Did you know?

Socket

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.

Install

Related posts

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