Warning
This repository is archived and no longer maintained.
- Archived: 2025-08-10 by @KemingHe
- Archive reason: moved on to more focused agentic AI development
- Inquries and corrections: email keminghe.career@gmail.com
Template for creating TypeScript utility packages for publishing to NPM registry. Social preview generated with Socialify.
- 📝 Full TypeScript support with comprehensive type definitions
- ⚡️ Zero runtime dependencies with 100% test coverage
- 🔄 Automated releases with Git hooks and strict linting
npm install @keminghe/npm-templateimport { env } from '@keminghe/npm-template';
// Basic usage
// Throws runtime error if API_KEY is missing or empty
const apiKey: string = env('API_KEY');
// With default value and pattern validation
const port: string = env('PORT', {
defaultValue: '3000',
pattern: /^[0-9]+$/
});import { isNonEmptyString } from '@keminghe/npm-template';
const value = 'hello';
if (isNonEmptyString(value)) {
// TypeScript knows value is string here
console.log(value.toUpperCase());
}// Add your utility functions here
// Follow similar pattern for type safety and validation
import { YourUtility } from './your-module';
// Document clear usage examples
const result = YourUtility.process('input');Retrieves and validates an environment variable value.
Parameters:
name- Environment variable nameoptions- Optional configuration objectdefaultValue?: string- Fallback if env var is not setpattern?: RegExp- Validation pattern to test against
Returns:
string- The validated environment variable value
Throws:
Errorif the variable is missing/empty with no defaultErrorif the value doesn't match the specified pattern
// Examples
const apiKey = env('API_KEY'); // Throws if not set
const port = env('PORT', {
defaultValue: '3000',
pattern: /^\d+$/
});Type guard that checks if a value is a non-empty string.
Parameters:
value- Any value to test
Returns:
boolean-trueif value is a non-empty string
const input = someValue;
if (isNonEmptyString(input)) {
// TypeScript knows input is string here
console.log(input.length);
}Document your new functions following this format:
/**
* Brief description of what the function does
* @param paramName - Parameter description
* @returns What the function returns
* @throws Error conditions if applicable
*/
function yourFunction(paramName: ParamType): ReturnType {
// Implementation
}pnpm install # Install dependencies
pnpm test # Run tests
pnpm build # Build package
pnpm verify # Full verificationSee Tag and Publish Guide for detailed instructions on:
- Setting up GPG signing
- Creating signed Git tags
- Automatic NPM publishing via GitHub Actions
- Fork the repository to your GitHub account
- Create a feature branch (
git checkout -b feature/my-update) - Make changes and commit (
git commit) with Commitizen - Push your changes (
git push origin feature/my-update) - Create a Pull Request for code review
Copyright 2025 Keming He