TypeScript foundation for Ionic Native plugin wrappers providing decorators, base classes, and utilities for Cordova/Capacitor integration
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Ionic Native Core provides the foundational infrastructure for TypeScript wrappers for Cordova and Capacitor plugins. It offers a comprehensive decorator system, base classes, and utilities that transform callback-based plugin interfaces into Promise and Observable patterns compatible with modern JavaScript frameworks.
npm install @ionic-native/coreimport { IonicNativePlugin } from "@ionic-native/core";For decorators:
import {
Cordova,
CordovaProperty,
CordovaInstance,
Plugin
} from "@ionic-native/core";For utilities:
import {
checkAvailability,
wrap,
getPromise
} from "@ionic-native/core";For Observable support (requires RxJS):
import { Observable } from "rxjs";Create a plugin wrapper by extending IonicNativePlugin and using decorators:
import { IonicNativePlugin, Plugin, Cordova } from "@ionic-native/core";
@Plugin({
pluginName: "ExamplePlugin",
plugin: "cordova-plugin-example",
pluginRef: "cordova.plugins.Example",
repo: "https://github.com/example/cordova-plugin-example",
platforms: ["Android", "iOS"]
})
export class ExamplePlugin extends IonicNativePlugin {
@Cordova()
getData(): Promise<any> {
return; // Promise return type is handled by decorator
}
@Cordova({ observable: true })
watchData(): Observable<any> {
return; // Observable return type is handled by decorator
}
}Ionic Native Core is built around several key components:
IonicNativePlugin provides common functionality for all plugin wrappersFoundation class that all Ionic Native plugin wrappers extend, providing standardized plugin metadata and availability checking.
class IonicNativePlugin {
static pluginName: string;
static pluginRef: string;
static plugin: string;
static repo: string;
static platforms: string[];
static install: string;
static installed(): boolean;
static getPlugin(): any;
static getPluginName(): string;
static getPluginRef(): string;
static getPluginInstallName(): string;
static getSupportedPlatforms(): string[];
}Comprehensive decorator system for transforming plugin methods into Promise/Observable patterns with automatic error handling and platform checking.
function Plugin(config: PluginConfig): ClassDecorator;
function Cordova(config?: CordovaOptions): MethodDecorator;
function CordovaProperty(): PropertyDecorator;
function CordovaInstance(config?: CordovaOptions): MethodDecorator;
function InstanceProperty(): PropertyDecorator;
function CordovaFunctionOverride(): MethodDecorator;Runtime checking utilities for plugin and Cordova availability with comprehensive error reporting.
function checkAvailability(
plugin: any | string,
methodName?: string,
pluginName?: string
): boolean | { error: string };
function instanceAvailability(
pluginObj: any,
methodName?: string
): boolean;Core utilities for creating promises and wrapping plugin methods with Promise/Observable patterns.
function getPromise<T>(
callback: (resolve: Function, reject?: Function) => any
): Promise<T>;
function wrap(
pluginObj: any,
methodName: string,
opts?: CordovaOptions
): (...args: any[]) => any;
function wrapInstance(
pluginObj: any,
methodName: string,
opts?: any
): Function;Promise and Observable Utilities
interface PluginConfig {
pluginName: string;
plugin: string;
pluginRef?: string;
repo?: string;
install?: string;
installVariables?: string[];
platforms?: string[];
[key: string]: any;
}
interface CordovaOptions {
destruct?: boolean;
methodName?: string;
sync?: boolean;
callbackOrder?: "reverse";
callbackStyle?: "node" | "object";
successIndex?: number;
errorIndex?: number;
successName?: string;
errorName?: string;
observable?: boolean;
clearFunction?: string;
clearWithArgs?: boolean;
eventObservable?: boolean;
event?: string;
element?: any;
otherPromise?: boolean;
platforms?: string[];
}const ERR_CORDOVA_NOT_AVAILABLE: { error: "cordova_not_available" };
const ERR_PLUGIN_NOT_INSTALLED: { error: "plugin_not_installed" };type WrapFn = (...args: any[]) => any;