fix: implement missing utility functions and fix edge-case bugs - #296
Open
stooit wants to merge 1 commit into
Open
fix: implement missing utility functions and fix edge-case bugs#296stooit wants to merge 1 commit into
stooit wants to merge 1 commit into
Conversation
- calculator: divide now throws on division by zero instead of returning Infinity - string-utils: wordCount collapses consecutive/leading/trailing whitespace; implement truncate at word boundary with ellipsis counting toward maxLength - task-manager: implement remove, update, and sortBy (priority/createdAt/status) - date-utils: formatRelative uses Math.round for day diff (36h -> 2 days ago) - validator: isEmail accepts long TLDs; isUrl accepts URLs with ports
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. All 60 tests now pass (0 fail);
tsc --noEmitis clean. No test files were modified and no dependencies were added.Changes
src/calculator.ts—dividenow throws on division by zero instead of returningInfinity.src/string-utils.tswordCount— trims and splits on\s+, collapsing consecutive/leading/trailing whitespace ("hello world"→ 2).truncate— implemented: returns unchanged whenstr.length <= maxLength; otherwise reserves 3 chars for"...", backs up to the last word boundary, and appends the ellipsis (ellipsis counts towardmaxLength).src/task-manager.ts— implementedremove(Map delete → true/false),update(partial title/description/priority, false if not found), andsortBy(priority high>medium>low, status, createdAt oldest-first). Sort copies the values before sorting, so internal order is untouched.src/date-utils.ts—formatRelativeday diff usesMath.roundinstead ofMath.floor, so 36 hours renders as "2 days ago".src/validator.ts—isEmailaccepts long TLDs (e.g..museum) and subdomains;isUrlaccepts URLs with ports (e.g.http://localhost:3000) by validating on protocol only.Verification
bun test→ 60 pass, 0 fail, 70 expect() calls.tsc --noEmitexits 0.truncatelength invariant across edge cases and ruled out ReDoS in the new email regex.Notes / assumptions
update(id, { description: undefined })intentionally no-ops rather than clearing the field — no test covers clearing, and scope was to fix only what tests require.formatRelativethat predates this change and is outside the failing-test scope.