Shared utilities for DH-Reporting app
npm install @orenuki/dh-reporting-sharedbash
For local development (from parent directory)
npm install ../dh-reporting-shared
For published package (future)
npm install @dh-reporting/shared
`
$3
`javascript
// Import validation functions
import { validateEmail, validateTimeEntry } from '@dh-reporting/shared';
// Import date utilities
import { formatWorkHours, calculateDuration } from '@dh-reporting/shared';
// Import types
import { User, Project, TimeEntry } from '@dh-reporting/shared';
// Import constants
import { APP_CONSTANTS, TIME_FORMATS } from '@dh-reporting/shared';
`
๐ Project Structure
`
src/
โโโ validation/ # Input validation functions
โ โโโ userValidation.js
โ โโโ timeValidation.js
โ โโโ projectValidation.js
โโโ utils/ # Utility functions
โ โโโ dateUtils.js
โ โโโ timeUtils.js
โ โโโ formatUtils.js
โโโ business-logic/ # Business rules and calculations
โ โโโ timeCalculations.js
โ โโโ projectLogic.js
โ โโโ overtimeRules.js
โโโ types/ # Type definitions
โ โโโ commonTypes.js
โ โโโ userTypes.js
โ โโโ projectTypes.js
โโโ constants/ # Application constants
โ โโโ appConstants.js
โ โโโ errorCodes.js
โ โโโ timeFormats.js
โโโ testing/ # Testing utilities
โ โโโ testUtils.js
โ โโโ mockData.js
โ โโโ testHelpers.js
โโโ index.js # Main export file
`
๐ ๏ธ Available Functions
$3
`javascript
import { validateEmail, validateEmployeeCode, validateTimeEntry } from '@dh-reporting/shared';
// Email validation
const isValidEmail = validateEmail('user@example.com'); // true/false
// Employee code validation
const isValidCode = validateEmployeeCode('EMP001'); // true/false
// Time entry validation
const isValidEntry = validateTimeEntry({
projectId: 'proj-123',
date: '2024-01-15',
duration: 480 // minutes
}); // true/false
`
$3
`javascript
import { formatWorkHours, calculateDuration, isBusinessDay } from '@dh-reporting/shared';
// Format work hours for display
const formatted = formatWorkHours(480); // "8.0 hours"
// Calculate duration between times
const duration = calculateDuration('09:00', '17:30'); // 510 minutes
// Check if date is a business day
const isBusiness = isBusinessDay(new Date()); // true/false
`
$3
`javascript
import { calculateOvertime, validateWorkSchedule, getProjectProgress } from '@dh-reporting/shared';
// Calculate overtime hours
const overtime = calculateOvertime(dailyHours, 8); // hours over standard
// Validate work schedule
const isValid = validateWorkSchedule(timeEntries); // true/false
// Calculate project progress
const progress = getProjectProgress(timeEntries, allocatedHours); // percentage
`
๐๏ธ Development
$3
`bash
Clone the repository
git clone https://bitbucket.org/your-username/dh-reporting-shared.git
cd dh-reporting-shared
Install dependencies
npm install
Run tests
npm test
Build the library
npm run build
`
$3
1. Make changes to source files in src/
2. Add tests for new functionality
3. Run tests to ensure everything works: npm test
4. Update version in package.json if needed
5. Commit changes with descriptive commit messages
6. Push to repository
$3
`bash
Run all tests
npm test
Run tests in watch mode
npm run test:watch
Run tests with coverage
npm run test:coverage
`
๐ฆ Usage in Projects
$3
`javascript
// In React Native components
import { validateEmail, formatWorkHours } from '@dh-reporting/shared';
const SignUpScreen = () => {
const handleEmailChange = (email) => {
const isValid = validateEmail(email);
// Handle validation result
};
};
`
$3
`javascript
// In React components
import { calculateOvertime, getProjectProgress } from '@dh-reporting/shared';
const ProjectDashboard = () => {
const progress = getProjectProgress(timeEntries, allocatedHours);
// Display progress
};
`
๐ Version Management
This library follows Semantic Versioning:
- MAJOR version for incompatible API changes
- MINOR version for backwards-compatible functionality additions
- PATCH version for backwards-compatible bug fixes
$3
When updating the shared library:
`bash
In mobile app
cd ../dh-reporting-mobile
npm install ../dh-reporting-shared
In web app
cd ../dh-reporting-web
npm install ../dh-reporting-shared
`
๐งช Testing Strategy
- Unit tests for all validation functions
- Integration tests for business logic
- Mock data generators for testing consuming applications
- Type checking for TypeScript compatibility
๐ Contributing
1. Create a feature branch from develop
2. Make your changes with appropriate tests
3. Ensure all tests pass
4. Update documentation if needed
5. Create a pull request to develop`