fix: repair edge-case bugs and implement missing utility functions - #284
Open
stooit wants to merge 1 commit into
Open
fix: repair edge-case bugs and implement missing utility functions#284stooit 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 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 bucket (fixes 36h off-by-one) - validator: isEmail accepts long TLDs; isUrl accepts URLs with a port 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 failing tests in the utility library (now 60 pass / 0 fail) by repairing edge-case bugs and implementing missing functions. Only the 5 source files were touched — no test files modified, no dependencies added.
Changes
src/calculator.ts—dividenow throws on division by zero instead of silently returningInfinity.src/string-utils.tswordCounttrims and splits on\s+, so consecutive/leading/trailing whitespace collapses correctly.truncateimplemented — truncates at a word boundary, ellipsis (...) counts towardmaxLength, returns unchanged when within the limit.src/task-manager.ts— implementedremove,update(partial field updates), andsortBy(priority high>medium>low, createdAt oldest-first, status).src/date-utils.ts—formatRelativeday bucket usesMath.roundinstead ofMath.floor, fixing the 36h → "2 days ago" off-by-one.src/validator.ts—isEmailaccepts long TLDs (e.g..museum);isUrlaccepts URLs with a port (e.g.http://localhost:3000).Verification
bun test: 60 pass, 0 fail across 5 files.tsc --noEmit: clean.Assumptions / notes
sortBy("status")orderspending → in_progress → completed(matches theStatusunion declaration order); not covered by a test.truncatewith a negativemaxLength, andupdateclearing an optionaldescriptionviaundefined.🤖 Generated with QuantCode