Skip to content

feat: refactor string truncate-middle to support grapheme clusters and code points - #13782

Open
ujjwalv01 wants to merge 4 commits into
stdlib-js:developfrom
ujjwalv01:feat-string-truncate-middle-refactor
Open

feat: refactor string truncate-middle to support grapheme clusters and code points#13782
ujjwalv01 wants to merge 4 commits into
stdlib-js:developfrom
ujjwalv01:feat-string-truncate-middle-refactor

Conversation

@ujjwalv01

@ujjwalv01 ujjwalv01 commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Resolves part of #1062 (truncate-middle portion).

Description

What is the purpose of this pull request?

This pull request:

  • Adds @stdlib/string/base/truncate-middle-code-points which truncates the middle Unicode code points of a string.
  • Adds @stdlib/string/base/truncate-middle-grapheme-clusters which truncates the middle grapheme clusters of a string.
  • Refactors @stdlib/string/truncate-middle to act as a mode dispatcher, supporting grapheme (default), code_point, and code_unit modes via an options.mode parameter.

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

This PR supersedes the previously abandoned PR #1119. All changes requested by the reviewer in that PR (pluralizing the package name, making seq a mandatory argument in base packages) have been incorporated.

Checklist

Please ensure the following tasks are completed before submitting this pull request.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

If you answered "yes" to using AI assistance, please provide a short disclosure indicating how you used AI assistance. This helps reviewers determine how much scrutiny to apply when reviewing your contribution.

I utilized an AI assistant to automate the generation of test cases and benchmark scaffolding. The core logic implementation and integration were authored manually.


@stdlib-js/reviewers

@ujjwalv01
ujjwalv01 requested a review from a team July 30, 2026 13:58
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Jul 30, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
string/base/truncate-middle-code-points $\\color{green}134/134$
$\\color{green}+100.00\\%$
$\\color{green}9/9$
$\\color{green}+100.00\\%$
$\\color{green}1/1$
$\\color{green}+100.00\\%$
$\\color{green}134/134$
$\\color{green}+100.00\\%$
string/base/truncate-middle-grapheme-clusters $\\color{green}155/155$
$\\color{green}+100.00\\%$
$\\color{green}12/12$
$\\color{green}+100.00\\%$
$\\color{green}1/1$
$\\color{green}+100.00\\%$
$\\color{green}155/155$
$\\color{green}+100.00\\%$
string/truncate-middle $\\color{red}178/182$
$\\color{green}+97.80\\%$
$\\color{red}17/19$
$\\color{green}+89.47\\%$
$\\color{green}1/1$
$\\color{green}+100.00\\%$
$\\color{red}178/182$
$\\color{green}+97.80\\%$

The above coverage report was generated for the changes in this PR.

@kgryte

kgryte commented Jul 31, 2026

Copy link
Copy Markdown
Member

@ujjwalv01 It is actually better if you split the packages into separate PRs. Why? Because we perform squash merging, and, for purposes of the changelog, we want one package added per commit.

Obviously, the top-level package PR will be dependent on the corresponding base packages, but that is fine. Just open the top-level package after the base packages have been merged.

@kgryte kgryte added Needs Changes Pull request which needs changes before being merged. and removed Needs Review A pull request which needs code review. labels Jul 31, 2026
@ujjwalv01

Copy link
Copy Markdown
Contributor Author

@kgryte Understood! That makes complete sense for the changelog. I will focus on getting the two base package PRs merged first. We can leave this one on draft until those are merged, and then I'll rebase this branch so it only contains the top-level modifications.

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

Labels

Needs Changes Pull request which needs changes before being merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants