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

@qhr123/sa2kit

v0.8.1

Published

A modern, type-safe React utility library with cross-platform support and platform adapters

Downloads

12

Readme

SA2Kit

A modern, type-safe React utility library with cross-platform support for building scalable applications.

Features

  • 🚀 Modern TypeScript - Full type safety and IntelliSense support
  • 📦 Tree-shakeable - Optimized bundle size with ESM support
  • 🔄 Cross-platform - Works in browser and Node.js environments
  • Zero dependencies - Minimal footprint (React as peer dependency)
  • 🧩 Modular - Import only what you need
  • 🎯 React Hooks - Custom hooks for common patterns
  • 📝 Logger System - Unified logging with multiple adapters
  • 💾 Storage Adapters - Universal storage abstraction
  • 📁 File Upload - Complete file management with progress tracking
  • 📊 Data Export - Flexible export to CSV, Excel, JSON formats
  • 🌍 i18n - Complete internationalization solution
  • 📈 Analytics - Comprehensive event tracking and analytics

Installation

npm install @qhr123/sa2kit
# or
yarn add @qhr123/sa2kit
# or
pnpm add @qhr123/sa2kit

Quick Start

Logger

import { logger, createLogger, LogLevel } from '@qhr123/sa2kit/logger';

// Use default logger
logger.info('Application started');
logger.debug('Debug information', { user: 'John' });
logger.error('Something went wrong', new Error('Error details'));

// Create custom logger with context
const apiLogger = createLogger('API', {
  minLevel: LogLevel.INFO,
  enableTimestamp: true,
});

apiLogger.info('API request completed');

Utility Functions

import { stringUtils, arrayUtils, fileUtils } from '@qhr123/sa2kit/utils';

// String utilities
const capitalized = stringUtils.capitalize('hello world');
const truncated = stringUtils.truncate('Long text...', 10);

// Array utilities
const unique = arrayUtils.unique([1, 2, 2, 3, 3, 4]);
const grouped = arrayUtils.groupBy(items, 'category');

// File utilities
const size = fileUtils.formatFileSize(1024000);
const isValid = fileUtils.isValidFilename('document.pdf');

React Hooks

import { useLocalStorage, useAsyncStorage } from '@qhr123/sa2kit/hooks';

function MyComponent() {
  // Persistent state with localStorage
  const [theme, setTheme] = useLocalStorage('theme', 'light');

  // Async storage operations
  const { data, loading, error } = useAsyncStorage('user-data');

  return <div>Theme: {theme}</div>;
}

File Upload

import { universalFileClient } from '@qhr123/sa2kit/universalFile';

// Upload a file with progress tracking
const uploadFile = async (file: File) => {
  const fileMetadata = await universalFileClient.uploadFile(
    {
      file,
      moduleId: 'user-avatars',
      businessId: 'user-123',
      permission: 'public',
    },
    (progress) => {
      console.log(`Upload progress: ${progress.progress}%`);
      console.log(`Speed: ${progress.speed} bytes/sec`);
    }
  );

  console.log('File uploaded:', fileMetadata.id);
  return fileMetadata;
};

// Query files
const files = await universalFileClient.queryFiles({
  moduleId: 'user-avatars',
  pageSize: 20,
});

// Get file URL
const fileUrl = await universalFileClient.getFileUrl(fileId);

Data Export

import { universalExportClient } from '@qhr123/sa2kit/universalExport';

// Export data to CSV
const exportData = async () => {
  const result = await universalExportClient.exportData({
    configId: 'my-export-config',
    dataSource: async () => [
      { id: 1, name: 'John', email: '[email protected]' },
      { id: 2, name: 'Jane', email: '[email protected]' },
    ],
    format: 'csv',
    callbacks: {
      onProgress: (progress) => {
        console.log(`Export progress: ${progress.progress}%`);
      },
      onSuccess: (result) => {
        console.log('Export completed:', result.fileName);
        // Download the file
        const url = URL.createObjectURL(result.fileBlob!);
        const a = document.createElement('a');
        a.href = url;
        a.download = result.fileName;
        a.click();
      },
    },
  });
};

Internationalization (i18n)

import { createI18n, useTranslation } from '@qhr123/sa2kit/i18n';
import { zhCN, enUS } from '@qhr123/sa2kit/i18n';

// Create i18n instance
const i18n = createI18n({
  locale: 'zh-CN',
  fallbackLocale: 'en-US',
  resources: {
    'zh-CN': zhCN,
    'en-US': enUS,
  },
});

// In React component
function MyComponent() {
  const { t, locale, setLocale } = useTranslation();

  return (
    <div>
      <p>{t('common.welcome')}</p>
      <button onClick={() => setLocale('en-US')}>
        Switch to English
      </button>
    </div>
  );
}

UI Components (Tailwind CSS)

import { LanguageSwitcher } from '@qhr123/sa2kit/i18n';

// Button group style (default)
<LanguageSwitcher variant="buttons" />

// Dropdown style
<LanguageSwitcher variant="dropdown" />

// Icon button with dropdown
<LanguageSwitcher variant="icon" />

// With custom className and callback
<LanguageSwitcher
  variant="buttons"
  className="my-custom-class"
  onLanguageChange={(locale) => {
    console.log('Language changed to:', locale);
  }}
/>

Requirements:

  • ✅ React >= 18.0.0
  • ✅ Tailwind CSS configured in your project (Setup Guide)
  • ✅ Next.js App Router compatible ('use client' included)

**Note:** UI components use Tailwind CSS. See the [Tailwind Setup Guide](./docs/tailwind-setup.md) for configuration instructions.

### Analytics

```typescript
import { Analytics, createAnalytics } from '@qhr123/sa2kit/analytics';

// Create analytics instance (需要提供适配器)
const analytics = createAnalytics('my-app', {
  appId: 'my-app',
  appVersion: '1.0.0',
  endpoint: '/api/analytics/events',
  platform: 'web',
  adapter: yourPlatformAdapter, // 需要自行实现
});

// Track events
analytics.trackEvent('button_click', {
  button_id: 'submit',
  page: 'home',
});

// Use decorators (TypeScript)
class MyService {
  @Track('user_login')
  async login(username: string) {
    // Login logic
  }

  @CatchError()
  async fetchData() {
    // Fetch logic
  }
}

// Use React Hooks
function MyComponent() {
  const trackEvent = useAnalyticsEvent(analytics);

  usePageView(analytics); // Auto track page views

  const handleClick = () => {
    trackEvent('button_click', { action: 'submit' });
  };

  return <button onClick={handleClick}>Submit</button>;
}

Documentation

Examples

Check out the examples directory for complete working examples:

  • React App Example
  • Next.js Integration
  • TypeScript Configuration

API Reference

Full API documentation is available at https://react-utils-kit.dev

Contributing

We welcome contributions! Please see CONTRIBUTING.md for details.

License

MIT © Your Name

Support