Options
All
  • Public
  • Public/Protected
  • All
Menu

tp-platform

Build Status Coverage Status npm version monthly downloads code style: prettier semantic-release UNPKG liense

Intro

Match the current platform and get the platform parameters and execute the initialization process.

tp-platform = detect-platform + get-platform-setting + customer-initialize-platform

Example

import { Platform, setupPlatform, mergeConfigs, PLATFORM_CONFIGS } from 'tp-platform';

const plt = setupPlatform({
  // configs
});

plt.platforms(); // ["core", "desktop", "mac", "web"]
plt.settings(); // {mode: "md", hoverCSS: true}
plt.versions(); // {}
console.log(plt.is('ios')); // false
console.log(plt.is('desktop')); // true

Install

NPM Badge

API

All exports here.

import { Platform, setupPlatform, mergeConfigs, PLATFORM_CONFIGS } from 'tp-platform';

new Platform(platformConfigs: PlatformConfigs)

The Platform service can be used to get information about your current device. You can get all of the platforms associated with the device using the platforms method, including whether the app is being viewed from a tablet, if it's on a mobile device or browser, and the exact platform (iOS, Android, Windows, etc). You can also get the orientation of the device, if it uses right-to-left language direction, and much much more. With this information you can completely customize your app to fit any device.

Here is the doc of Instance Members!

setupPlatform(platformConfigs: PlatformConfigs)

Setup platform with default platform configs.

  • @param {PlatformConfigs} platformConfigs - The configs to match platforms
  • @return {Platform} - Return platform instance

The code like this:

function setupPlatform(platformConfigs: PlatformConfigs): Platform {
  const _finalConf = mergeConfigs(PLATFORM_CONFIGS, platformConfigs);
  return new Platform(_finalConf);
}

mergeConfigs(defConfig: PlatformConfigs, custConfig: PlatformConfigs)

Merge Parameters, and the priority is:

  1. Custom parameters have higher priority than the default configuration, such as core configuration, custom priority is higher than the default.
  2. In the plt.platforms() array, the more advanced Platform parameters, the higher the priority is, for example: core < mobile < ios < iphone < cordova.
  3. The plain object will use assign to collect params, other types of parameters will be replaced directly.

  4. @param {PlatformConfigs} defConfig - The dist configs

  5. @param {PlatformConfigs} custConfig - The customer configs
  6. @return {PlatformConfigs}

PLATFORM_CONFIGS

Default parameters for platform configuration, Including the common platform configuration. Here is the code.

Development

  • npm t: Run test suite
  • npm start: Run npm run build in watch mode
  • npm run test:watch: Run test suite in interactive watch mode
  • npm run test:prod: Run linting and generate coverage
  • npm run build: Generate bundles and typings, create docs
  • npm run lint: Lints code
  • npm run commit: Commit using conventional commit style (husky will tell you to use it if you haven't :wink:)

Reference

License

MIT

Index

Type aliases

DocumentDirection

DocumentDirection: "ltr" | "rtl"

PlatformConfigs

PlatformConfigs: object

Type declaration

Variables

NON_TEXT_INPUT_REGEX

NON_TEXT_INPUT_REGEX: RegExp = /^(radio|checkbox|range|file|submit|reset|color|image|button)$/i

Functions

getCss

  • getCss(docEle: HTMLElement): object
  • Parameters

    • docEle: HTMLElement

    Returns object

    • Optional animationDelay?: undefined | string
    • Optional transform?: undefined | string
    • Optional transformOrigin?: undefined | string
    • Optional transition?: undefined | string
    • Optional transitionDelay?: undefined | string
    • Optional transitionDuration?: undefined | string
    • Optional transitionEnd?: undefined | string
    • Optional transitionStart?: undefined | string
    • Optional transitionTimingFn?: undefined | string

isAndroid

isCordova

isDesktop

isElectron

isIos

isIosUIWebView

  • isIosUIWebView(plt: Platform): boolean

isLinux

isMac

isMobile

isSafari

isTablet

isWKWebView

isWindows

mergeConfigs

  • name

    mergeConfigs

    description

    Merge Parameters, and the priority is:

    1. Custom parameters have higher priority than the default configuration, such as core configuration, custom priority is higher than the default.
    2. In the plt.platforms() array, the more advanced Platform parameters, the higher the priority is, such as: core < mobile < ios < iphone < cordova.
    3. The plain object will use assign to collect params, other types of parameters will be replaced directly.

    Parameters

    Returns PlatformConfigs

setupPlatform

Object literals

PLATFORM_CONFIGS

PLATFORM_CONFIGS: object

android

android: object

android

type

type: Type = Type.SYSTEM

isMatch

versionParser

settings

settings: object

autoFocusAssist

autoFocusAssist: string = "immediate"

mode

mode: string = "md"

scrollAssist

scrollAssist: boolean = true

tapPolyfill

tapPolyfill: boolean = true

cordova

cordova: object

cordova

type

type: Type = Type.ENVIRONMENT

initialize

isMatch

core

core: object

core

type

type: Type = Type.BASE

isMatch

  • isMatch(): boolean

settings

settings: object

mode

mode: string = "md"

desktop

desktop: object

desktop: 桌面

type

type: Type = Type.PLATFORM

isMatch

settings

settings: object

hoverCSS

hoverCSS: boolean = true

electron

electron: object

electron

type

type: Type = Type.ENVIRONMENT

initialize

isMatch

ios

ios: object

ios

type

type: Type = Type.SYSTEM

isMatch

versionParser

settings

settings: object

autoFocusAssist

autoFocusAssist: string = "delay"

mode

mode: string = "ios"

scrollAssist

scrollAssist: boolean = false

tapPolyfill

tapPolyfill: isIosUIWebView = isIosUIWebView

ipad

ipad: object

ipad

type

type: Type = Type.BRAND

isMatch

settings

settings: object

keyboardHeight

keyboardHeight: number = 500

iphone

iphone: object

iphone

type

type: Type = Type.BRAND

isMatch

linux

linux: object

for desktop

type

type: Type = Type.SYSTEM

isMatch

mac

mac: object

type

type: Type = Type.SYSTEM

isMatch

mobile

mobile: object

type

type: Type = Type.PLATFORM

isMatch

settings

settings: object

hoverCSS

hoverCSS: boolean = false

tablet

tablet: object

tablet: 平板电脑, pad

type

type: Type = Type.PLATFORM

isMatch

settings

settings: object

hoverCSS

hoverCSS: boolean = false

windows

windows: object

Desktop: Windows

type

type: Type = Type.SYSTEM

isMatch

settings

settings: object

autoFocusAssist

autoFocusAssist: string = "immediate"

mode

mode: string = "wp"

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc