feat(string): add strTruncate,strCount strAt and strMatchAll helpers, shared literal regex helper, and coverage#530
feat(string): add strTruncate,strCount strAt and strMatchAll helpers, shared literal regex helper, and coverage#530
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #530 +/- ##
==========================================
+ Coverage 98.83% 98.86% +0.03%
==========================================
Files 138 140 +2
Lines 4019 4147 +128
Branches 859 892 +33
==========================================
+ Hits 3972 4100 +128
Misses 47 47
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds several new string helpers and supporting infrastructure to @nevware21/ts-utils, including String.at / String.matchAll wrappers + polyfills, plus shared helpers and updated exports/tests/size limits.
Changes:
- Added
strAt/polyStrAtandstrMatchAll/polyStrMatchAll, and wired them into the global polyfills loader. - Introduced reusable helpers (
createLiteralRegex,createIterableIterator) and refactoredreplaceAllto use the literal-regex helper. - Expanded/added tests and updated bundle size thresholds/docs accordingly.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/test/src/common/string/truncate.test.ts | Minor test formatting update (blank line changes). |
| lib/test/src/common/string/match_all.test.ts | New tests for strMatchAll/polyStrMatchAll incl. native parity checks. |
| lib/test/src/common/string/at.test.ts | New tests for strAt/polyStrAt incl. native parity checks. |
| lib/test/src/common/helpers/regexp.test.ts | Adds test coverage for createLiteralRegex. |
| lib/test/bundle-size-check.js | Updates bundle-size thresholds used by test tooling. |
| lib/src/string/replace_all.ts | Refactors literal string matcher handling to createLiteralRegex and expands docs. |
| lib/src/string/match_all.ts | New matchAll helper + polyfill using iterators and literal-regex handling. |
| lib/src/string/at.ts | New at helper + polyfill built on polyArrAt + mathToInt. |
| lib/src/polyfills.ts | Registers at and matchAll polyfills on String.prototype. |
| lib/src/iterator/create.ts | Adds createIterableIterator export for combined Iterator+Iterable objects. |
| lib/src/index.ts | Exports new helpers and new helper exports (createLiteralRegex, createIterableIterator). |
| lib/src/helpers/regexp.ts | Adds createLiteralRegex helper implementation + docs. |
| docs/feature-backlog.md | Updates backlog to reflect implemented string methods. |
| .size-limit.json | Updates size-limit thresholds for built artifacts. |
| export function createIterableIterator<T>(ctx: CreateIteratorContext<T>): IterableIterator<T> { | ||
| return makeIterable(createIterator<T>(ctx), ctx) as IterableIterator<T>; | ||
| } |
There was a problem hiding this comment.
createIterableIterator() is a new exported iterator helper but there are existing iterator tests in lib/test/src/common/iterator/create.test.ts that cover createIterator/createIterable. Adding targeted tests for createIterableIterator (including that Symbol.iterator returns itself and that for...of / iterForOf consumption behaves correctly) would help prevent regressions.
nevware21-bot
left a comment
There was a problem hiding this comment.
Approved by nevware21-bot
… shared literal regex helper, and coverage - **strTruncate**: Truncate strings to maximum length with optional suffix support - Preserves hard max length boundary (suffix included within limit) - Truncates suffix if needed to maintain max length constraint - Type coercion via asString(); throws for null/undefined - **strCount**: Count non-overlapping substring occurrences - Returns 0 for empty search strings (prevents unbounded matches) - Type coercion via asString(); throws for null/undefined - add strAt and polyStrAt - add strMatchAll and polyStrMatchAll - wire String.at and String.matchAll polyfills - add createLiteralRegex and export it - refactor replace_all and match_all to use createLiteralRegex for literal matcher handling - add createIterableIterator and export it - update public exports for new non-polyfill APIs and keep polyStrReplaceAll in the polyfill export section
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
lib/src/string/replace_all.ts:90
- The updated docs say
searchValuecan be "any object with a [Symbol.replace] method", and the implementation does support that, but the TypeScript signature still limitssearchValuetostring | RegExp. Either widen the type so TS consumers can use the documented behavior, or adjust the docs to reflect the intended typed API.
/*#__NO_SIDE_EFFECTS__*/
export function polyStrReplaceAll(value: string, searchValue: string | RegExp, replaceValue: string | ((substring: string, ...args: any[]) => string)): string {
_throwIfNullOrUndefined(value);
| }); | ||
|
|
||
| assert.equal(done, false, "Check that the return was not called as it doesn't need to be"); | ||
| assert.equal(done, false, "Check that the return was called"); |
There was a problem hiding this comment.
The assertion expects done to remain false, but the failure message says "return was called". This message is misleading for this test case (the iterator completes immediately, so return should not be invoked). Update the message (or the expectation) so they match.
| assert.equal(done, false, "Check that the return was called"); | |
| assert.equal(done, false, "Check that the return was not called"); |
| * ``` | ||
| */ | ||
| /*#__NO_SIDE_EFFECTS__*/ | ||
| export function polyStrMatchAll(value: string, matcher: string | RegExp): IterableIterator<RegExpExecArray> { |
There was a problem hiding this comment.
polyStrMatchAll is documented/implemented to accept matcher objects with a [Symbol.matchAll] method, but the function signature restricts matcher to string | RegExp. Please align the type definition with the supported behavior (or narrow the docs if you want to keep the signature consistent with TS's built-in String#matchAll types).
nevware21-bot
left a comment
There was a problem hiding this comment.
Approved by nevware21-bot
strTruncate: Truncate strings to maximum length with optional suffix support
strCount: Count non-overlapping substring occurrences
add strAt and polyStrAt
add strMatchAll and polyStrMatchAll
wire String.at and String.matchAll polyfills
add createLiteralRegex and export it
refactor replace_all and match_all to use createLiteralRegex for literal matcher handling
add createIterableIterator and export it
update public exports for new non-polyfill APIs and keep polyStrReplaceAll in the polyfill export section