Skip to content

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

Merged
nev21 merged 2 commits into
mainfrom
nev21/strConvert
Mar 21, 2026
Merged

feat(string): add strTruncate,strCount strAt and strMatchAll helpers, shared literal regex helper, and coverage#530
nev21 merged 2 commits into
mainfrom
nev21/strConvert

Conversation

@nev21
Copy link
Copy Markdown
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
Copy Markdown

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 (9851089).
⚠️ Report is 1 commits behind head on main.

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
Copy Markdown
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.

Comment thread lib/src/string/match_all.ts
Comment thread lib/src/string/match_all.ts
Comment thread lib/test/src/common/string/truncate.test.ts
Comment thread lib/test/src/common/string/truncate.test.ts
Comment thread lib/test/src/common/string/at.test.ts
Comment thread lib/test/src/common/string/match_all.test.ts
Comment thread lib/src/helpers/regexp.ts
Copy link
Copy Markdown
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.

Comment thread lib/src/string/match_all.ts
Comment thread lib/src/string/match_all.ts Outdated
Comment thread lib/src/string/match_all.ts Outdated
Comment thread lib/src/iterator/create.ts Outdated
Comment thread lib/src/helpers/regexp.ts Outdated
Copy link
Copy Markdown
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 thread lib/src/iterator/create.ts
Comment thread lib/src/iterator/create.ts
Comment thread lib/src/string/match_all.ts Outdated
Comment thread lib/src/helpers/regexp.ts
@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
Copy Markdown
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
Copy Markdown
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.

Comment thread lib/src/string/match_all.ts
Comment thread lib/src/string/replace_all.ts
… 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
Copy Markdown
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);

Comment thread lib/test/src/common/iterator/create.test.ts Outdated
Comment thread lib/src/string/match_all.ts
nevware21-bot
nevware21-bot previously approved these changes Mar 21, 2026
Copy link
Copy Markdown
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

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
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

@nev21 nev21 merged commit 53d481f into main Mar 21, 2026
10 checks passed
@nev21 nev21 deleted the nev21/strConvert branch March 21, 2026 21:30
nev21 added a commit that referenced this pull request May 19, 2026
## Release v0.14.0

This PR increases the version to `0.14.0` and updates the changelog with
all significant changes since v0.13.0.

### Summary of Changes

#### Features
- New array helpers and array-like detection (#525)
- `strReplace` and `strReplaceAll` string helpers (#527)
- `strCapitalizeWords` helper (#528)
- `strTruncate`, `strCount`, `strAt`, `strMatchAll` helpers (#529, #530)
- `arrFlatMap` with ES5 polyfill (#533)
- Typing utilities and expanded TSDoc examples (#535)
- `isAsyncIterable` and `isIntegerInRange` helpers (#536)
- `strStartsWithAny`, `strEndsWithAny`, `strWrap`, `strUnwrap`,
`strNormalizeNewlines` (#543)
- New object utility helpers and prototype pollution hardening (#564,
#565)

#### Bug Fixes
- Fix ES2015 built-in type errors in consumers by adding lib reference
directive to published declarations (#558)
- Fix `thisArg` binding in `polyArrFindIndex` / `polyArrFindLastIndex`
polyfills (#562)
- Fix falsy `thisArg` (0, `''`, `false`) being overridden in
`arrForEach`, `iterForOf`, `objForEachKey` (#566)

#### Repository Improvements
- Drop Node.js 16 from CI matrix and add Node.js 24 (#549)
- Upgrade Grunt devDependency to v1.6.2 (#552)
- Add funding metadata to published package manifests (#554)

### Files Updated
- `CHANGELOG.md` — Added v0.14.0 entry
- `package.json` — Version bumped to 0.14.0
- `lib/package.json` — Version bumped to 0.14.0
- `README.md` — Updated recommended version specification
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