Conversation
- calculator: divide throws on division by zero instead of returning Infinity - string-utils: wordCount collapses consecutive whitespace; implement truncate at word boundary with ellipsis counted toward maxLength - task-manager: implement remove, update, and sortBy (priority/createdAt/status) - date-utils: fix off-by-one in formatRelative day bucketing (round, not floor) - validator: isEmail accepts long TLDs/subdomains; isUrl accepts URLs with ports
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 TypeScript utility library. Test suite now: 60 pass, 0 fail;
tsc --noEmitclean.Only source files were changed — no test files modified, no dependencies added.
Fixes by file
src/calculator.ts—dividenow throws on a zero divisor instead of returningInfinity.src/string-utils.ts—wordCountcollapses consecutive whitespace (splits on/\s+/after trim);truncateimplemented per its TODO: unchanged whenstr.length <= maxLength, otherwise truncates at a word boundary with"..."counting towardmaxLength.src/task-manager.ts— implementedremove(false on unknown id),update(partial field updates, false on unknown id), andsortBy(priority high→low, createdAt oldest-first, plus status).src/date-utils.ts— fixed off-by-one informatRelative: day bucketing usesMath.roundon the absolute hour difference (36h → "2 days ago").src/validator.ts—isEmailaccepts long TLDs and subdomains;isUrlaccepts URLs with an explicit port.Assumptions
truncatereserves 3 chars for the ellipsis and backs up to the last word boundary; amaxLength <= 3guard avoids a negative slice budget.sortByonstatus(in the type union but not under test) was implemented rather than left to throw.updateuses per-field!== undefinedchecks so a partialchangesobject can't blank unmentioned fields.Non-blocking notes for follow-up
isEmailis a syntactic check only — pair with a confirmation flow before treating an address as verified.updateaccepts caller-supplied values without length/content bounds; worth a security pass if this feeds a service storing personal data.Testing
bun test→ 60 pass, 0 failbunx tsc --noEmit→ exits 0