fix: implement missing utilities and fix edge-case bugs - #337
Open
stooit wants to merge 1 commit into
Open
Conversation
- calculator: divide throws on division by zero (incl. -0) instead of returning Infinity - string-utils: implement truncate (word-boundary, ellipsis within maxLength); fix wordCount to split on any whitespace run - task-manager: implement remove, partial update, and sortBy (priority/status/createdAt) - date-utils: fix off-by-one in formatRelative (round + abs for symmetric past/future) - validator: accept long TLDs in isEmail; accept ports in isUrl while keeping http/https allowlist
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/60 passing) by implementing missing functionality and correcting edge-case bugs. No test files modified, no dependencies added.
Changes
calculator.ts—dividenow throws on division by zero (including-0) instead of returningInfinity.string-utils.ts— implementedtruncate(truncates at a word boundary with"..."counted towardmaxLength, returns unchanged when within limit); fixedwordCountto split on any whitespace run so consecutive spaces/tabs/newlines no longer inflate the count.task-manager.ts— implementedremove(true/false viaMap.delete), partialupdate(only applies keys present inchanges, guarded by!== undefined), andsortByforpriority/status/createdAt(sorts a copy, leaving Map order intact).date-utils.ts— fixed off-by-one informatRelative:Math.floor→Math.roundwithMath.absapplied before rounding, giving symmetric past/future day counts. Removed the now-staleBUG:comment.validator.ts—isEmailTLD quantifier{2,4}→{2,}to accept long TLDs (e.g..museum);isUrlnow accepts explicit ports while keeping thehttp/httpsprotocol allowlist (still rejectsftp://).Verification
bun test: 60 pass / 0 failtsc --noEmit: cleanAssumptions / notes
isEmailremains a deliberately loose regex — it satisfies the tests but is not a full RFC 5322 validator. For security-relevant use, verification-by-delivery is the durable control. Left as-is since no test required tightening.updatetreats{ description: undefined }as "no change" (conventionalPartialsemantics); there's no path to clear a field, matching the tested contract.