fix: implement missing utilities and fix edge-case bugs - #277
Open
stooit wants to merge 1 commit into
Open
Conversation
- calculator: divide now throws on division by zero - string-utils: wordCount collapses consecutive whitespace; implement truncate at word boundary with ellipsis - task-manager: implement remove, update, and sortBy (priority/createdAt/status) - date-utils: formatRelative uses rounding to fix off-by-one (36h -> 2 days ago) - validator: isEmail accepts long TLDs; isUrl accepts host:port All 60 tests pass. No test files or dependencies modified.
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 the utility library. The suite now reports 60 pass / 0 fail (was 44 pass / 16 fail). No test files were modified and no dependencies were added.
Changes (src only)
calculator.ts—dividenow throws on division by zero instead of returningInfinity(b === 0also catches-0).string-utils.ts—wordCountcollapses consecutive whitespace (/\s+/); implementedtruncateto cut at a word boundary with the ellipsis counting towardmaxLength.task-manager.ts— implementedremove,update, andsortBy. Priority sort orders high > medium > low; sort is stable so equal keys keep insertion order.date-utils.ts—formatRelativenow usesMath.round(Math.abs(...)), fixing the off-by-one (36h → "2 days ago") symmetrically for past and future.validator.ts—isEmailaccepts long TLDs (e.g..museum);isUrlacceptshost:port(e.g.http://localhost:3000). Added a JSDoc note thatisUrlis a format check, not an SSRF control.Verification
bun test→ 60 pass, 0 failtsc --noEmit→ cleanAssumptions / scope notes
maxLengthguard, tab/newline word boundaries intruncate, patch-clear semantics inupdate) were left out as they have no test coverage and no in-repo callers.sortBy("status")needed some ordering because"status"is in the type union; chosein_progress > pending > completed. No test constrains it.package.json/.gitignoreedits, docs) were reverted to honour the "no new dependencies / fix only what's required" constraint.