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 🙏

© 2026 – Pkg Stats / Ryan Hefner

mcs-shared

v1.0.0

Published

Shared React components, hooks, and utilities for building real-time chat applications

Readme

MCS-Shared

Shared React components, hooks, and utilities for building real-time chat applications with Socket.io.

Installation

npm install mcs-shared

Peer Dependencies

This package requires the following peer dependencies:

npm install react react-dom @tanstack/react-virtual react-i18next socket.io-client

Features

Components

  • ChatMessage - Message bubble with text, images, and file attachments
  • ProgressiveImage - Lazy-loaded images with blur-up effect
  • EmojiPicker - Emoji selection UI
  • TypingIndicator - Animated "user is typing..." indicator
  • UnreadIndicator - Badge showing unread message count
  • ScrollToBottomButton - Auto-scroll button for chat
  • FullImageModal - Full-screen image viewer
  • ErrorBoundary - React error boundary
  • Button - Reusable button component
  • SafeText - XSS-safe text rendering
  • HighlightedText - Text with search term highlighting
  • ImageSkeleton - Loading placeholder for images
  • MessageSearchBar - Search messages UI

Hooks

  • useSocket - Socket.io connection management with auto-reconnect
  • usePresence - Track online/offline user status
  • useRateLimit - Client-side rate limiting
  • useTypingIndicator - Typing indicator with auto-stop
  • useMessageGrouping - Group consecutive messages by sender

Utilities

  • compressImage - Client-side image compression
  • sanitizeUsername - XSS prevention for usernames
  • groupMessages - Group messages for display
  • highlightText - Highlight search terms in text
  • emojiDetection - Detect emoji-only messages

TypeScript Types

Comprehensive TypeScript types for:

  • User, Organization, ChatRoom, Message
  • Authentication responses
  • API responses
  • Message status

Usage Examples

Socket Connection

import { useSocket } from 'mcs-shared';

function ChatApp() {
  const { socket, connected, emit, on, off } = useSocket({
    url: 'https://api.example.com',
    autoConnect: true
  });

  useEffect(() => {
    if (!connected) return;

    const handleMessage = (message) => {
      console.log('New message:', message);
    };

    on('message:new', handleMessage);
    return () => off('message:new', handleMessage);
  }, [connected, on, off]);

  const sendMessage = (content) => {
    emit('message:send', { content });
  };

  return <div>Connected: {connected ? 'Yes' : 'No'}</div>;
}

Chat Message

import { ChatMessage } from 'mcs-shared';

function MessageList({ messages, currentUser }) {
  return (
    <div>
      {messages.map(message => (
        <ChatMessage
          key={message._id}
          message={message}
          isCurrentUser={message.sender._id === currentUser._id}
        />
      ))}
    </div>
  );
}

Progressive Image

import { ProgressiveImage } from 'mcs-shared';

function ImageGallery({ images }) {
  return (
    <div>
      {images.map(image => (
        <ProgressiveImage
          key={image.id}
          src={image.url}
          alt={image.description}
          thumbnailSrc={image.thumbnail}
        />
      ))}
    </div>
  );
}

Rate Limiting

import { useRateLimit } from 'mcs-shared';

function ChatInput() {
  const { checkLimit, getRemainingTime } = useRateLimit({
    maxAttempts: 3,
    windowMs: 5000
  });

  const handleSend = () => {
    if (!checkLimit('sendMessage')) {
      const remaining = getRemainingTime('sendMessage');
      alert(`Rate limit exceeded. Try again in ${remaining}ms`);
      return;
    }

    // Send message...
  };

  return <button onClick={handleSend}>Send</button>;
}

Presence Tracking

import { usePresence } from 'mcs-shared';

function UserList({ users }) {
  const { isUserOnline } = usePresence(socket);

  return (
    <ul>
      {users.map(user => (
        <li key={user.id}>
          {user.name} - {isUserOnline(user.id) ? 'Online' : 'Offline'}
        </li>
      ))}
    </ul>
  );
}

Security Features

  • XSS Prevention: All text inputs are sanitized
  • Safe HTML Rendering: Links are detected and rendered safely
  • Input Validation: Built-in validation utilities
  • Rate Limiting: Client-side rate limiting to prevent abuse

Performance Optimizations

  • Lazy Loading: Images load on-demand with Intersection Observer
  • Progressive Enhancement: Blur-up image loading effect
  • Message Grouping: Reduces DOM nodes by grouping consecutive messages
  • Memoization: Components use React.memo for optimal re-renders

Contributing

Part of the MCS (Multi-Client System) project. Contributions welcome!

License

MIT License - see LICENSE file for details

Credits

Built for the MCS real-time chat application platform.