A demo npm package showcasing TypeScript best practices for development, testing, and publishing.
This package serves as a comprehensive demonstration of modern npm package development using TypeScript. While functionally minimal (implementing simple greeting functionality), it showcases industry best practices for:
- β¨ TypeScript Development: Strict typing, modern ES features, and proper module exports
- π§ͺ Comprehensive Testing: Unit tests, integration tests, and 95%+ coverage
- π Code Quality: ESLint, Prettier, and automated formatting
- π CI/CD Pipeline: GitHub Actions for testing, building, and publishing
- π Documentation: JSDoc comments, usage examples, and API documentation
- π§ Automation: Dependabot for dependency updates and security patches
This package is intentionally minimal in functionality. Its value lies in demonstrating proper package structure, development practices, and automation workflows rather than solving complex problems. It's a "Hello, World" for the npm ecosystem - simple in purpose, comprehensive in implementation.
# Using npm
npm install @rumenx/sandbox-npm-package
# Using yarn
yarn add @rumenx/sandbox-npm-package
# Using pnpm
pnpm add @rumenx/sandbox-npm-package
import {
greet,
greetWithOptions,
isValidName,
} from '@rumenx/sandbox-npm-package';
// Basic greeting
console.log(greet()); // "Hello, World!"
console.log(greet('Alice')); // "Hello, Alice!"
// Advanced greeting with options
console.log(
greetWithOptions('Bob', {
prefix: 'Good morning',
suffix: '!',
capitalize: true,
})
); // "Good morning, Bob!"
// Name validation
console.log(isValidName('Alice')); // true
console.log(isValidName('')); // false
Generates a simple greeting message.
Parameters:
name
(optional): The name to include in the greeting. Defaults to "World" if not provided.
Returns: A formatted greeting string.
Examples:
greet(); // "Hello, World!"
greet('Alice'); // "Hello, Alice!"
greet(' bob '); // "Hello, Bob!" (trims and capitalizes)
Generates a customizable greeting message with advanced options.
Parameters:
name
(optional): The name to include in the greetingoptions
(optional): Configuration object for customizing the greeting
Options:
interface GreetingOptions {
prefix?: string; // Default: "Hello"
suffix?: string; // Default: "!"
capitalize?: boolean; // Default: true
}
Examples:
greetWithOptions('Alice', { prefix: 'Hi' }); // "Hi, Alice!"
greetWithOptions('bob', { capitalize: false }); // "Hello, bob!"
Validates if a name is considered valid for greeting.
Parameters:
name
(optional): The name to validate
Returns: true
if the name is valid (non-empty after trimming), false
otherwise.
Examples:
isValidName('Alice'); // true
isValidName(' '); // false
isValidName(undefined); // false
interface GreetingOptions {
prefix?: string;
suffix?: string;
capitalize?: boolean;
}
- Node.js 18+
- npm 8+
# Clone the repository
git clone https://github.com/RumenDamyanov/sandbox-npm-package.git
cd sandbox-npm-package
# Install dependencies
npm install
# Build the project
npm run build
# Development
npm run dev # Watch mode development
npm run build # Build the package
npm run clean # Clean build artifacts
# Testing
npm test # Run tests
npm run test:watch # Watch mode testing
npm run test:coverage # Generate coverage report
# Code Quality
npm run lint # Check linting rules
npm run lint:fix # Fix auto-fixable linting issues
npm run format # Format code with Prettier
npm run format:check # Check if code is formatted
npm run typecheck # Run TypeScript type checking
# Package Management
npm run prepare # Pre-commit build
npm run prepublishOnly # Pre-publish checks
sandbox-npm-package/
βββ .github/
β βββ workflows/ # GitHub Actions
β βββ dependabot.yml # Dependency updates
βββ .ai/
β βββ instructions.md # AI/Human instructions
βββ src/
β βββ index.ts # Main entry point
β βββ greet.ts # Core functionality
β βββ types.ts # Type definitions
βββ tests/
β βββ greet.test.ts # Unit tests
β βββ index.test.ts # Integration tests
βββ dist/ # Built files (generated)
βββ Configuration files...
βββ Documentation files...
This package maintains high testing standards:
- 95%+ Code Coverage: Comprehensive test suite covering all functionality
- Multiple Test Types: Unit tests, integration tests, edge cases
- Automated Testing: CI pipeline runs tests on multiple Node.js versions and operating systems
Run tests locally:
npm test # Run all tests
npm run test:coverage # Generate coverage report
npm run test:watch # Watch mode for development
- ESLint: TypeScript-aware rules with strict configuration
- Prettier: Consistent code formatting
- Automated: Pre-commit hooks and CI pipeline enforcement
- Strict TypeScript: No
any
types, comprehensive type definitions - Type Exports: Full TypeScript support for consumers
- Documentation: JSDoc comments for all public APIs
-
CI Pipeline (
ci.yml
):- Linting and formatting checks
- Tests on multiple Node.js versions (18, 20, 22)
- Tests on multiple operating systems (Ubuntu, Windows, macOS)
- Code coverage reporting
- Security auditing
-
Publishing (
publish.yml
):- Automated npm publishing on GitHub releases
- Package verification and validation
- Release asset generation
-
Security (
codeql.yml
):- Weekly security analysis
- Vulnerability scanning
- Automated security updates
Automated dependency updates for:
- npm packages (weekly)
- GitHub Actions (weekly)
- Security patches (immediate)
This project is licensed under the MIT License - see the LICENSE.md file for details.
Contributions are welcome! Please read our Contributing Guidelines and Code of Conduct before getting started.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Make your changes
- Add tests for your changes
- Ensure all tests pass and code is formatted
- Commit your changes (
git commit -m 'feat: add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: contact@rumenx.com
This package demonstrates:
- Modern npm package structure
- TypeScript development workflow
- Testing strategies with Jest
- Code quality tools setup
- Advanced TypeScript configurations
- CI/CD pipeline implementation
- Automated dependency management
- Professional documentation practices
- Package publishing strategies
- Multi-format module exports
- Security automation
- Open source maintenance workflows
- TypeScript Handbook
- Jest Testing Framework
- ESLint Configuration
- GitHub Actions Documentation
- npm Publishing Guide
- Bundle Size: < 5KB minified
- Dependencies: Zero runtime dependencies
- Node.js Support: 18+ (LTS)
- TypeScript Support: Full type definitions included
- Test Coverage: 95%+
Made with β€οΈ by Rumen Damyanov
This package exists to bridge the gap between simple tutorials and complex real-world packages. It provides a complete, production-ready example of how modern npm packages should be structured, developed, and maintained while keeping the actual functionality intentionally simple.