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

kcsdi-plugin-api

v0.1.25

Published

Core library for KCSDI application plugin development, providing cross-platform communication capabilities and runtime management features.

Readme

kcsdi-plugin-api

Core library for KCSDI application plugin development, providing cross-platform communication capabilities and runtime management features.

Key Features

🌐 Dual-protocol support - Unified TCP Socket & Serial port communication
🚀 Full-duplex communication - Supports bidirectional real-time data transfer
🔧 Runtime management - Theme switching/multi-language support out-of-the-box

Installation

# npm
npm install kcsdi-plugin-api
# yarn
yarn add kcsdi-plugin-api
# bun
bun install kcsdi-plugin-api

Quick Start

Basic Communication Example

import { Socket, getElectronAPI } from 'kcsdi-plugin-api';
import { useEffect, useRef } from 'react';

function CommunicationComponent() {
  // Create TCP connection instance
  const tcpSocket = useRef(new Socket({
    protocol: 'tcp',
    host: '127.0.0.1',
    port: 8973,
  }));

  // Create serial port connection instance
  const serialSocket = useRef(new Socket({
    protocol: 'serial',
    path: 'COM4',
    baudRate: 115200,
  }));

  useEffect(() => {
    const handleMessage = (data: Uint8Array) => {
      console.log('Received data:', new TextDecoder().decode(data));
    };

    const handleError = (err: Error) => {
      console.error('Connection error:', err.message);
    };

    // Event subscription
    const socket = tcpSocket.current;
    // const socket = serialSocket.current;
    socket.on('open', () => console.log('Connection established'));
    socket.on('message', handleMessage);
    socket.on('error', handleError);

    // Initialize connection
    socket.open();

    return () => {
      // Cleanup
      socket.close();
      socket.removeAllListeners();
    };
  }, []);

  return <div>Communication Component</div>;
}

Runtime Configuration Management

function RuntimeConfig() {
  useEffect(() => {
    const electronAPI = getElectronAPI();
    
    // Theme change listener
    const clearTheme = electronAPI.onChangeTheme((newTheme) => {
      document.documentElement.setAttribute('data-theme', newTheme);
    });

    // Language change listener
    const clearLanguage = electronAPI.onChangeLanguage((newLanguage) => {
      i18n.changeLanguage(newLanguage);
    });

    return () => {
      clearTheme();
      clearLanguage();
    };
  }, []);

  return null;
}

API Reference

Socket Class

Constructor

new Socket(options: ITCPSocketConnectionOptions | ISerialSocketConnectionOptions)

Core Methods

| Method | Parameters | Returns | Description | |--------------|----------------------|-------------|----------------------| | open() | - | Promise | Establish connection | | close() | - | Promise | Close connection | | send() | string/Uint8Array | Promise | Send data |

Event System

| Event | Listener Param | Trigger Condition | |---------------|--------------------|------------------------| | open | - | Connection established | | message | Uint8Array | Data received | | error | Error | Error occurred | | close | - | Connection closed |

Electron Runtime API

interface IElectronAPI {
  // Get serial port list
  getSerialPorts: () => Promise<Array<{ path: string }>>;
  
  // Theme management
  onChangeTheme: (callback: (theme: string) => void) => () => void;
  
  // Multi-language support
  onChangeLanguage: (callback: (lang: string) => void) => () => void;
}

Best Practices

  1. Connection Management
    Recommended to establish connection when component mounts and clean up on unmount:

    useEffect(() => {
      const socket = new Socket({...});
      socket.open();
         
      return () => socket.close();
    }, []);
  2. Error Handling
    Always listen to error events to prevent uncaught exceptions:

    socket.on('error', (err) => {
      console.error(`[${socketId}] Error:`, err);
    });
  3. Binary Data Handling
    Use built-in conversion utilities:

    // Send binary data
    socket.send(new Uint8Array([0x01, 0x02]));
       
    // Receive processing
    socket.on('message', (raw) => {
      const text = socket.uint8ArrayToString(raw);
    });

License

MIT