Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add String.truncate utility #4103

Open
skoshx opened this issue Dec 9, 2024 · 4 comments
Open

add String.truncate utility #4103

skoshx opened this issue Dec 9, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@skoshx
Copy link

skoshx commented Dec 9, 2024

What is the problem this feature would solve?

Being able to truncate text, which is quite useful in for instance @effect/cli apps. I'm using it to make sure that the multiSelect doesn't overflow and cause glitches when rendering.

What is the feature you are proposing to solve the problem?

String.truncate(text: string, maxLength: number) => string

What alternatives have you considered?

I currently have a utility function for this. But I kind of expected String module to contain it. I feel like if Effect wants to be JavaScript's standard library, then it's a useful function to have.

@skoshx skoshx added the enhancement New feature or request label Dec 9, 2024
@jessekelly881
Copy link
Contributor

jessekelly881 commented Dec 9, 2024

You can already do this with String.slice(0, maxLength)(text)

const truncate = (maxLength: number) => String.slice(0, number)

@skoshx
Copy link
Author

skoshx commented Dec 9, 2024

(The truncate should also optionally add at the end)

And I understand it's a short function to define yourself, but the point of a standard library is to provide utility functions so we don't have to write these function ourselves.

I see no downside in including such functions, that can be treeshaken away if not used.

@jessekelly881
Copy link
Contributor

Let me know if you think anything is missing here. As is, emojis and other multibyte characters aren't supported. https://github.com/Effect-TS/effect/pull/4110/files

@skoshx
Copy link
Author

skoshx commented Dec 10, 2024

Great, thank you soo much for this, looks absolutely great!! Also the dual API is super useful 🤩

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants