npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@navigator.menu/pdk

v3.0.1

Published

Plugin Development Kit for Navigator - utilities, mocks, and types for building plugins

Readme

@navigator.menu/pdk

Plugin Development Kit for Navigator

Utilities, types, mocks, and base classes for building Navigator plugins.

📦 Installation

npm install @navigator.menu/pdk
# or
pnpm add @navigator.menu/pdk
# or
yarn add @navigator.menu/pdk

🚀 Quick Start

Creating a Plugin

import { BasePlugin, NipValidator } from '@navigator.menu/pdk';

export class MyPlugin extends BasePlugin {
  constructor() {
    super('my-plugin');
  }

  async init() {
    // Setup plugin
    console.log('MyPlugin initialized!');
    
    // Emit NIP event
    const event = NipValidator.createEvent(
      'custom:my_event',
      this.name,
      { message: 'Hello from my plugin!' }
    );
    
    // Use event with EventBus (injected by Navigator Core)
  }

  async start() {
    console.log('MyPlugin started!');
  }

  async destroy() {
    console.log('MyPlugin destroyed!');
  }
}

Using Utilities

import { debounce, clamp, getProperty, setProperty } from '@navigator.menu/pdk/utils';

// Debounce function
const handleResize = debounce(() => {
  console.log('Resized!');
}, 300);

// Clamp values
const speed = clamp(velocity, 0, 100);

// Deep object access
const value = getProperty(config, 'ui.theme.colors.primary', '#000');
setProperty(config, 'ui.theme.colors.primary', '#00d4ff');

Testing Plugins

import { CoreMock, EventBusMock, AppStateMock } from '@navigator.menu/pdk/testing';
import { MyPlugin } from './MyPlugin';

describe('MyPlugin', () => {
  it('should initialize correctly', async () => {
    const core = new CoreMock();
    const plugin = new MyPlugin();
    
    core.registerPlugin(plugin);
    await core.init();
    
    expect(core.isInitialized()).toBe(true);
    expect(core.getPlugin('my-plugin')).toBe(plugin);
  });
  
  it('should emit events', async () => {
    const eventBus = new EventBusMock();
    
    eventBus.on('custom:my_event', (payload) => {
      console.log('Event received:', payload);
    });
    
    eventBus.emit('custom:my_event', { message: 'Test' });
    
    expect(eventBus.wasEmitted('custom:my_event')).toBe(true);
  });
});

📖 API Reference

BasePlugin

Abstract base class for plugins with standard lifecycle methods.

Methods:

  • init() - Initialize plugin (required, must implement)
  • start() - Start plugin (optional)
  • stop() - Stop plugin (optional)
  • destroy() - Cleanup resources (optional)
  • setPriority(priority: number) - Set plugin load priority
  • setConfig(config: object) - Set plugin configuration
  • getConfig<T>(key: string, defaultValue?: T) - Get config value

NipValidator

Validate and create NIP v1.0 compliant events.

Static Methods:

  • validate(event: any) - Validate event structure
  • createEvent<T>(type, source, payload, metadata?) - Create valid NIP event

Utilities (@navigator.menu/pdk/utils)

Object Utilities:

  • deepMerge<T>(target, ...sources) - Deep merge objects
  • getProperty<T>(obj, path, defaultValue?) - Get nested property
  • setProperty(obj, path, value) - Set nested property

Function Utilities:

  • debounce<T>(func, wait) - Debounce function calls
  • throttle<T>(func, limit) - Throttle function calls
  • retry<T>(fn, options) - Retry async function with backoff

Math Utilities:

  • clamp(value, min, max) - Clamp number between min/max
  • lerp(start, end, t) - Linear interpolation
  • mapRange(value, inMin, inMax, outMin, outMax) - Map value between ranges
  • distance(x1, y1, x2, y2) - Calculate distance between points

Misc Utilities:

  • createId(prefix?) - Generate unique ID
  • wait(ms) - Promise-based delay

Testing Mocks (@navigator.menu/pdk/testing)

CoreMock:

  • Full INavigatorCore implementation for testing
  • Methods: init(), start(), stop(), destroy(), registerPlugin(), getPlugin()
  • Test helpers: isInitialized(), isStarted()

EventBusMock:

  • Full IEventBus implementation for testing
  • Methods: on(), off(), emit(), once(), clear(), getHistory()
  • Test helpers: getListeners(), wasEmitted()

AppStateMock:

  • Full IAppState implementation for testing
  • Methods: get(), set(), watch(), getState(), reset()

🧪 Testing Best Practices

  1. Use Mocks: Always use CoreMock, EventBusMock, and AppStateMock for unit tests
  2. Test Lifecycle: Verify all lifecycle methods (init, start, stop, destroy)
  3. Test Events: Check that plugins emit correct NIP events
  4. Validate Events: Use NipValidator.validate() to ensure event compliance
  5. Isolate Tests: Reset mocks between tests using .clear() or .reset()

📚 Learn More

📝 License

MIT