Platform Libs
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: {
vendor: string;
version: string;
};
Browser: {
type: string;
vendor: string;
version: string;
};
UA: {
productName: string;
productVersion: string;
systemInfo: string;
extras?: string;
};
isDesktop: boolean;
isMobile: boolean;
isAOS: boolean;
isIOS: boolean;
}
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'));
console.log(Platform.checkVersion(baseVersion, '1.0.0'));
console.log(Platform.checkVersion(baseVersion, '0.9.0'));
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);
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;
platformInfo.Browser.version = [matches[1], matches[2], matches[3]].join('.');
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());
Change Log
ํ๋ก์ ํธ ๋ณ๊ฒฝ์ฌํญ์ CHANGELOG.md ํ์ผ ์ฐธ์กฐ.
License
ํ๋ก์ ํธ ๋ผ์ด์ผ์ค๋ LICENSE ํ์ผ ์ฐธ์กฐ.