date-core
Version:
Modern, lightweight date utilities library for React Native and web apps. Features comprehensive locale support with Arabic numerals, intelligent error handling, and production-ready logging. 93% smaller bundle size than heavy date libraries.
322 lines (252 loc) • 7.1 kB
Markdown
Thank you for your interest in contributing to Date-Core! This document provides guidelines and information for contributors.
- [Code of Conduct](
- [How Can I Contribute?](
- [Development Setup](
- [Testing](
- [Submitting Changes](
- [Adding New Locales](
- [Code Style](
This project and everyone participating in it is governed by our Code of Conduct. By participating, you are expected to uphold this code.
- Use the GitHub issue tracker
- Include detailed steps to reproduce the bug
- Provide your environment details (OS, Node.js version, etc.)
- Include error messages and stack traces
### Suggesting Enhancements
- Use the GitHub issue tracker with the "enhancement" label
- Describe the feature and its benefits
- Provide use cases and examples
### Pull Requests
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Update documentation if needed
- Submit a pull request
## 🛠️ Development Setup
### Prerequisites
- Node.js >= 14.0.0
- Yarn (recommended) or npm
```bash
git clone https://github.com/yourusername/date-core.git
cd date-core
yarn install
yarn test
yarn demo
```
```bash
yarn test
yarn test:watch
yarn test:coverage
yarn demo
yarn demo:advanced
yarn demo:multi-locale
yarn demo:error
yarn demo:init
yarn build
yarn prepublishOnly
```
```bash
yarn test
yarn test:watch
yarn test:coverage
```
- **Unit Tests**: Test individual functions
- **Integration Tests**: Test function combinations
- **Locale Tests**: Test locale-specific functionality
- **Error Handling Tests**: Test invalid input handling
```javascript
// Example test structure
describe('formatDate', () => {
it('should format valid date correctly', () => {
const result = formatDate(new Date('2024-01-15'));
expect(result).toBe('2024-01-15');
});
it('should handle invalid date gracefully', () => {
const result = formatDate('invalid-date');
expect(result).toMatch(/^\d{4}-\d{2}-\d{2}$/);
});
});
```
Use conventional commit format:
```
type(scope): description
[]
[]
```
Examples:
- `feat(locale): add Italian locale support`
- `fix(formatting): handle null dates gracefully`
- `docs(readme): update installation instructions`
1. **Fork** the repository
2. **Create** a feature branch: `git checkout -b feature/amazing-feature`
3. **Make** your changes
4. **Add** tests for new functionality
5. **Run** tests: `yarn test`
6. **Commit** your changes: `git commit -m 'feat: add amazing feature'`
7. **Push** to the branch: `git push origin feature/amazing-feature`
8. **Open** a Pull Request
- Provide a clear description of the changes
- Include tests for new functionality
- Update documentation if needed
- Ensure all tests pass
- Follow the code style guidelines
Create a new locale file in `lib/locales/`:
```javascript
// lib/locales/it.js (Italian example)
export const it = {
months: [
'gennaio',
'febbraio',
'marzo',
'aprile',
'maggio',
'giugno',
'luglio',
'agosto',
'settembre',
'ottobre',
'novembre',
'dicembre',
],
monthsShort: [
'gen',
'feb',
'mar',
'apr',
'mag',
'giu',
'lug',
'ago',
'set',
'ott',
'nov',
'dic',
],
weekdays: [
'domenica',
'lunedì',
'martedì',
'mercoledì',
'giovedì',
'venerdì',
'sabato',
],
weekdaysShort: ['dom', 'lun', 'mar', 'mer', 'gio', 'ven', 'sab'],
weekdaysMin: ['do', 'lu', 'ma', 'me', 'gi', 've', 'sa'],
relativeTime: {
future: 'tra %s',
past: '%s fa',
s: 'alcuni secondi',
ss: '%d secondi',
m: 'un minuto',
mm: '%d minuti',
h: "un'ora",
hh: '%d ore',
d: 'un giorno',
dd: '%d giorni',
w: 'una settimana',
ww: '%d settimane',
M: 'un mese',
MM: '%d mesi',
y: 'un anno',
yy: '%d anni',
},
calendar: {
sameDay: 'oggi alle LT',
nextDay: 'domani alle LT',
nextWeek: 'dddd alle LT',
lastDay: 'ieri alle LT',
lastWeek: 'dddd scorso alle LT',
sameElse: 'L',
},
numberMap: {}, // For custom numeral systems
symbolMap: {}, // For custom numeral systems
};
export default it;
```
1. **Create** the locale file
2. **Add** export to `lib/locales/index.js`
3. **Add** tests for the new locale
4. **Update** documentation
5. **Test** with demos
```javascript
// Test the new locale
import {setLocale, formatDateLocalized} from 'date-core';
import {it} from 'date-core';
// Register and test
registerLocale('it', it);
setLocale('it');
console.log(formatDateLocalized(new Date())); // Should show Italian date
```
- Use ES6+ features
- Use arrow functions where appropriate
- Use template literals for string interpolation
- Use destructuring for object/array access
- Use const/let instead of var
- Use meaningful variable names
```
lib/
├── config/
├── core/
├── utils/
└── locales/
```
- Keep functions small and focused
- Use descriptive function names
- Add JSDoc comments for public functions
- Handle errors gracefully
- Return consistent data types
```javascript
/**
* Formats a date with locale support
* @param {Date|string} date - The date to format
* @param {Object} options - Formatting options
* @param {string} [options.locale] - Locale code
* @param {string} [options.format] - Format type
* @returns {string} Formatted date string
*/
export const formatDateLocalized = (date, {locale, format} = {}) => {
// Implementation
};
```
- [GitHub Issues](https://github.com/yourusername/date-core/issues)
- [API Documentation](./README.md
- [Demo Examples](./demos/)
Thank you for contributing to Date-Core! Your contributions help make this library better for everyone.