Skip to content
/ lobe-lib-template Public 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.

License

Notifications You must be signed in to change notification settings

lobehub/lobe-lib-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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.


Changelog Β· Report Bug Β· Request Feature

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 options
    • config: Custom library configuration
    • timeout: 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 watch
  • bun build - Build the library for production
  • bun test - Run tests
  • bun test:coverage - Run tests with coverage
  • bun lint - Lint and fix code
  • bun type-check - Type check TypeScript code
  • bun 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

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.

More Resources


πŸ“ License

Copyright Β© 2025 LobeHub.
This project is MIT licensed.

About

πŸ—ΊοΈ 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.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

  •  

Packages

No packages published

Contributors 2

  •  
  •