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
- π― 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
To install lobe-lib-template
, run the following command:
$ bun add lobe-lib-template
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'] }
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();
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();
The main class that provides the core functionality.
new LobeLib(options?: LibOptions)
Parameters:
options
(optional): Configuration optionsconfig
: Custom library configurationtimeout
: Timeout for async operations (default: 5000ms)
Returns a copy of the current configuration.
Updates the library configuration with new values.
Returns library information including formatted version.
Processes data asynchronously with optional timeout.
Validates input data and returns validation results.
interface LibConfig {
name: string;
version: string;
debug?: boolean;
}
interface LibOptions {
config?: LibConfig;
timeout?: number;
}
Formats a version string by adding 'v' prefix.
Validates that a configuration object has required fields.
Creates a default configuration object.
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
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
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
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.
- π€― 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.
- π 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
- π€ Lobe TTS - A high-quality & reliable TTS/STT library for Server and Browser
- π Lobe i18n - Automation ai tool for the i18n (internationalization) translation process.