fix: implement missing utilities and fix edge-case bugs - #326
Open
stooit wants to merge 1 commit into
Open
Conversation
- calculator: divide now throws on division by zero instead of returning Infinity - string-utils: wordCount collapses consecutive whitespace; implement truncate at word boundary with ellipsis counting toward maxLength - task-manager: implement remove, update, and sortBy (priority/createdAt/status) - date-utils: formatRelative rounds days instead of flooring (36h => 2 days ago) - validator: isEmail accepts long TLDs; 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 5 source files. All 60 tests now pass; no test files were modified and no dependencies were added.
Changes
src/calculator.ts—dividenow throws on division by zero instead of returningInfinity.src/string-utils.ts—wordCountcollapses consecutive whitespace (splits on\s+after trim).truncateimplemented: truncates at a word boundary with"..."counting towardmaxLength, returns unchanged whenstr.length <= maxLength, and handles short/edge inputs.src/task-manager.ts— implementedremove(true/false on found),update(partial title/description/priority, false for unknown id), andsortBy(priority high>medium>low, createdAt oldest-first, status workflow order).sortBysorts a copy and does not mutate internal state.src/date-utils.ts—formatRelativenow rounds days instead of flooring, so 36h reads "2 days ago".src/validator.ts—isEmailaccepts long TLDs (bound widened to DNS label limit{2,63}) while still rejecting empty labels;isUrlaccepts URLs with ports, keeping thehttp/httpsprotocol allow-list.Assumptions
sortBy("status")uses the workflow order pending -> in_progress -> completed (no explicit test asserts this ordering, chosen as the natural default).Security note
isUrlvalidates scheme only. If ever used to gate a server-side fetch it is not sufficient SSRF protection on its own —http://localhost:3000and link-local addresses pass. A host allow-list / private-range block at the call site would be needed for that use case.Verification
bun test-> 60 pass, 0 fail.tsc --noEmitclean.