fix: implement missing utils and fix edge-case bugs to pass tests - #330
Open
stooit wants to merge 1 commit into
Open
fix: implement missing utils and fix edge-case bugs to pass tests#330stooit wants to merge 1 commit into
stooit wants to merge 1 commit into
Conversation
- calculator: divide throws on division by zero instead of returning Infinity - string-utils: wordCount collapses consecutive whitespace; implement truncate - date-utils: fix off-by-one in diffDays for future dates (abs before round) - validator: broaden isEmail regex; fix isUrl port handling (keep scheme allowlist) - task-manager: implement/complete remove, update, and sortBy
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 across 5 source files with no test-file changes and no new dependencies. Full suite now: 60 pass / 0 fail;
bunx tsc --noEmitexits 0.Changes
dividethrowsError("Division by zero")whenb === 0instead of returningInfinity.wordCountsplits on/\s+/against the trimmed string so consecutive whitespace collapses; implementedtruncate(returns unchanged whenstr.length <= maxLength, reserves 3 chars for"..."so output never exceedsmaxLength, cuts back to the last word boundary within budget, hard-slices a single overflowing word).diffDaysby takingMath.absbeforeMath.round.isEmail(arbitrary-depth subdomains, 2+ char TLDs, labels can't start/end with hyphen); fixedisUrlport handling while keeping the http/https scheme allowlist (still rejectsjavascript:etc.).remove(boolean semantics),update(returns false for unknown id, only applies provided fields), andsortBy(priority/status rank maps +createdAttimestamp compare, stable-sort for ties).Testing
bun test→ 60 pass, 0 failbunx tsc --noEmit→ exit 0Notes / assumptions
sortBy("createdAt")relies on stable sort for same-millisecond ties (passes tests).isUrlscheme allowlist is only protective if callers route user-supplied URLs through it.