LobeHub Library Template
A modern, well-structured TypeScript library template for building high-quality npm packages. This template provides a solid foundation with comprehensive tooling, testing setup, and development workflow.
Table of contents
TOC
✨ Features
- 🎯 TypeScript First - Built with TypeScript for better developer experience
- 📦 Modern Build - Uses tsup for fast, modern bundling
- 🧪 Testing Ready - Configured with Vitest for unit testing
- 📝 Linting & Formatting - ESLint, Prettier, and commit hooks setup
- 🔄 CI/CD Ready - GitHub Actions for testing and publishing
- 📚 Documentation - JSDoc comments and comprehensive README
- 🎨 Modern Tooling - Latest development tools and best practices
📦 Installation
To install lobe-lib-template, run the following command:
$ bun add lobe-lib-template
🚀 Quick Start
Basic Usage
import { LobeLib } from 'lobe-lib-template';
// Create a new instance
const lib = new LobeLib();
// Get library information
const info = lib.getInfo();
console.log(info); // { name: 'lobe-lib-template', version: '1.0.0', formattedVersion: 'v1.0.0' }
// Process data asynchronously
const result = await lib.processData('Hello World');
console.log(result); // 'Hello World'
// Validate data
const validation = lib.validateData('');
console.log(validation); // { isValid: false, errors: ['Data cannot be empty'] }
Advanced Configuration
import { LibConfig, LobeLib } from 'lobe-lib-template';
const config: LibConfig = {
name: 'my-custom-lib',
version: '2.0.0',
debug: true,
};
const lib = new LobeLib({
config,
timeout: 3000,
});
// Update configuration
lib.updateConfig({ debug: false });
// Get current configuration
const currentConfig = lib.getConfig();
Utility Functions
import { createDefaultConfig, formatVersion, validateConfig } from 'lobe-lib-template';
// Format version string
const formatted = formatVersion('1.2.3'); // 'v1.2.3'
// Validate configuration
const isValid = validateConfig({ name: 'test', version: '1.0.0' }); // true
// Create default configuration
const defaultConfig = createDefaultConfig();
📖 API Reference
LobeLib Class
The main class that provides the core functionality.
Constructor
new LobeLib(options?: LibOptions)
Parameters:
options(optional): Configuration optionsconfig: Custom library configurationtimeout: Timeout for async operations (default: 5000ms)
Methods
getConfig(): LibConfig
Returns a copy of the current configuration.
updateConfig(newConfig: Partial<LibConfig>): void
Updates the library configuration with new values.
getInfo(): { name: string; version: string; formattedVersion: string }
Returns library information including formatted version.
processData<T>(data: T): Promise<T>
Processes data asynchronously with optional timeout.
validateData<T>(data: T): { isValid: boolean; errors: string[] }
Validates input data and returns validation results.
Types
LibConfig
interface LibConfig {
name: string;
version: string;
debug?: boolean;
}
LibOptions
interface LibOptions {
config?: LibConfig;
timeout?: number;
}
Utility Functions
formatVersion(version: string): string
Formats a version string by adding 'v' prefix.
validateConfig(config: LibConfig): boolean
Validates that a configuration object has required fields.
createDefaultConfig(): LibConfig
Creates a default configuration object.
🛠️ Development
You can use Github Codespaces for online development:
Or clone it for local development:
$ git clone https://github.com/lobehub/lobe-lib-template.git
$ cd lobe-lib-template
$ bun install
$ bun dev
Available Scripts
bun dev- Start development mode with watchbun build- Build the library for productionbun test- Run testsbun test:coverage- Run tests with coveragebun lint- Lint and fix codebun type-check- Type check TypeScript codebun ci- Run all CI checks
Project Structure
lobe-lib-template/
├── src/
│ └── index.ts # Main library entry point
├── dist/ # Built files (generated)
├── tests/ # Test files
├── tsup.config.ts # Build configuration
├── vitest.config.ts # Test configuration
├── tsconfig.json # TypeScript configuration
└── package.json # Package configuration
🤝 Contributing
Contributions of all types are more than welcome, if you are interested in contributing code, feel free to check out our GitHub Issues to get stuck in to show us what you're made of.
🔗 Links
More Products
- 🤯 Lobe Chat - An open-source, extensible (Function Calling), high-performance chatbot framework. It supports one-click free deployment of your private ChatGPT/LLM web application.
- 🅰️ Lobe Theme - The modern theme for stable diffusion webui, exquisite interface design, highly customizable UI, and efficiency boosting features.
- 🧸 Lobe Vidol - Experience the magic of virtual idol creation with Lobe Vidol, enjoy the elegance of our Exquisite UI Design, dance along using MMD Dance Support, and engage in Smooth Conversations.
Design Resources
- 🍭 Lobe UI - An open-source UI component library for building AIGC web apps.
- 🥨 Lobe Icons - Popular AI / LLM Model Brand SVG Logo and Icon Collection.
- 📊 Lobe Charts - React modern charts components built on recharts
Development Resources
- 🎤 Lobe TTS - A high-quality & reliable TTS/STT library for Server and Browser
- 🌏 Lobe i18n - Automation ai tool for the i18n (internationalization) translation process.
