Skip to content

feat(string): add strTruncate,strCount strAt and strMatchAll helpers, shared literal regex helper, and coverage#530

Open
nev21 wants to merge 1 commit intomainfrom
nev21/strConvert
Open

feat(string): add strTruncate,strCount strAt and strMatchAll helpers, shared literal regex helper, and coverage#530
nev21 wants to merge 1 commit intomainfrom
nev21/strConvert

Conversation

@nev21
Copy link
Contributor

@nev21 nev21 commented Mar 21, 2026

  • 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

@nev21 nev21 added this to the 0.14.0 milestone Mar 21, 2026
@nev21 nev21 requested a review from a team as a code owner March 21, 2026 04:04
Copilot AI review requested due to automatic review settings March 21, 2026 04:04
@nev21 nev21 requested a review from a team as a code owner March 21, 2026 04:04
@codecov
Copy link

codecov bot commented Mar 21, 2026

Codecov Report

❌ Patch coverage is 99.25926% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 98.86%. Comparing base (43becdc) to head (7000deb).

Files with missing lines Patch % Lines
lib/src/polyfills.ts 50.00% 1 Missing ⚠️
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              
Files with missing lines Coverage Δ
lib/src/helpers/regexp.ts 100.00% <100.00%> (ø)
lib/src/iterator/create.ts 100.00% <100.00%> (ø)
lib/src/string/at.ts 100.00% <100.00%> (ø)
lib/src/string/match_all.ts 100.00% <100.00%> (ø)
lib/src/string/replace_all.ts 100.00% <100.00%> (ø)
lib/src/polyfills.ts 53.06% <50.00%> (+1.99%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/polyStrAt and strMatchAll/polyStrMatchAll, and wired them into the global polyfills loader.
  • Introduced reusable helpers (createLiteralRegex, createIterableIterator) and refactored replaceAll to 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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 5 comments.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.

Comment on lines +197 to +199
export function createIterableIterator<T>(ctx: CreateIteratorContext<T>): IterableIterator<T> {
return makeIterable(createIterator<T>(ctx), ctx) as IterableIterator<T>;
}
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot generated this review using guidance from repository custom instructions.
@nev21 nev21 force-pushed the nev21/strConvert branch from 91ecf72 to b5902b8 Compare March 21, 2026 05:30
nevware21-bot
nevware21-bot previously approved these changes Mar 21, 2026
Copy link
Contributor

@nevware21-bot nevware21-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved by nevware21-bot

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

… 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
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 searchValue can be "any object with a [Symbol.replace] method", and the implementation does support that, but the TypeScript signature still limits searchValue to string | 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");
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
assert.equal(done, false, "Check that the return was called");
assert.equal(done, false, "Check that the return was not called");

Copilot uses AI. Check for mistakes.
* ```
*/
/*#__NO_SIDE_EFFECTS__*/
export function polyStrMatchAll(value: string, matcher: string | RegExp): IterableIterator<RegExpExecArray> {
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@nevware21-bot nevware21-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved by nevware21-bot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants