Skip to content

Conversation

@webpro
Copy link

@webpro webpro commented Jun 21, 2025

Thanks for a great package, been very useful.

Hit an odd bug:

const input = "██ █";
const result = getStringTruncatedWidth(input, { limit: 2 });
// { width: 2, index: 4, truncated: true, ellipsed: true }

The index should be 2. While this looks fine:

const input = "█ ██";
const result = getStringTruncatedWidth(input, { limit: 2 });
// { width: 2, index: 2, truncated: true, ellipsed: true }

Also, not sure if you even want to support this, feel free to reject. But I've tried to fix up the unmatched part anyway. Also not sure if it's up to your vision/standards, but happy to adjust.

@fabiospampinato
Copy link
Owner

Is this essentially about "invalid" surrogate pairs? 🤔 could you update the PR to work on the current version of the library? I suppose we should support this, hopefully without slowing things down.

# Conflicts:
#	src/index.ts
#	test/index.js
@webpro webpro force-pushed the fix/support-double-codepoint branch from a6de877 to d20dd64 Compare August 23, 2025 07:29
@webpro
Copy link
Author

webpro commented Aug 23, 2025

Is this essentially about "invalid" surrogate pairs? 🤔

could you update the PR to work on the current version of the library?

I suppose we should support this, hopefully without slowing things down.

If anything, it should speed up things as it does less work. Running npm run compile && npm run benchmark improves slightly, but I'm not sure exactly what's exercised and whether it's a fair comparison.

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.

2 participants