https://github.com/keminghe/npm-template
Template for creating TypeScript utility packages for publishing to NPM registry.
https://github.com/keminghe/npm-template
node npm pnpm template typescript
Last synced: about 2 months ago
JSON representation
Template for creating TypeScript utility packages for publishing to NPM registry.
- Host: GitHub
- URL: https://github.com/keminghe/npm-template
- Owner: KemingHe
- License: mit
- Created: 2025-02-27T03:59:09.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-28T16:02:27.000Z (over 1 year ago)
- Last Synced: 2025-02-28T20:26:52.387Z (over 1 year ago)
- Topics: node, npm, pnpm, template, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@keminghe/npm-template
- Size: 83 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ⚠️ [Archived] ⚠️ @keminghe/npm-template
> [!WARNING]
> **This repository is archived and no longer maintained.**
>
> - **Archived**: 2025-08-10 by [@KemingHe](https://github.com/KemingHe)
> - **Archive reason**: moved on to more focused agentic AI development
> - **Inquries and corrections**: email [keminghe.career@gmail.com](mailto:keminghe.career@gmail.com)



[](https://codecov.io/gh/KemingHe/npm-template)
Template for creating TypeScript utility packages for publishing to NPM registry. Social preview generated with [Socialify](https://socialify.git.ci).
## ⭐ Features
- 📝 Full TypeScript support with comprehensive type definitions
- ⚡️ Zero runtime dependencies with 100% test coverage
- 🔄 Automated releases with Git hooks and strict linting
## 📥 Installation
```bash
npm install @keminghe/npm-template
```
## 🚀 Usage
### Environment Variable Utility
```typescript
import { 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]+$/
});
```
### String Validation
```typescript
import { isNonEmptyString } from '@keminghe/npm-template';
const value = 'hello';
if (isNonEmptyString(value)) {
// TypeScript knows value is string here
console.log(value.toUpperCase());
}
```
### _Your Custom Utility_
```typescript
// 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');
```
## 📚 API
### `env(name: string, options?: EnvOptions): string`
Retrieves and validates an environment variable value.
**Parameters:**
- `name` - Environment variable name
- `options` - Optional configuration object
- `defaultValue?: string` - Fallback if env var is not set
- `pattern?: RegExp` - Validation pattern to test against
**Returns:**
- `string` - The validated environment variable value
**Throws:**
- `Error` if the variable is missing/empty with no default
- `Error` if the value doesn't match the specified pattern
```typescript
// Examples
const apiKey = env('API_KEY'); // Throws if not set
const port = env('PORT', {
defaultValue: '3000',
pattern: /^\d+$/
});
```
### `isNonEmptyString(value: unknown): value is string`
Type guard that checks if a value is a non-empty string.
**Parameters:**
- `value` - Any value to test
**Returns:**
- `boolean` - `true` if value is a non-empty string
```typescript
const input = someValue;
if (isNonEmptyString(input)) {
// TypeScript knows input is string here
console.log(input.length);
}
```
### _Your Custom API_
_Document your new functions following this format:_
```typescript
/**
* 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
}
```
## ⚙️ Development
```bash
pnpm install # Install dependencies
pnpm test # Run tests
pnpm build # Build package
pnpm verify # Full verification
```
## 🏷️ Release Process
See [Tag and Publish Guide](https://github.com/KemingHe/npm-template/blob/main/docs/tag-and-publish.md) for detailed instructions on:
- Setting up GPG signing
- Creating signed Git tags
- Automatic NPM publishing via GitHub Actions
## 🤝 Contributing
1. Fork the repository to your GitHub account
2. Create a feature branch (`git checkout -b feature/my-update`)
3. Make changes and commit (`git commit`) with Commitizen
4. Push your changes (`git push origin feature/my-update`)
5. Create a Pull Request for code review
## 📄 License
[MIT License](https://github.com/KemingHe/npm-template/blob/main/LICENSE)
Copyright 2025 [Keming He](http://linkedin.com/in/keminghe)