fix: implement missing utilities and fix edge-case bugs - #331
Open
stooit wants to merge 1 commit into
Open
Conversation
- calculator: divide now throws on zero divisor instead of returning Infinity - string-utils: implement truncate (word-boundary + ellipsis); fix wordCount for consecutive whitespace - date-utils: fix off-by-one in formatRelative day rounding - validator: fix isEmail long-TLD rejection and isUrl explicit-port rejection - task-manager: implement remove, update, and sortBy 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 (now 60 pass / 0 fail) by implementing missing functionality and correcting edge-case bugs across the utility library. No test files were modified and no dependencies were added.
Fixes
src/calculator.ts—dividereturnedInfinityfor a zero divisor; now throwsError("Division by zero")(fail-closed on invalid input).src/string-utils.tstruncate— implemented: returns unchanged whenstr.length <= maxLength, otherwise reserves 3 chars for"...", backtracks to the last word boundary, trims trailing whitespace, and appends the ellipsis. GuardsmaxLength <= 3so the result never exceedsmaxLength.wordCount— wassplit(" ")(counted empty strings from consecutive spaces). Now trims and splits on/\s+/, also handling tabs/newlines.src/date-utils.ts—formatRelativeusedMath.floor(diffHours / 24), so 12h–47h all rendered "1 day ago". Switched toMath.round; 36h now yields "2 days ago".src/validator.tsisEmail— regex rejected long TLDs (e.g..museum); replaced with a pattern allowing dot-separated labels and a 2+ letter TLD.isUrl— removed theport === ""clause that rejected URLs carrying an explicit port; scheme allowlist (http/https) remains the control.src/task-manager.ts— implementedremove(delegates toMap.delete),update(returnsfalsefor unknown id; applies only present keys), andsortBy(priority/status rank maps + numericcreatedAtcomparator).Testing
bun test→ 60 pass / 0 fail.Assumptions / notes
sortBy/listhand out references to the liveTaskobjects (no defensive copy). Tests don't exercise mutation of stored state, so this was left as-is, but worth noting if consumed across trust boundaries.