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. |
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);
nevware21-bot
left a comment
There was a problem hiding this comment.
Approved by nevware21-bot
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
nevware21-bot
left a comment
There was a problem hiding this comment.
Approved by nevware21-bot
## 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
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