Thank you for your interest in contributing! This document provides guidelines for contributing to the @countrystatecity/timezones package.
-
Fork and Clone
git clone https://github.com/YOUR_USERNAME/countrystatecity-timezones.git cd countrystatecity-timezones -
Install Dependencies
npm install
-
Build Package
npm run build
-
Run Tests
npm test
Create a descriptive branch name:
git checkout -b feature/add-new-utility
git checkout -b fix/loader-bug
git checkout -b docs/update-readme-
Code Changes
- Follow existing code style
- Add TypeScript types for all new code
- Update tests for any changes
- Ensure all tests pass:
npm test
-
Documentation
- Update README files for user-facing changes
- Add JSDoc comments to public APIs
- Update CHANGELOG if applicable
-
Testing
# Run all tests npm test # Run tests in watch mode npm run test:watch # Run specific test file npm run test -- tests/unit/loaders.test.ts
Use conventional commit format:
feat:New featurefix:Bug fixdocs:Documentation changestest:Test changeschore:Maintenance tasksrefactor:Code refactoring
Examples:
git commit -m "feat: add getCountryByName utility function"
git commit -m "fix: resolve directory mapping issue for special characters"
git commit -m "docs: update API documentation with examples"-
Push Your Branch
git push origin your-branch-name
-
Create Pull Request
- Go to GitHub and create a PR
- Fill out the PR template
- Link any related issues
-
CI Checks
- All tests must pass
- Code must build successfully
- Bundle size checks must pass
-
Review Process
- Address review feedback
- Keep PR scope focused
- Respond to comments
tests/
├── unit/ # Unit tests for individual functions
├── integration/ # Integration tests for workflows
└── compatibility/ # iOS/Safari compatibility tests
Use Vitest for all tests:
import { describe, it, expect } from 'vitest';
import { getCountries } from '../../src/loaders';
describe('getCountries', () => {
it('should return array of countries', async () => {
const countries = await getCountries();
expect(Array.isArray(countries)).toBe(true);
expect(countries.length).toBeGreaterThan(0);
});
});# Run all tests
npm test
# Run iOS compatibility tests only
npm run test:ios
# Run with coverage
npx vitest --coverageTo update the timezone data from the source:
# Download latest data
curl -L "https://github.com/dr5hn/countries-states-cities-database/releases/latest/download/json-countries%2Bstates%2Bcities.json.gz" \
-o /tmp/countries-data.json.gz
gunzip /tmp/countries-data.json.gz
# Generate timezone data structure
npm run generate-data -- /tmp/countries-data.json
# Test with new data
npm run build
npm testData updates happen automatically:
- Schedule: Weekly on Sundays at 00:00 UTC
- Process: Downloads → Transforms → Tests → Creates PR
- Review: Check the automated PR before merging
To add new functionality to the package:
-
Create Feature Files
# Add your new function in src/ touch src/your-feature.ts -
Export from Index
// src/index.ts export { yourNewFunction } from './your-feature';
-
Add Tests
# Create test file touch tests/unit/your-feature.test.ts -
Update Documentation
- Add API documentation in README.md
- Include usage examples
- Document any breaking changes
# Clean all build artifacts
rm -rf dist/
# Reinstall dependencies
rm -rf node_modules package-lock.json
npm install
# Build with verbose output
npm run build# Run tests with debug output
DEBUG=* npm test
# Run single test file
npx vitest tests/unit/loaders.test.ts
# Update test snapshots
npx vitest -u- Check workflow logs in GitHub Actions
- Run the same commands locally
- Ensure Node version matches (v18 or higher)
- Verify all dependencies are installed correctly
- Use JSDoc for all public functions
- Include
@param,@returns,@example - Document any warnings or limitations
Example:
/**
* Get all cities in a specific state
* @param countryCode - ISO2 country code (e.g., 'US')
* @param stateCode - State code (e.g., 'CA')
* @returns Promise with array of cities
* @example
* ```typescript
* const cities = await getCitiesOfState('US', 'CA');
* console.log(cities[0].name); // "Los Angeles"
* ```
*/
export async function getCitiesOfState(
countryCode: string,
stateCode: string
): Promise<ICity[]> {
// Implementation
}Update README.md for:
- API changes and new functions
- Usage examples
- Breaking changes or migration guides
- Use strict mode
- Prefer
constoverlet - Use explicit return types
- Avoid
any(useunknownif needed)
Code is formatted automatically, but follow these guidelines:
- 2 spaces for indentation
- Single quotes for strings
- Trailing commas in objects/arrays
- No semicolons
- Functions:
camelCase - Types/Interfaces:
PascalCasewithIprefix for interfaces - Constants:
UPPER_SNAKE_CASE - Files:
kebab-case.ts
For any data-related issues (incorrect country names, missing cities, wrong coordinates, etc.), please report them to the source database repository:
📊 Countries States Cities Database
This package uses data from the above repository. Data fixes should be made there first, then synced to this package.
Include:
- Clear description of the issue
- Steps to reproduce
- Expected vs actual behavior
- Environment (Node version, OS, etc.)
- Code samples or screenshots
Include:
- Use case and motivation
- Proposed API design
- Examples of usage
- Impact on bundle size
- 📖 Documentation
- 🐛 Issues
- 🌐 NPM Package
By contributing, you agree that your contributions will be licensed under the Open Database License (ODbL) v1.0, the same license as the project.