or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

availability.mdbase-plugin.mddecorators.mdindex.mdpromise-observable.md
tile.json

tessl/npm-ionic-native--core

TypeScript foundation for Ionic Native plugin wrappers providing decorators, base classes, and utilities for Cordova/Capacitor integration

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@ionic-native/core@5.36.x

To install, run

npx @tessl/cli install tessl/npm-ionic-native--core@5.36.0

index.mddocs/

Ionic Native Core

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.

Package Information

  • Package Name: @ionic-native/core
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @ionic-native/core

Core Imports

import { 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";

Basic Usage

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
  }
}

Architecture

Ionic Native Core is built around several key components:

  • Base Plugin Class: IonicNativePlugin provides common functionality for all plugin wrappers
  • Decorator System: Transforms method calls to handle Promise/Observable patterns and error checking
  • Availability Checking: Runtime verification of plugin and Cordova availability
  • Promise/Observable Wrapping: Automatic conversion of callback-based APIs to modern async patterns
  • Error Handling: Comprehensive error reporting for missing plugins and Cordova
  • Framework Integration: Native support for Angular 1 dependency injection

Capabilities

Base Plugin Class

Foundation 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[];
}

Base Plugin Class

Decorator System

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;

Decorators

Availability and Error Checking

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;

Availability Checking

Promise and Observable Utilities

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

Core Types

Configuration Interfaces

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[];
}

Error Constants

const ERR_CORDOVA_NOT_AVAILABLE: { error: "cordova_not_available" };
const ERR_PLUGIN_NOT_INSTALLED: { error: "plugin_not_installed" };

Utility Types

type WrapFn = (...args: any[]) => any;