Skip to content

REQUEST | useTruncateString | String truncation function #4355

@CodeXiD

Description

@CodeXiD

Clear and concise description of the problem

As a developer using VueUse I am very happy to use many functions provided by this library, but as for me it would be useful to implement such a basic utility as string truncation, so that each time I do not implement my own helper, or resort to installing an external library for this particular function.

Suggested solution

In module Utilities we could provide following implementation the useTruncateString function (since there is a useTrunc function, I believe that such a name indicated the specific purpose of the new function).
The function would accept a string to be truncated, as well as an options object:
length - the length of the truncated string
omission - a string to insert at the end of the truncated string (default "...")
separator - a pattern for truncation (for example, by space or comma)

Alternative

Of course a function with such functionality is implemented in lodash, but I think such a basic function would be useful by default in VueUse

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions