Conversation
Implement truncate, TaskManager remove/update/sortBy; fix divide-by-zero, whitespace word counting, day rounding, and email/URL validation. - calculator: divide throws on zero divisor instead of returning Infinity - string-utils: implement truncate (word-boundary, ellipsis in budget), fix wordCount to split on runs of whitespace after trim - task-manager: implement remove, update (honours falsy values), sortBy - date-utils: round day buckets (Math.round + abs) fixing off-by-one - validator: isEmail validates domain labels (subdomains, long TLDs), isUrl accepts non-empty port while keeping http/https restriction
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 functions and correcting edge-case bugs across five utility modules. No test files were modified and no dependencies were added.
Changes
src/calculator.ts—dividenow throws on a zero divisor instead of silently returningInfinity.src/string-utils.ts— implementedtruncate(word-boundary clip with"..."counted towardmaxLength, unchanged whenstr.length <= maxLength, clamped for small/negativemaxLength); fixedwordCountto split on runs of whitespace after trimming.src/task-manager.ts— implementedremove(Map-backed true/false contract),update(applies only supplied fields, honouring falsy values like""), andsortBy(priority/status rank maps, numericcreatedAt; sorts a copy so Map order is preserved).src/date-utils.ts— day bucket usesMath.roundon the absolute diff, fixing an off-by-one (e.g. 36h → "2 days ago") and making future dates round symmetrically.src/validator.ts—isEmailvalidates each domain label separately (fixes subdomains and long TLDs) with RFC 5321 length bounds;isUrlaccepts a non-empty port while keeping the http/https-only restriction.Verification
bun test→ 60 pass / 0 fail (was 44 pass / 16 fail).bunx tsc --noEmit→ clean.maxLengthclamp intruncate; corrected a misleading ReDoS rationale in theisEmaildocstring).Assumptions / notes
truncatewithmaxLength <= 3on a longer string hard-clips without an ellipsis (ellipsis alone would exceed the budget) — untested edge, chosen for the length guarantee.updateuses!== undefinedchecks, so an optional field cannot currently be cleared by passingundefined— matches existing untested behaviour; left as-is.in_progress > pending > completed) is not test-covered; chosen as a sensible default.