Skip to content

Commit be49396

Browse files
docs: add CHANGELOG and migration guide for v0.1.0
- Add comprehensive CHANGELOG.md with breaking changes documentation - Add migration guide in README for users upgrading from v0.0.x - Document all behavioral changes and required code updates - Provide clear before/after examples for migration
1 parent deb86e0 commit be49396

2 files changed

Lines changed: 210 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [0.1.0] - 2025-11-04
9+
10+
### ⚠️ BREAKING CHANGES
11+
12+
This release introduces **breaking changes** that will require code updates for existing users.
13+
14+
#### Error Handling Changes
15+
16+
**Previous Behavior (v0.0.x):**
17+
- Invalid inputs (null, undefined, non-numeric strings) were silently handled
18+
- Methods returned `0` and logged warnings to console
19+
- Division by zero returned `0`
20+
21+
**New Behavior (v0.1.0+):**
22+
- Invalid inputs now throw `HyperMathError` exceptions
23+
- Division by zero throws `DivisionByZeroError` (extends `HyperMathError`)
24+
- No silent failures - all errors must be handled
25+
26+
#### Migration Guide
27+
28+
**Before (v0.0.x):**
29+
```typescript
30+
import { HyperMath } from 'hypermath';
31+
32+
// Silent failure - returns 0 on error
33+
const result = HyperMath.multiply(userInput, 5);
34+
const quotient = HyperMath.divide(10, 0); // Returns 0
35+
```
36+
37+
**After (v0.1.0+):**
38+
```typescript
39+
import { HyperMath, HyperMathError, DivisionByZeroError } from 'hypermath';
40+
41+
// Proper error handling required
42+
try {
43+
const result = HyperMath.multiply(userInput, 5);
44+
} catch (error) {
45+
if (error instanceof HyperMathError) {
46+
console.error('Invalid input:', error.message);
47+
// Handle error appropriately
48+
}
49+
}
50+
51+
// Division by zero protection
52+
try {
53+
const quotient = HyperMath.divide(10, divisor);
54+
} catch (error) {
55+
if (error instanceof DivisionByZeroError) {
56+
console.error('Cannot divide by zero');
57+
}
58+
}
59+
```
60+
61+
#### Behavior Corrections
62+
63+
- **`subtract(0, n)`**: Now correctly returns `-n` instead of `0`
64+
- **`divide(0, n)`**: Now correctly returns `0` (unchanged)
65+
- **Edge case handling**: Proper handling of NaN, Infinity, and extreme values
66+
67+
### Added
68+
69+
-**Custom Error Classes**
70+
- `HyperMathError`: Base error class for all HyperMath errors
71+
- `DivisionByZeroError`: Specific error for division by zero operations
72+
73+
- 📚 **Comprehensive Documentation**
74+
- JSDoc comments for all public methods
75+
- Detailed parameter and return type documentation
76+
- Error throwing documentation with examples
77+
78+
-**Robust Test Coverage**
79+
- Expanded from 4 to 52 unit tests
80+
- Edge case testing (negative numbers, zero handling, precision)
81+
- Invalid input testing for all methods
82+
- All tests passing with 100% coverage of core functionality
83+
84+
- 🛡️ **Enhanced Input Validation**
85+
- Validates null, undefined, NaN, Infinity
86+
- Trims whitespace from string inputs
87+
- Better error messages with context
88+
- Type checking for unsupported types
89+
90+
- 📦 **Package Configuration**
91+
- Added `types` field for TypeScript definitions
92+
- Added `files` field to optimize package size
93+
- Only distributes necessary files (dist, README, LICENSE)
94+
95+
### Changed
96+
97+
- 🔧 **Code Refactoring**
98+
- Extracted `processInput()` as private helper method
99+
- Extracted `formatResult()` as private helper method
100+
- Cleaner, more maintainable code structure
101+
- Better separation of concerns
102+
103+
- 📖 **README Improvements**
104+
- Added error handling section with examples
105+
- Enhanced API documentation with parameters and throws
106+
- Added edge cases documentation
107+
- Corrected technical inaccuracies (`.toFixed()` vs `.toPrecision()`)
108+
- Added support section with GitHub issues link
109+
- Updated features list with accurate descriptions
110+
111+
### Fixed
112+
113+
- 🐛 **Subtract method**: Now correctly handles `subtract(0, n)` returning `-n` instead of `0`
114+
- 🐛 **Precision documentation**: Corrected claims about "2 significant digits" to "2 decimal places"
115+
116+
### Technical Details
117+
118+
- **Error Types**: All methods now throw typed errors for better error handling
119+
- **Input Processing**: Unified input validation across all methods
120+
- **TypeScript Support**: Full type safety with exported error classes
121+
- **Zero Dependencies**: Remains lightweight with no external dependencies
122+
123+
---
124+
125+
## [0.0.10] - Previous Release
126+
127+
### Features
128+
- Basic arithmetic operations (multiply, add, divide, subtract)
129+
- Precision handling up to 2 decimal places
130+
- String and number input support
131+
- Console warnings for invalid inputs
132+
133+
### Behavior
134+
- Silent failure mode (returns 0 on errors)
135+
- Console.warn for invalid inputs
136+
- Limited edge case handling
137+
138+
---
139+
140+
## Upgrading from v0.0.x to v0.1.0
141+
142+
### Required Changes
143+
144+
1. **Wrap arithmetic operations in try-catch blocks** where invalid input is possible
145+
2. **Import error classes** if you need to catch specific error types
146+
3. **Remove any code** that relied on `0` being returned for invalid inputs
147+
4. **Update tests** to expect thrown errors instead of `0` returns
148+
149+
### Benefits
150+
151+
- ✅ Better error visibility and debugging
152+
- ✅ More predictable behavior
153+
- ✅ Proper TypeScript error typing
154+
- ✅ Production-ready error handling
155+
- ✅ Comprehensive test coverage
156+
157+
### Support
158+
159+
If you encounter issues upgrading, please:
160+
- Check the [README](README.md) for updated usage examples
161+
- Review the error handling section
162+
- Open an issue on [GitHub](https://github.com/hyperteksolutions/hypermath/issues)
163+
164+
---
165+
166+
[0.1.0]: https://github.com/hyperteksolutions/hypermath/compare/v0.0.10...v0.1.0
167+
[0.0.10]: https://github.com/hyperteksolutions/hypermath/releases/tag/v0.0.10

README.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,54 @@ Formats a number to maintain precision up to 2 decimal places.
140140

141141
**Throws:** `HyperMathError` if input is invalid
142142

143+
## Migration from v0.0.x
144+
145+
⚠️ **Version 0.1.0 introduces breaking changes.** If you're upgrading from v0.0.x, please note:
146+
147+
### What Changed
148+
149+
In previous versions (v0.0.x), invalid inputs would silently return `0` with a console warning. **Now, errors are thrown** for better error handling and debugging.
150+
151+
**Old Behavior (v0.0.x):**
152+
```typescript
153+
HyperMath.multiply('invalid', 5); // Returned 0 (with console warning)
154+
HyperMath.divide(10, 0); // Returned 0
155+
```
156+
157+
**New Behavior (v0.1.0+):**
158+
```typescript
159+
HyperMath.multiply('invalid', 5); // Throws HyperMathError ❌
160+
HyperMath.divide(10, 0); // Throws DivisionByZeroError ❌
161+
```
162+
163+
### How to Update Your Code
164+
165+
Wrap operations in try-catch blocks where invalid input is possible:
166+
167+
```typescript
168+
// Before (v0.0.x) - unsafe
169+
const result = HyperMath.multiply(userInput, 5);
170+
171+
// After (v0.1.0+) - safe
172+
try {
173+
const result = HyperMath.multiply(userInput, 5);
174+
// Use result...
175+
} catch (error) {
176+
if (error instanceof HyperMathError) {
177+
console.error('Invalid input:', error.message);
178+
// Handle error appropriately
179+
}
180+
}
181+
```
182+
183+
See [CHANGELOG.md](CHANGELOG.md) for complete migration guide.
184+
143185
## Notes
144186

145187
- **Precision**: This library uses `.toFixed(2)` internally to maintain precision up to 2 decimal places. This may lead to rounding in some cases. Be aware of this limitation when using the library for calculations requiring higher precision.
146188
- **Error handling**: The library now throws `HyperMathError` exceptions instead of returning 0 for invalid inputs. Make sure to handle these errors appropriately in your code.
147189
- **Edge cases**:
148-
- **Division by zero**: Throws `HyperMathError` instead of returning 0
190+
- **Division by zero**: Throws `DivisionByZeroError` instead of returning 0
149191
- **Invalid inputs**: Any null, undefined, or non-numeric string values will throw `HyperMathError`
150192
- **String parsing**: String inputs are parsed using `parseFloat()`, so partial numeric strings like "123abc" will parse as 123
151193
- **Type safety**: TypeScript users benefit from full type definitions and the custom `HyperMathError` class for better error handling

0 commit comments

Comments
 (0)