Overview
@morjs/api is the runtime API package used inside mini-program source code. It exposes a single mor object that wraps the platform’s native global API (wx, my, etc.) with normalization logic, plus utilities for module management (subpackages and plugins) and environment detection.
| Property | Value |
|---|---|
| Package | @morjs/api |
| Version | 1.0.69 |
| License | ISC |
| Node | >= 12.13.0 |
| Exports | CommonJS (lib/) and ESM (esm/) |
In most projects you use
@morjs/core rather than @morjs/api directly. @morjs/core imports @morjs/api internally and re-exports the parts your app code needs. Use @morjs/api only when you need low-level access to the API object or module manager without the full App/Page/Component abstractions.Installation
Exports
@morjs/api re-exports everything from @morjs/runtime-base and adds:
Default export — mor
mor object implements the MorAPI interface:
createApi
Create a custom MorAPI instance, optionally with adapter plugins:
Array of adapter objects. Each adapter may implement
initApi(api, options) to add or override methods on the MorAPI object.Options passed through to each adapter’s
initApi call.MorAPIAdapter interface
Module manager exports
@morjs/api also exports the module management layer used for integrating subpackages and plugins at runtime:
ModuleTypes enum
| Value | Description |
|---|---|
SUBPACKAGE | A lazy-loaded subpackage module |
DYNAMIC_PLUGIN | A dynamically loaded plugin module (Alipay only) |
STATIC_PLUGIN | A statically loaded plugin module |
IModuleItem interface
Re-exports from @morjs/runtime-base
All exports from @morjs/runtime-base are available from @morjs/api:
| Export | Description |
|---|---|
ENV_TYPE | Enum: WECHAT, ALIPAY, QQ, BAIDU, DINGDING, TAOBAO, BYTEDANCE, KUAISHOU, WEB |
ENV_TYPE_DESC | Human-readable descriptions for each ENV_TYPE |
getEnv() | Returns the current ENV_TYPE value at runtime |
getGlobalObject() | Returns the platform global object (wx, my, etc.) |
logger | Shared logger instance |
event | Cross-platform event emitter |
transformApis | Internal API transform utility used by platform adapters |
markAsUnsupport | Mark an API method as unsupported on a given platform |