@showroomprive/srp-gamma-lib-demo
v1.0.4
Published
A sample library nodejs
Readme
SRP Gamma Lib Demo - TypeScript Demo Library
A demonstration TypeScript library showcasing best practices for Node.js library development within the Gamma platform ecosystem. This library serves as a template and reference implementation for creating robust, testable, and maintainable TypeScript libraries.
🚀 Features
- TypeScript First: Full TypeScript support with strict type checking
- Modern JavaScript: ES2020+ features with Node.js 18+ compatibility
- Comprehensive Testing: Jest-based unit testing with coverage reports
- Type Definitions: Exported TypeScript declarations for IntelliSense
- NPM Package: Ready for publication and distribution
- CI/CD Ready: Automated testing and deployment configurations
- Documentation: JSDoc comments and comprehensive README
- Best Practices: Follows industry standards for library development
📋 Prerequisites
- Node.js 18.x or higher
- npm 8.x or higher
- TypeScript 5.0+ (for development)
🛠️ Installation
As a Package
npm install @showroomprive/srp-gamma-lib-demoFor Development
# Clone the repository
git clone <repository-url>
cd src/libs/srp-gamma-lib-demo
# Install dependencies
npm install🏃♂️ Usage
Basic Usage
import { GammaDemoService } from '@showroomprive/srp-gamma-lib-demo';
// Initialize the service
const demoService = new GammaDemoService();
// Use service methods
const result = demoService.performDemoOperation('input-data');
console.log(result);Advanced Usage
import { GammaDemoService } from '@showroomprive/srp-gamma-lib-demo';
// With configuration
const service = new GammaDemoService({
enableLogging: true,
timeout: 5000,
retryAttempts: 3
});
// Async operations
async function example() {
try {
const result = await service.asyncOperation();
return result;
} catch (error) {
console.error('Operation failed:', error);
}
}CommonJS Usage
const { GammaDemoService } = require('@showroomprive/srp-gamma-lib-demo');
const service = new GammaDemoService();
const result = service.performDemoOperation('data');📁 Project Structure
src/libs/srp-gamma-lib-demo/
├── src/
│ └── services/
│ ├── gamma.demo.service.ts # Main service implementation
│ └── gamma.demo.service.spec.ts # Unit tests
├── dist/ # Compiled JavaScript output
├── jest.config.ts # Jest testing configuration
├── tsconfig.json # TypeScript base configuration
├── tsconfig.lib.json # Library-specific TypeScript config
├── package.json # Package configuration
└── README.md # This documentation🧪 Development
Build the Library
# Compile TypeScript to JavaScript
npm run build
# Output will be in the dist/ directoryRun Tests
# Run all tests
npm test
# Run tests with coverage
npm run test:coverage
# Run tests in watch mode
npm run test:watchCode Quality
# Lint code (if configured)
npm run lint
# Format code (if configured)
npm run format
# Type check
npx tsc --noEmit🔧 API Reference
GammaDemoService
The main service class providing demonstration functionality.
Constructor
constructor(options?: GammaDemoOptions)Parameters:
options(optional): Configuration options for the service
Methods
performDemoOperation(input: string): string
Performs a basic demonstration operation.
Parameters:
input: Input string to process
Returns:
- Processed string result
Example:
const result = service.performDemoOperation('hello');
// Returns: "Processed: hello"asyncOperation(): Promise<string>
Performs an asynchronous demonstration operation.
Returns:
- Promise resolving to operation result
Example:
const result = await service.asyncOperation();
// Returns: "Async operation completed"validateInput(input: unknown): boolean
Validates input data according to service rules.
Parameters:
input: Data to validate
Returns:
- Boolean indicating validation success
Types
GammaDemoOptions
Configuration options for the demo service.
interface GammaDemoOptions {
enableLogging?: boolean;
timeout?: number;
retryAttempts?: number;
customConfig?: Record<string, any>;
}📦 Building and Publishing
Build for Distribution
# Clean previous builds
rm -rf dist/
# Compile TypeScript
npm run build
# Verify build output
ls -la dist/Package Verification
# Test the package locally
npm pack
# Install locally for testing
npm install ./showroomprive-srp-gamma-lib-demo-1.0.3.tgzPublishing
# Login to npm (if not already logged in)
npm login
# Publish to npm registry
npm publish
# Publish with specific tag
npm publish --tag beta🧪 Testing Strategy
Unit Tests
Tests are written using Jest and cover:
- Service functionality
- Error handling
- Edge cases
- Type validation
- Async operations
Test Structure
// Example test structure
describe('GammaDemoService', () => {
let service: GammaDemoService;
beforeEach(() => {
service = new GammaDemoService();
});
describe('performDemoOperation', () => {
it('should process input correctly', () => {
const result = service.performDemoOperation('test');
expect(result).toBe('Processed: test');
});
it('should handle empty input', () => {
const result = service.performDemoOperation('');
expect(result).toBe('Processed: ');
});
});
});Coverage Targets
- Statements: > 90%
- Branches: > 85%
- Functions: > 95%
- Lines: > 90%
🔍 Configuration
TypeScript Configuration
// tsconfig.lib.json
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"removeComments": false,
"emitDeclarationOnly": false
},
"include": ["src/**/*"],
"exclude": ["**/*.spec.ts", "**/*.test.ts"]
}Jest Configuration
// jest.config.ts
export default {
preset: 'ts-jest',
testEnvironment: 'node',
roots: ['<rootDir>/src'],
testMatch: ['**/__tests__/**/*.ts', '**/*.(test|spec).ts'],
collectCoverageFrom: [
'src/**/*.ts',
'!src/**/*.d.ts',
'!src/**/*.spec.ts'
],
coverageThreshold: {
global: {
branches: 85,
functions: 95,
lines: 90,
statements: 90
}
}
};🚦 CI/CD Integration
Azure DevOps Pipeline
# azure-pipelines.yml
trigger:
branches:
include:
- main
paths:
include:
- src/libs/srp-gamma-lib-demo/*
jobs:
- job: BuildAndTest
pool:
vmImage: 'ubuntu-latest'
steps:
- task: NodeTool@0
inputs:
versionSpec: '18.x'
- script: npm ci
displayName: 'Install dependencies'
- script: npm run build
displayName: 'Build library'
- script: npm test
displayName: 'Run tests'
- task: PublishTestResults@2
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: 'junit.xml'🔍 Troubleshooting
Common Issues
Build Errors
# Clear cache and rebuild rm -rf dist/ node_modules/ npm install npm run buildType Errors
# Check TypeScript configuration npx tsc --noEmit --listFilesTest Failures
# Run tests in verbose mode npm test -- --verboseImport Issues
# Verify package exports node -e "console.log(require('./package.json').main)"
📚 Documentation
🤝 Contributing
- Follow the Contributing Guidelines
- Maintain TypeScript strict mode compliance
- Write comprehensive unit tests
- Document public APIs with JSDoc comments
- Follow semantic versioning for releases
- Update README for API changes
Development Workflow
- Fork and Clone: Create your own fork and clone locally
- Branch: Create feature branch from main
- Develop: Write code following project standards
- Test: Ensure all tests pass with good coverage
- Document: Update documentation as needed
- PR: Submit pull request with clear description
📄 License
This project is part of the Gamma platform. See the main repository license for details.
🔗 Related Projects
- SRP Gamma Node Private - Production Node.js utilities
- SRP Gamma Angular Library - Angular component library
- SRP Gamma CSS Library - Shared CSS and design tokens
- SRP Gamma V18 - Angular 18 application
- SRP Gamma NestJS API - Backend API
📈 Version History
| Version | Date | Changes | |---------|------|---------| | 1.0.3 | Current | Latest stable release | | 1.0.2 | Previous | Bug fixes and improvements | | 1.0.1 | Previous | Initial bug fixes | | 1.0.0 | Initial | First stable release |
🎯 Roadmap
- [ ] Add more demonstration patterns
- [ ] ESM module support
- [ ] Performance benchmarking
- [ ] Advanced async patterns
- [ ] Stream processing examples
- [ ] Error handling best practices
- [ ] Logging integration examples
