Skip to content

vanakat/plugin-api

Repository files navigation

Obsidian Plugin API

Standardized way of exposing and using Obsidian plugin APIs.

APIs are published on the global window.PluginApi object, so they can be used by other plugins as well as anywhere else in Obsidian, e.g. in Templater user scripts or the developer console.

Installation

npm install --save-dev @vanakat/plugin-api

Usage

This module exposes 2 functions:

  • registerAPI(name, api, plugin) – registers plugin API in global variable (window.PluginApi); the API is automatically unregistered when the plugin unloads
  • pluginApi(name) – returns plugin API based on its name; if no API is registered under that name, shows a notice asking the user to install the plugin

Exposing an API from your plugin:

import { Plugin } from 'obsidian';
import { registerAPI } from '@vanakat/plugin-api';

export class MyPlugin extends Plugin {
    async onload() {
        registerAPI('MyPlugin', new MyPluginApi(this), this);
    }
}

Consuming an API from another plugin:

import { pluginApi } from '@vanakat/plugin-api';

const api = pluginApi('MyPlugin');

Examples

Following plugins already use @vanakat/plugin-api:

License

MIT

About

Standartized way to expose and use Obsidian Inter-Plugin APIs

Resources

License

Stars

10 stars

Watchers

1 watching

Forks

Contributors