@tomfanhm/ts-lib-starter
v0.0.1
Published
A production-ready TypeScript library starter
Readme
@tomfanhm/ts-lib-starter
A production-ready TypeScript library starter with dual ESM/CJS output, comprehensive testing, and automated publishing.
Installation
npm install @tomfanhm/ts-lib-starter
# or
pnpm add @tomfanhm/ts-lib-starter
# or
yarn add @tomfanhm/ts-lib-starterUsage
ESM
import { add, capitalize, slugify } from "@tomfanhm/ts-lib-starter";
add(2, 3); // 5
capitalize("hello"); // "Hello"
slugify("Hello World!"); // "hello-world"CJS
const { add, capitalize, slugify } = require("@tomfanhm/ts-lib-starter");
add(2, 3); // 5
capitalize("hello"); // "Hello"
slugify("Hello World!"); // "hello-world"API
Math
| Function | Description |
| ---------------- | --------------------------------------------------------------- |
| add(a, b) | Returns the sum of two numbers |
| subtract(a, b) | Returns the difference of two numbers |
| multiply(a, b) | Returns the product of two numbers |
| divide(a, b) | Returns the quotient (throws DivisionByZeroError if b is 0) |
String
| Function | Description |
| ----------------------------------- | --------------------------------------- |
| capitalize(str) | Uppercases the first letter |
| slugify(str) | Converts to a URL-friendly slug |
| truncate(str, maxLength, suffix?) | Truncates with suffix (default "...") |
Errors
| Class | Description |
| --------------------- | -------------------------------------- |
| LibraryError | Base error with code field |
| DivisionByZeroError | Thrown by divide() when divisor is 0 |
Full API documentation: run pnpm run docs to generate Typedoc output in docs/.
Development
# Install dependencies
pnpm install
# Run in watch mode
pnpm run dev
# Run tests
pnpm run test
# Run tests in watch mode
pnpm run test:watch
# Run tests with coverage
pnpm run test:coverage
# Lint and format
pnpm run lint
pnpm run lint:fix
# Type-check
pnpm run type-check
# Build
pnpm run build
# Full quality check
pnpm run qualityScripts
| Script | Description |
| --------------- | -------------------------------------------------------------------- |
| build | Bundle with tsup (ESM + CJS) |
| dev | Build in watch mode |
| test | Run tests with Vitest |
| test:watch | Run tests in watch mode |
| test:coverage | Run tests with V8 coverage |
| lint | ESLint + Prettier check |
| lint:fix | Auto-fix lint and format issues |
| format | Format with Prettier |
| type-check | TypeScript type checking |
| docs | Generate Typedoc documentation |
| quality | Full quality pipeline (lint, type-check, test, build, publint, attw) |
Changesets
This project uses Changesets for versioning.
To add a changeset:
pnpm run changesetFollow the prompts to describe your change. When PRs with changesets are merged to main, the release workflow automatically creates a version PR. Merging that PR publishes to NPM.
Publishing
Publishing is automated via GitHub Actions:
- Create a changeset:
pnpm run changeset - Commit and push to a feature branch
- Merge the PR to
main - The release workflow creates a "Version Packages" PR
- Merge the version PR to publish to NPM
For manual publishing:
pnpm run releaseLicense
MIT
