fix: implement missing utilities and fix edge-case bugs - #274
Open
stooit wants to merge 1 commit into
Open
Conversation
- calculator: divide throws on division by zero - string-utils: implement truncate (word-boundary, ellipsis in maxLength); wordCount handles consecutive whitespace - task-manager: implement remove/update (false for unknown id) and sortBy (priority high>medium>low, createdAt oldest first) - date-utils: fix off-by-one in formatRelative day rounding (abs before round, both past and future) - validator: isEmail supports subdomains/long TLDs with anchored labels; isUrl accepts URLs with a port
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 (60/60 now pass) by implementing missing functionality and correcting edge-case bugs across the utility library. No test files were modified and no dependencies were added.
Changes
src/calculator.ts—dividenow throws on division by zero instead of returning a poisonedInfinity/NaN.src/string-utils.ts— implementedtruncate(truncates at a word boundary with"..."counting towardmaxLength; returns unchanged when within limit; guards short/negativemaxLength). FixedwordCountto split on/\s+/so consecutive spaces/tabs/newlines are handled.src/task-manager.ts— implementedremoveandupdate(both returnfalsefor an unknown id;updateapplies only fields explicitly present) andsortBy(priorityhigh > medium > low;createdAtoldest first).src/date-utils.ts— fixed off-by-one informatRelativeday rounding. Rounding now takes the absolute value beforeMath.round, so 36h resolves to "2 days" for both past and future dates (a review pass caught that rounding the signed value regressed future dates at.5-day boundaries).src/validator.ts—isEmailnow supports arbitrary subdomain depth and long TLDs with anchored labels (still rejectsa@-b.com,a@b..com).isUrlaccepts URLs with a port (e.g.http://localhost:3000) while retaining thehttp/httpsscheme allow-list.Verification
bun test→ 60 pass, 0 failbunx tsc --noEmit→ cleanAssumptions
user@münchen.de) that the old permissive regex accepted are now rejected. This matches the test contract; IDN support was never a requirement. Flagged here in case a consumer relies on it.sortByties oncreatedAtfall back to insertion order via stable sort, which equals creation order givencreatedAtis assigned inadd.