fix: implement missing utilities and fix edge-case bugs - #335
Open
stooit wants to merge 1 commit into
Open
Conversation
- calculator: divide throws on division by zero instead of returning Infinity - string-utils: implement truncate (word-boundary, ellipsis in budget, negative/whitespace-safe); fix wordCount for consecutive whitespace - task-manager: implement remove, partial update, and sortBy (priority/status/createdAt) - date-utils: fix off-by-one in formatRelative day rounding - validator: widen isEmail regex and fix isUrl port check All 60 tests pass; no test files or dependencies changed.
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
Makes the full
bun testsuite pass (was 44 pass / 16 fail → now 60 pass / 0 fail) by implementing missing functionality and fixing edge-case bugs across the utility library. No test files or dependencies were changed.Changes by file
src/calculator.ts—dividenow throwsError("Division by zero")when the divisor is0(also catches-0) instead of returningInfinity.src/string-utils.tswordCountsplits on/\s+/against the trimmed input, so consecutive/leading/trailing whitespace no longer inflates the count.truncateimplemented: returns input unchanged whenstr.length <= maxLength; otherwise reserves 3 chars for"...", cuts at the last whitespace run (word boundary), and is hardened formaxLength <= 0(returns"") and non-space whitespace boundaries.src/task-manager.ts— implementedremove(viaMap.deletecontract), partialupdate(only applies keys explicitly present), andsortByforpriority(high>medium>low),status(pending>in_progress>completed), andcreatedAt(oldest first). Sort operates on a copy so the internal Map order is preserved.src/date-utils.ts—formatRelativeday calculation changedMath.floor→Math.round, fixing the off-by-one where 12h–47h all reported "1 day ago".src/validator.ts—isEmailregex widened to allow multi-level subdomains and longer TLDs while still rejecting missing@/embedded spaces;isUrldropped a spuriousurl.port === ""condition (protocol still restricted to http/https).Verification
bun test→ 60 pass / 0 fail (70 expect() calls, 5 files)tsc --noEmitcleantest/modified; no dependencies added.Assumptions / notes
truncatewas additionally hardened against negativemaxLength(length-invariant violation) and non-space whitespace boundaries — small, no-regression robustness improvements consistent withwordCount's whitespace handling in the same file.formatRelative's hour/minute sub-boundaries; left unchanged as it's outside this task's scope.isEmailremains a syntactic check only — if used to gate account creation, pair with confirmation-link verification.