fix: implement missing utilities and fix edge-case bugs - #281
Open
stooit wants to merge 1 commit into
Open
Conversation
- calculator: divide throws on division by zero instead of returning Infinity/NaN - string-utils: implement truncate (word-boundary, ellipsis counts toward maxLength); fix wordCount to collapse consecutive whitespace - task-manager: implement remove/update/sortBy (priority and createdAt ordering) - date-utils: fix off-by-one in day rounding (round instead of floor) - validator: isEmail accepts long TLDs + multi-level subdomains; isUrl accepts ports All 60 tests pass. No test files modified, no dependencies added.
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 all 60 tests pass (was 44 pass / 16 fail). Fixes edge-case bugs and implements missing functionality across the five utility modules. No test files modified, no dependencies added — changes are confined to
src/.Changes
calculator.ts—dividenow throws on division by zero instead of returningInfinity/NaN, failing loudly at the boundary.string-utils.ts— implementedtruncate(truncates at a word boundary,"..."counts towardmaxLength, returns unchanged when within limit, handles strings shorter than the ellipsis). FixedwordCountto collapse consecutive whitespace (splits on/\s+/, also handles tabs/newlines).task-manager.ts— implementedremove(returnsfalsefor unknown id),update(title/priority;falsefor unknown id), andsortBy(priority: high→medium→low; createdAt: oldest first).sortBycopies before sorting so insertion order inlist()is preserved.date-utils.ts— fixed off-by-one informatRelativeday rounding (Math.roundinstead ofMath.floor, consistent with the minute/hour branches).validator.ts—isEmailaccepts arbitrary-length TLDs and multi-level subdomains (and got stricter: rejectsa@b..com,a@.com);isUrlaccepts URLs with a port (removed an erroneousurl.port === ""check) while retaining the http/https scheme allowlist.Verification
tsc --noEmitis clean.Assumptions & known limitations
Per the task constraint ("fix only what the tests require"), the following untested edge cases were left as-is and are documented here for follow-up:
date-utils.formatRelativeusesMath.roundon days; at exact half-day ties, past vs. future differ by direction (no test covers the future case).string-utils.truncateassumes a positivemaxLength; negative/NaNvalues are unguarded.task-manager.updatecannot clear the optionaldescriptionfield (undefinedmeans "leave unchanged").validator.isUrlperforms syntactic validation only — it should not gate server-side fetches without a host allowlist.isEmailis syntactic only and does not prove deliverability.