fix: implement missing utilities and fix edge-case bugs - #265
Open
stooit wants to merge 1 commit into
Open
Conversation
- calculator: guard divide against division by zero - date-utils: use Math.round for day diff (36h -> '2 days ago') - string-utils: implement truncate at word boundary with ellipsis - task-manager: complete missing/incomplete TaskManager methods - validator: relax email TLD regex, use URL parser for isUrl All 60 tests pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes all 16 previously-failing tests across the utility library. Suite now passes 60/60 with no test files modified and no new dependencies.
Changes
src/calculator.ts—dividenow throwsDivision by zerowhen the divisor is0instead of returningInfinity.src/date-utils.ts— day-difference now usesMath.roundinstead ofMath.floor, so 36 hours correctly reports"2 days ago"(fixes the off-by-one).src/string-utils.ts— implementedtruncate: truncates at a word boundary with"..."counting towardmaxLength, returns the string unchanged whenstr.length <= maxLength.src/task-manager.ts— completed the missing/incompleteTaskManagermethods without mutating internal state on read.src/validator.ts— relaxed theisEmailTLD regex to accept long TLDs (e.g..museum); reworkedisUrlto use the platformURLparser with anhttp/httpsprotocol guard (accepts ports likehttp://localhost:3000).Verification
bun test→ 60 pass, 0 fail (70 assertions).Assumptions / Notes
src/were changed; no test files touched, no dependencies added.date-utils.ts(23h30m–23h59m rounds to "24 hours ago" rather than "1 day ago"). It predates this change, is untested, and is out of scope — noted for a possible follow-up.