fix: make all failing tests pass across utility library - #283
Open
stooit wants to merge 1 commit into
Open
Conversation
Implements truncate, TaskManager remove/update/sortBy; fixes wordCount consecutive-space handling, formatRelative day rounding, isEmail long TLDs, and isUrl port rejection.
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 previously failing tests (60/60 now green) across the TypeScript utility library. Only
src/files changed — no test files modified, no new dependencies.Changes
src/calculator.ts—dividenow throws on a zero divisor instead of returningInfinity(explicitb === 0guard, also catches-0).src/string-utils.ts— implementedtruncate(ellipsis counted withinmaxLength, word-boundary aware); fixedwordCountto split on/\s+/so runs of whitespace/tabs/newlines don't produce phantom empty words.src/task-manager.ts— implemented stubbedremove,update(partial updates only touch provided keys), andsortBy(priority/status rank maps +createdAttimestamp; sorts a copy).src/date-utils.ts—formatRelativeday calc usesMath.roundinstead ofMath.floor, so 36h reads "2 days ago".src/validator.ts—isEmailaccepts long TLDs (e.g..museum) while still rejecting empty labels;isUrlno longer rejects URLs with ports (e.g.http://localhost:3000), protocol still allowlisted to http/https.Verification
bun test→ 60 pass / 0 fail (stable across repeated runs)tsc --noEmitcleanAssumptions & notes
dividethrowing is an API-visible behaviour change vs. the previousInfinityreturn, sanctioned by the in-codeBUG:comment.maxLengthintruncate, and clearing an optionaldescriptionfield viaupdate.isUrl/isEmailare syntactic validators only; ifisUrlever guards a redirect/fetch target, protocol allowlisting alone won't prevent SSRF to internal addresses.