Match the current platform and get the platform parameters and execute the initialization process.
tp-platform = detect-platform + get-platform-setting + customer-initialize-platform
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
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 instanceThe 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:
core configuration, custom priority is higher than the default.plt.platforms() array, the more advanced Platform parameters,
the higher the priority is, for example: core < mobile < ios < iphone < cordova.The plain object will use assign to collect params, other types of parameters will be replaced directly.
@param {PlatformConfigs} defConfig - The dist configs
@param {PlatformConfigs} custConfig - The customer configs@return {PlatformConfigs} PLATFORM_CONFIGSDefault parameters for platform configuration, Including the common platform configuration. Here is the code.
npm t: Run test suitenpm start: Run npm run build in watch modenpm run test:watch: Run test suite in interactive watch modenpm run test:prod: Run linting and generate coveragenpm run build: Generate bundles and typings, create docsnpm run lint: Lints codenpm run commit: Commit using conventional commit style (husky will tell you to use it if you haven't :wink:)MIT
dist configs
customer configs
android
cordova
core
desktop: 桌面
electron
ios
ipad
iphone
for desktop
tablet: 平板电脑, pad
Desktop: Windows
Generated using TypeDoc
mergeConfigs
Merge Parameters, and the priority is:
coreconfiguration, custom priority is higher than the default.plt.platforms()array, the more advanced Platform parameters, the higher the priority is, such as: core < mobile < ios < iphone < cordova.assignto collect params, other types of parameters will be replaced directly.